ComfyUI Node

Pt Reshape

Reshape any tensor without touching its data

By HowToSD·Created about a year ago·Updated about a year ago· 7
Pt Reshape
  • tens
  • TENSOR
new_shape

Pt Reshape is the node that lets you change the shape of a tensor without moving a single value. In the ComfyUI-Pt-Wrapper world, reshape is the plumbing between nearly everything: a model expects (batch, channels, height, width) but your data came in as a flat list; a linear layer wants a 2D matrix and you've got a 4D tensor; a display node wants one dimension. If you've ever hit a shape mismatch error in a training workflow, this is the node that fixes it - provided you respect the one iron rule of reshaping.

What it actually does

It's a thin wrapper around torch.reshape. You feed it a TENSOR and a new_shape written as a Python list or tuple, and it returns a tensor with the new shape. The data is untouched and the order of elements is preserved - you're just reinterpreting how those values are laid out in dimensions.

The one rule: the total number of elements must stay the same. A tensor of shape (2, 3, 4) has 24 elements, so you can reshape it to (6, 4), (4, 6), (24,), or (2, 2, 6) - but never to (5, 5). Try it and you get a runtime error. This trips up more people than anything else on this node.

The input that matters is new_shape, a multiline text field. Two ways to write it:

  • A full shape: [6, 4] or (6, 4).
  • A shape with -1 to auto-infer: [2, -1] means "make the first dim 2 and figure out the second from the element count." This is the trick that saves you from doing the multiplication yourself, and it's the one I'd actually reach for most of the time.

Output is a single TENSOR in the new shape, ready to wire into whatever model node, math node, or reducer needs it.

How to install it

Pt Reshape is part of the ComfyUI-Pt-Wrapper pack. In ComfyUI Manager, search ComfyUI-Pt-Wrapper and install, then restart. Or by hand:

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

Restart after. Note the pack's dependencies are heavy - transformers, datasets, accelerate, peft, gensim, sentencepiece, plus the pandas/scikit-learn/scipy stack - so the first install is slow and there's real conflict potential with other nodes that pin different transformers versions.

Gotchas

Beyond the element-count rule, the parsing trap applies here too: new_shape goes through Python's ast.literal_eval, so it must be valid list or tuple syntax. [2, -1] works; 2, -1 with no brackets fails. Get into the habit of writing the brackets.

One more nuance worth knowing: reshape will happily give you a view (zero-copy) when it can and copy when it can't. That's an efficiency detail, not a correctness one - you won't notice it until you're moving big tensors around and wondering why memory spiked.

CategoryData Analysis

Inputs (2)

NameTypeDefaultDescription
tensTENSOR
new_shapeSTRING

Outputs (1)

NameTypeDescription
TENSORTENSOR