ComfyUI Node

Pt Size

Extract a tensor's shape as a first-class value

By HowToSD·Created about a year ago·Updated about a year ago· 7
Pt Size
  • tens
  • PTSIZE

Pt Size does one thing: it pulls the shape out of a tensor and hands it to you as a value you can use. In most ComfyUI packs, "shape" is an implicit fact - you only find out about it when something breaks. In ComfyUI-Pt-Wrapper, the pack treats a tensor's size as a real object (a PTSIZE) that flows through the graph like any other data. This node is the tap that extracts it, and from there you can display it with Pt Show Size, stringify it with Pt Size To String, convert it with Pt Size To Numpy, or feed it into any of the size-aware operations.

What it actually does

It's a thin wrapper around tens.size() - the method returns a torch.Size, which is the tuple-like object holding the length of each dimension. One TENSOR in, one PTSIZE out. There are no parameters, no options, nothing to configure. If you give it a tensor of shape (2, 3, 96, 32), you get a torch.Size([2, 3, 96, 32]) out.

The value of this is in the workflow context. In a training graph - say one of the pack's dog-vs-cat or CIFAR-10 pipelines - you often need to know what a tensor's dimensions are to configure the next node correctly, and sometimes you need that shape as actual data: to build a matching tensor with Pt Size Create, to check it against an expected shape, or to log it. Pt Size is the read side of that; Pt Size Create is the write side.

Only one input:

  • tens - any TENSOR.

Output is a single PTSIZE.

How to install it

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

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

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

Gotchas

The main thing to keep straight is the type. A PTSIZE is its own custom type in this pack - it isn't a regular STRING or TENSOR. You can't wire it into a generic text node or a math node; you need the size-aware consumers the pack provides (Pt Show Size, Pt Size To String, Pt Size To Numpy). The flip side: don't expect a PTSIZE to plug into nodes from other packs, because they don't know the type exists. Keep size-related conversions inside this pack and you're fine.

Also remember this node doesn't display anything on its own. Pt Size by itself produces output you can't see - wire it into Pt Show Size or Pt Size To String when you're debugging, or it looks like nothing happened.

CategoryData Analysis

Inputs (1)

NameTypeDefaultDescription
tensTENSOR

Outputs (1)

NameTypeDescription
PTSIZEPTSIZE