ComfyUI Node

Pt Std

Standard deviation along any dimension, with the correction you actually want

By HowToSD·Created about a year ago·Updated about a year ago· 7
Pt Std
  • tens
  • TENSOR
correction1
dim
keepdimfalse

Pt Std computes the standard deviation of a tensor along the dimension or dimensions you choose. It's a summary-statistics node, and it's one of the ones you'll actually build pipelines around: understanding the spread of your data is half of data analysis. In the ComfyUI-Pt-Wrapper world, that means knowing whether your values are tightly clustered or all over the place before you feed them to a model - and this node gives you that as a real tensor you can inspect, compare, or pass onward.

What it actually does

It's a wrapper around torch.std(tens, dim=..., correction=..., keepdim=...). One TENSOR in, one TENSOR out - a reduction node that collapses the dimensions you name down to a standard deviation. The inputs:

  • tens - the tensor to summarize.
  • correction - 0 or 1 (default 1). This is the Bessel's correction toggle: 1 computes the sample standard deviation (divides by N-1), which is what you want when your tensor is a sample of a larger population. 0 computes the population standard deviation (divides by N), for when your data is the whole set. The default of 1 matches what most people expect from "std" in a stats context, but it matters at small sizes - for a tensor with 10 elements the difference is visible.
  • dim - a multiline string saying which dimension(s) to reduce over. The pack's convention: type 0, [0], or (1, 2) - an integer, a list, or a tuple, all accepted.
  • keepdim - a boolean. True keeps the reduced dimension in place as size 1, which makes downstream broadcasting much easier.

The keepdim toggle is the one beginners skip and then regret. Reduce over a dimension and it disappears by default; turning it on keeps the tensor's rank intact, so shapes line up when you wire the result into math against the original tensor.

How to install it

It's part of the ComfyUI-Pt-Wrapper pack. ComfyUI Manager: search ComfyUI-Pt-Wrapper, install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper

Restart after. The pack's requirements.txt is heavy (transformers, datasets, accelerate, peft, gensim, sentencepiece, pandas, scikit-learn, scipy) - slow first install, possible conflicts with other nodes.

Gotchas

The dim field has the pack's usual parsing rule: it's a string, and it must be valid Python syntax - 0, [0], or (1, 2), brackets/tuples included. And you can reduce over multiple dimensions at once with a tuple like (1, 2), which is easy to forget.

The correction distinction trips people when they compare against a calculator. If you compute std on a small tensor and get a slightly different number than a naive formula, you're probably comparing sample vs. population - flip correction to 0 to match. Neither is "wrong"; they answer different questions. And for a single element or all-NaN regions, std can come out NaN - same silent-poisoning trap as Pt Sqrt, so check your inputs.

CategoryData Analysis

Inputs (4)

NameTypeDefaultDescription
tensTENSOR
correctionINT10–1
dimSTRING
keepdimBOOLEANfalse

Outputs (1)

NameTypeDescription
TENSORTENSOR