ComfyUI Node

Tensor Join

Tensor Join — putting tensors together, two at a time

By StableLlama·Created about a year ago·Updated 4 days ago· 48
Tensor Join
  • tensor1
  • tensor2
  • *
dim0
modeconcatenate

Tensor Join is the reverse of Tensor Slice: instead of cutting a tensor apart, it glues two of them together. Two tensors in, one tensor out, with a dropdown choosing between concatenate (append along an existing dimension) and stack (add a brand-new dimension). If you've ever needed to batch two images into one tensor or line up two feature vectors, this is the node.

It's part of Basic data handling by StableLlama, a dependency-free utility pack that wraps everyday Python and PyTorch into ComfyUI nodes - the tensor section's assembly tool, alongside the slice/reshape/permute family.

How it works

Both inputs are coerced to tensors if needed, then one of two PyTorch ops runs:

  • concatenate - torch.cat([t1, t2], dim=dim). The tensors must match in every dimension except the one you're joining along. Joining two [1, 512, 512, 3] images along dim 0 gives [2, 512, 512, 3] - a real batch.
  • stack - torch.stack([t1, t2], dim=dim). This inserts a new dimension at dim, so the tensors must match in all dimensions. Stacking two [512, 512, 3] images at dim 0 gives [2, 512, 512, 3].

Same end shape in that example, very different meanings: concatenate says "these are two items of the same kind," stack says "this is one group of two items."

The inputs that matter

Four inputs:

  • tensor1, tensor2 (wildcards *) - the two things to join.
  • dim (INT, default 0) - which dimension to join along.
  • mode (dropdown, default concatenate) - concatenate or stack.

One wildcard output.

Where you'd actually use it

Building batches and sequences. Two images that should be processed together become one batched tensor via concatenate along dim 0. Two masks or feature vectors get lined up with stack. And because it's strictly two inputs, chaining is how you get to three or more - join A+B, then join the result with C. Slightly clunky, but it works and it's explicit about what's happening.

Installing it

# ComfyUI Manager (recommended): search "Basic data handling", install, restart.

# or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
# restart ComfyUI

No dependencies beyond torch, no model downloads.

Where people get burned

Concatenate demands matching shapes everywhere but the join dim. Try to concatenate two images of different widths and PyTorch refuses outright. This is the failure mode you'll hit first, and the error is your friend - it means the node is stopping you before you bake in a misaligned tensor.

Confusing stack and concatenate. The shapes both accept are different (stack needs a full match; concat tolerates one mismatched dim), and the resulting semantics differ. Getting them mixed up usually surfaces as a shape error or - worse - silently produces a tensor with an extra dimension that downstream nodes choke on.

Only two inputs. If you're assembling a big batch from many pieces, remember it's pairwise. Plan for a chain of joins rather than expecting a multi-socket node.

Dtype consistency. Join two int64 tensors and you get an int64 tensor, which may not play nice with float math later. If you're building toward image ops, keep both sides float. Same general wildcard caveat as the rest of this pack: it does tensor work, so feed it tensors.

CategoryBasic/tensor

Inputs (4)

NameTypeDefaultDescription
tensor1*
tensor2*
dimINT0
modeCOMBOconcatenate2 options: concatenate, stack

Outputs (1)

NameTypeDescription
**