ComfyUI Node

Pt Mm

Matrix multiply, but strictly 2D only

By HowToSD·Created about a year ago·Updated about a year ago· 7
Pt Mm
  • tens_a
  • tens_b
  • TENSOR

Pt Mm is torch.mm - matrix multiplication with a strict rule: both inputs must be exactly 2D. It's the picky sibling of Pt Mat Mul, which handles batched and mixed-rank inputs. For plain linear algebra - a weight matrix times a vector, a rotation, a projection - this is the tighter tool, and its strictness is a feature: it catches shape mistakes at the node instead of silently broadcasting them away.

How it works

Two required TENSOR inputs, tens_a and tens_b, one TENSOR output. The implementation checks both are rank-2 and raises a clear ValueError if not ("torch.mm() only supports 2D tensors"), then runs torch.mm(tens_a, tens_b). The inner-dimension rule applies as usual: (m, k) × (k, n)(m, n).

Why both nodes exist

There's real overlap, and you'll wonder which one to grab. The honest answer: Pt Mat Mul is the general-purpose one - same math, plus batched support and vector promotion. Pt Mm is the strict one. For most workflows you could use either and get the same numbers on 2D inputs. Where Mm earns its place is when you want the guardrail - if your pipeline is supposed to stay 2D and a stray batch dimension would break the math downstream, Mm fails loudly instead of quietly doing something surprising. And if you're debugging, a ValueError with a message beats a wrong shape half a graph later.

The thing to keep separate is Pt Mul (element-wise). People type "mul," get the wrong operation, and burn ten minutes wondering why their numbers look nothing like a product. Mm and Mat Mul are matrix products; Mul is per-element scaling.

Installing

Pt Mm is part of the HowToSD/ComfyUI-Pt-Wrapper pack under the "Data Analysis" menu - one install, ~200 nodes. ComfyUI Manager: search ComfyUI-Pt-Wrapper, install, restart. Manual:

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

The pack's heavy requirements.txt (transformers, peft, accelerate…) serves the training side; mm needs only PyTorch, already installed. Skip the pip line for math-only work. No models to download.

Pack-wide note: everything uses the custom TENSOR type, separate from ComfyUI's IMAGE/LATENT - convert with Pt From Image (Pt From Image Transpose for (b, c, h, w)) and Pt To Image.

CategoryData Analysis

Inputs (2)

NameTypeDefaultDescription
tens_aTENSOR
tens_bTENSOR

Outputs (1)

NameTypeDescription
TENSORTENSOR