ComfyUI Node

张量拼接

Cat two tensors along any axis, with a debug mode that tells you it worked

By spawner1145·Created about a year ago·Updated 11 months ago· 2
张量拼接
  • tensor1
  • tensor2
  • concatenated_tensor
  • debug_info
dim1
enable_debugfalse

A torch.cat with a safety belt. TensorConcatenation joins two tensors along any dimension you pick - dim defaults to 1, the token/sequence axis, which is the one you usually want for embeddings. It's the raw-tensor version of this pack's ConditioningConcatenation: that one handles full CONDITIONING objects, this one just joins tensors.

The inputs are minimal: tensor1, tensor2, and dim (range -10..10, negatives count back from the end). Everything else is validation. Before it cats, it checks that both tensors have the same number of dimensions, that every axis except the one you're joining on matches, and it moves tensor2 to tensor1's device if they differ. Wrong shapes produce a clear error naming the offending axis - the exact message you want when you've guessed wrong about a wire.

The interesting extra is enable_debug, which is off by default and most people never need. Flip it on and the node also computes an order-sensitivity score: it cats in both orders (t1;t2 vs t2;t1) and reports the norm of the difference as debug_info. A near-zero score means the two halves are nearly interchangeable; a big one means order genuinely changes the result. For token embeddings this is a nice reality check on whether (prompt A, prompt B) and (prompt B, prompt A) are different - which, for the record, they are, and the debug number tells you by how much. debug_info also dumps shapes, dims, and devices, making this a surprisingly decent debugging node in its own right.

The concatenated_tensor output is, naturally, this pack's TENSOR type, so it feeds the pack's other tensor nodes (TensorPooledMerge, TensorShapeAdapter, TensorCrossAttention, ...) and the emb input of ConditioningPacker. It will not wire into core nodes - that's the usual closed-loop arrangement of this pack.

Practical notes: dim=1 on a [B, S, H] embedding stacks sequences (this is the one you want for "put these two prompt embeddings back to back"); dim=-1 stacks the feature dimension (use with concat strategies elsewhere); dim=0 stacks the batch. The min/max on dim are generous, but if you ask for a dimension that doesn't exist, the error names the shape and you'll fix it in one read.

Install

ComfyUI Manager → search comfyui-spawner-nodes → install → restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/spawner1145/comfyui-spawner-nodes

Requirements are three pure-Python libs (piexif, pypng, xmltodict), no model downloads. The README is a one-liner, the UI labels are Chinese, and the author (spawner1145, also of a Wan2.1 SD extension) keeps the pack barely documented. The node itself is straightforward enough that it doesn't matter much.

Troubleshooting

  • "维度 X 大小不匹配" - the two tensors don't agree on some axis other than the join axis. The error tells you which. You're probably mixing [B, S, H] from different sources.
  • "张量维度数量不匹配" - one tensor has a different rank. [B, S, H] vs [B, S] won't cat, no matter what.
  • Order-sensitivity is huge and you didn't expect it - embeddings are order-dependent. That's what the debug number is there to show you; it's not a bug.
Categoryspawner/tensor

Inputs (4)

NameTypeDefaultDescription
tensor1TENSOR
tensor2TENSOR
dimINT1-10–10
enable_debugoptBOOLEANfalse

Outputs (2)

NameTypeDescription
concatenated_tensorTENSOR
debug_infoSTRING