Pt Var
Sample variance, population variance, and the one dial between them
- tens
- TENSOR
Pt Var computes the variance of a tensor along the dimension or dimensions you specify - a reduction op in the same family as the pack's PtMean and PtStd, but for spread rather than center. It's the kind of node you reach for when you want to actually understand your data in the graph: how much do these features vary, is this channel noisy, how spread out is this distribution relative to that one.
Four inputs, and only two of them will genuinely trip you up. tens is the tensor. correction is the interesting dial: 1 gives you sample variance with Bessel's correction (divide by N−1, the standard choice when your tensor is a sample of something bigger), and 0 gives population variance (divide by N). Default is 1, which is the statistically conservative default and usually the right one. keepdim just decides whether the reduced dimensions stay in the output shape as size-1 axes (handy if you want the result to broadcast back against the original tensor). The fiddly one is dim: it's a string, not a number. You type the dimension as text - 0, [0], or (1, 2) all work - and the node parses it. Single int, list, or tuple, all acceptable.
Mechanically it's a thin wrapper over torch.var with the correction passed through, so behavior matches PyTorch exactly. That matters when you're comparing against reference computations - you won't get off-by-one-divisor surprises.
The best use case I've found: inspecting feature tensors before training. Feed a batch's features in, reduce over the batch axis, and watch how variance changes as you tweak preprocessing. It's cheap, immediate, and tells you more about whether your data pipeline is sane than any loss curve.
Install
ComfyUI Manager (search "ComfyUI-Pt-Wrapper"), or:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
Restart ComfyUI. The pack installs a heavy dependency set (transformers, datasets, peft, accelerate, scikit-learn, pandas, seaborn, matplotlib, gensim, sentencepiece). No model files to download.
Common issues
The dim string is the main source of facepalms. If you type 1, 2 instead of (1, 2) the parser may or may not do what you meant - get in the habit of writing explicit tuples for multi-dim reductions. And correction only accepts 0 or 1; the node validates it and throws otherwise. A completely flat variance output (all zeros) isn't a bug - it means your data has no spread, which is itself a finding.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| tens | TENSOR | — | |
| correction | INT | 10–1 | — |
| dim | STRING | — | |
| keepdim | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TENSOR | TENSOR | — |