Pt Max
The max along a dimension, values only — no argmax
- tens
- TENSOR
Pt Max computes the maximum along a dimension - and returns only the values, not the positions. It's torch.amax (not torch.max), which is the detail that trips people up: amax gives you the biggest numbers, but if you want to know where they were, you're out of luck with this node. That's a deliberate choice and it covers the common cases.
How it works
Three inputs:
- tens - the TENSOR to reduce.
- dim - a STRING field (multiline) that takes
0,[0], or(1, 2). It's parsed, so you can reduce over one axis or several at once. Leave it empty and you get the global max over everything. - keepdim - a boolean, default off. On, the reduced axis stays around as a size-1 dimension; off, it's gone.
The implementation is torch.amax(tens, dim=dim, keepdim=keepdim). Nothing clever, which is exactly right.
keepdim: the thing people skip and then regret
It's worth understanding because it quietly changes what you can do next. With keepdim=True, a (b, c, h, w) tensor reduced over (2, 3) becomes (b, c, 1, 1) - still broadcastable against the original, which is what you need if you're about to divide, subtract, or normalize by the max. With keepdim=False you get (b, c), which is cleaner but won't line up against the source tensor without a reshape. Rule of thumb: if the max feeds back into a computation with the original tensor, keep it.
Where it fits
Global max pooling is the classic use - collapsing spatial dimensions before a classifier head, the same operation the pack's ResNet and Transformer examples rely on. It's also how you'd find the peak of an attention map or the extreme of a loss tensor. Combined with Pt Min, it gives you the range of any tensor.
Gotchas
Values only, remember - no argmax indices. And the dim string is parsed as Python: (1, 2) is a tuple, [0] is a list, both fine, but stray characters will throw. The output is the same dtype as the input.
Installing
Pt Max rides in the HowToSD/ComfyUI-Pt-Wrapper pack under "Data Analysis." ComfyUI Manager: search ComfyUI-Pt-Wrapper, install, restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
The heavy requirements (transformers, peft, accelerate…) are for training; max needs only PyTorch. Skip the pip line for math-only use. No models to download.
Pack-wide: the TENSOR type is separate from ComfyUI's IMAGE/LATENT - convert with Pt From Image (Pt From Image Transpose for (b, c, h, w)) and Pt To Image.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| tens | TENSOR | — | |
| dim | STRING | — | |
| keepdim | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TENSOR | TENSOR | — |