ComfyUI Node

Pt Permute

Pt Permute is the transpose glue of this pack

By HowToSD·Created about a year ago·Updated about a year ago· 7
Pt Permute
  • tens
  • TENSOR
new_axes

PtPermute rearranges the dimensions of a tensor - torch.permute() as a node. You give it the new order of axes as text like [0, 3, 1, 2], and it returns a tensor with the dimensions shuffled to match. It's the most-used utility node in this pack's image path, because the pack's tensors are channels-first (b, c, h, w) while ComfyUI's native images are channels-last (b, h, w, c) - and getting from one convention to the other is a permute, nothing more.

How it works

Two inputs:

  • tens - any tensor, any rank.
  • new_axes - a text field holding the permutation as a list, e.g. [0, 3, 1, 2]. Each index names where that original axis should go. The example from the source: a (2, 3, 96, 32) tensor with [0, 3, 1, 2] becomes (2, 32, 3, 96).

Output is a single TENSOR with the same data, reordered. It's a view-like operation in spirit - cheap, no data movement beyond what permute requires.

The two permutations you'll memorize

The pack's own docs drill these in, and they're worth repeating because they're the whole game:

  • IMAGE → tensor: ComfyUI gives you (b, h, w, c). After Pt From Image, permute with (0, 2, 3, 1) to get (b, c, h, w) - channels second, ready for model nodes and Pt Pad.
  • tensor → IMAGE: after your processing, permute back with (0, 3, 1, 2) from (b, c, h, w) to (b, h, w, c), then Pt To Image.

Mixing these up is the classic silent-failure mode: the node won't error, but every image comes out transposed or color-mangled. Write the two permutations on a sticky note if you're new to this pack.

The parsing gotcha

new_axes must parse as a Python list or tuple of integers - [0, 2, 3, 1] is the canonical form. Each axis index has to be valid for the tensor's rank, and the set of indices must be exactly a permutation of 0..rank-1. Leave one out or repeat one and you'll get a runtime error; the node does validate that it's all integers, but a bad-but-parseable list still fails downstream. No tensors are copied needlessly here - permute is a cheap axis shuffle, so feel free to use it liberally in pipelines.

Installing it

Part of ComfyUI-Pt-Wrapper (HowToSD's no-code PyTorch pack, a spin-off of ComfyUI-Data-Analysis). ComfyUI Manager → search "ComfyUI-Pt-Wrapper", or:

cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper

Restart after; first boot is slow while pandas, scikit-learn, transformers, sentencepiece, peft and friends install. No model downloads needed.

CategoryData Analysis

Inputs (2)

NameTypeDefaultDescription
tensTENSOR
new_axesSTRING

Outputs (1)

NameTypeDescription
TENSORTENSOR