ReshapeTensor
Change a tensor's shape without touching its values
- input_data
- TORCH_TENSOR
Tensors carry both data and shape, and the shape is wrong more often than the data is. ReshapeTensor lets you restate a tensor's dimensions - take a (60000, 1, 28, 28) MNIST stack and flatten it to (60000, 784) so a linear layer can eat it, or un-flatten back out again. No data moves, no values change; you're just telling PyTorch to reinterpret the layout. It's the connective tissue of any training graph in this pack.
It's part of EternalKernel PyTorch Nodes (TashaSkyUp), the raw-PyTorch-in-ComfyUI pack, and it sits between the data nodes and the model nodes in basically every workflow the pack is designed for. Neural network layers are shape-strict; this is how you make your data match them.
How it works
The node takes a tensor and a comma-separated shape string and calls .reshape() on it. Two things matter in practice.
First, the -1 wildcard: 1, -1 means "first dimension of 1, figure out the rest for me." It's the default, and it's how you flatten anything - the source's own comment uses it as the flatten idiom. You can only have one -1 in a shape, because the whole point is that it's inferred from the total element count.
Second, reshape is a view when it can be and a copy when it must be - you don't need to care which, but it means it's cheap, which is why you can sprinkle these around freely.
The format note from the sibling nodes applies here in reverse: ReshapeTensor splits on commas and does not want parentheses, so it's 1, -1 not (1, -1). The pack is inconsistent about this across nodes, so when a shape string fails, the first thing to check is which format convention the node uses.
Inputs and outputs
- input_data (required
TORCH_TENSOR) - whatever needs reshaping. - shape (required STRING) - comma-separated dims, default
1, -1. - Output: TORCH_TENSOR - same values, new shape.
The most common uses: 1, -1 to flatten a whole sample into one row, -1, 28, 28 to go back to images, or -1, 10 to match a ten-class output head.
Installing it
Shared with the whole pack:
cd ComfyUI/custom_nodes
git clone https://github.com/TashaSkyUp/EternalKernelPytorchNodes.git
cd EternalKernelPytorchNodes
pip install -r requirements.txt
Restart ComfyUI and it's under ETK/pytorch - or ComfyUI Manager, searching "EternalKernel PyTorch Nodes".
Troubleshooting
There's exactly one interesting error and it's easy to produce: reshape a (60000, 784) tensor to (10, 60000) and you get a clean RuntimeError: shape '[10, 60000]' is invalid for input of size 47040000. The total number of elements must match, always - that's the whole constraint. Beginners often hit it when they flatten a batch and forget that the batch dimension is included, so "flatten to 784" fails on a (64, 1, 28, 28) tensor (that's 50,176 elements, not 784). Answer: -1, 784, or flatten per-sample. And since this pack loosens ComfyUI's return-type validation globally, a shape error can surface a node or two downstream - when in doubt, simplify the chain.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| input_data | TORCH_TENSOR | — | |
| shape | STRING | 1, -1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TORCH_TENSOR | TORCH_TENSOR | — |