Transpose
Swap any two dimensions — and learn why order matters so much
- tensor
- output
Half of debugging a deep learning pipeline is fixing dimension order, and half of that is transposing. Transpose is the node that swaps any two dimensions of a tensor - torch.transpose exposed with a widget. If you've got a [H, W, C] image tensor and something downstream wants [C, H, W], this is the two-widget fix. It looks trivial. It is trivial. It's also one of the nodes you'll reach for constantly once you're moving tensors between steps that disagree about layout.
The key mental model: transpose reorders axes, it does not change the data. A transpose of a 2D matrix is a flip across the diagonal; on higher-rank tensors it's a permutation. That's different from reshape, which reinterprets the same memory as a new shape - and conflating the two is one of the most common beginner bugs in all of torch. This node can't fix your mental model for you, but it gives you a safe place to experiment: transpose a small matrix you know by heart, print it with Tensor → String, and see exactly what swapped.
Inputs
tensor- thecdlTensorto reorder.dim0/dim1- the two axis indices to swap, both widgets (default0and1, range 0–5). For a[H, W, C]→[C, H, W]move you'd swap dims0and2after dropping the batch axis, or1and3if you're handling a[B, H, W, C]in one shot.
Output
One output, output, same cdlTensor type with the two dimensions exchanged. Same dtype, same number of elements, just reordered axes.
Installing it
It's part of ComfyDL. ComfyUI Manager, search "ComfyDL", or:
cd ComfyUI/custom_nodes
git clone https://github.com/Cynthia-lxx/ComfyDL
pip install -r ./ComfyDL/requirements.txt
Restart ComfyUI. Pack-wide dependency is just matplotlib; no models to download.
Gotchas
Out-of-range dimensions are the footgun: dim0/dim1 go up to 5, but your tensor might only have 3 axes, and torch.transpose will throw a runtime error if you ask to swap axis 4 of a rank-3 tensor. If a workflow suddenly dies, check that you're not transposing a nonexistent dimension - it's the node's number one failure mode. Also keep in mind this creates a view (shared memory) in torch, which is fast and memory-free, but it means the output is not a copy; that's an implementation detail that rarely bites in this pack but explains why it's so cheap.
This is a young, niche pack with essentially no community presence, but the mechanism here is a direct torch wrapper, so what you learn debugging it transfers 1:1 to writing torch by hand. Which, honestly, is the point of the whole pack.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| tensor | TENSOR | — | |
| dim0 | INT | 00–5 | — |
| dim1 | INT | 10–5 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| output | TENSOR | — |