Pt Stack
Stack two tensors into one with a brand-new dimension
- tens_a
- tens_b
- TENSOR
Pt Stack joins two tensors by adding a whole new dimension. That's the distinction that matters with this node: it doesn't glue tensors side by side, it layers them. Stack two (3, 4) tensors along a new axis and you get a (2, 3, 4) tensor - one new leading dimension of size 2. It's the operation you reach for when you want to build a batch: instead of ten separate tensors floating around, stack them into one batch dimension and feed the result to a model or a data-loader-style step in one wire.
What it actually does
It's a wrapper around torch.stack([tens_a, tens_b], dim=dim). Two TENSOR inputs and a dim integer (default 1, range -10 to 10) that decides where the new axis goes. Stack at dim=0 and the new dimension is first - two (3, 4) tensors become (2, 3, 4). Stack at dim=1 and the new dimension sits in the middle - (3, 2, 4).
The one hard requirement: the two input tensors must have the same shape. This isn't concatenation, where shapes can differ along the joined axis; stacking demands exact shape agreement because it's creating a new axis, not merging along an existing one. Feed it mismatched shapes and you get a runtime error.
The default of dim=1 is worth noting. For rank-2 tensors, dim 1 puts the new axis in the middle, which is a common shape for sequence-style data. But honestly, for most "make a batch" use cases you'll want dim=0, so change it consciously.
Only the three inputs:
- tens_a and tens_b - the two tensors to stack, same shape required.
- dim - where the new axis goes.
Output is a single TENSOR with one more dimension than the inputs.
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 the heavy training stack (transformers, datasets, accelerate, peft, gensim, sentencepiece, pandas, scikit-learn, scipy) - slow first install, possible conflicts with other nodes pinning different transformers versions.
Gotchas
The same-shape requirement is the trap. If you're trying to stack things that are almost the same shape, you'll get a runtime error rather than a silent fix - and the error message may not immediately tell you it's a shape mismatch, so check your inputs with Pt Size first.
Also keep stack vs. concat straight. This pack also has a concatenation node, and they serve different purposes: stack adds a dimension (two (3,4) → (2,3,4)), concat joins along an existing dimension (two (3,4) → (6,4)). Grabbing the wrong one produces a valid-looking but structurally wrong tensor. And since it only takes two tensors, building a bigger stack means chaining the node - stack the first two, then stack that result with the third.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| tens_a | TENSOR | — | |
| tens_b | TENSOR | — | |
| dim | INT | 1-10–10 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TENSOR | TENSOR | — |