Pt Mul
Element-wise multiply — the scaling workhorse
- tens_a
- tens_b
- TENSOR
Pt Mul is element-wise multiplication - torch.mul - the operation that scales tensors, weights them, and applies masks. It's the most reachable node in the arithmetic family because its only rule is that shapes broadcast. No inner-dimension matching like matrix multiply, no strict ranks. Two tensors in, same-shape tensor out, each element multiplied by its partner.
How it works
Required inputs tens_a and tens_b, both TENSOR, one TENSOR output. Implementation: torch.mul(tens_a, tens_b). That's it. The reason it's so flexible is broadcasting - a 1-element tensor (or scalar-shaped tensor) multiplies every element of a big tensor, and two same-shape tensors combine element by element.
The three things it actually gets used for
Scaling. Want to multiply every value in a tensor by 0.5? Create a 1-element tensor with the pack's tensor-create node and multiply. That's the graph's version of x * 0.5, and it's everywhere - learning-rate-style adjustments, gain on a feature map, attenuation of a signal.
Masking. Multiply a feature tensor by a 0/1 mask and the masked-out positions go to zero. This is the mechanism behind attention masking and region gating, and it's why the pack's Transformer-from-scratch examples lean on it. (Boolean masks need a cast to numbers first, since the logical nodes output torch.bool.)
Element-wise weighting. Two tensors of the same shape, multiply, and you've applied per-element weights - a Hadamard product. That's how you'd weight a batch of samples differently, or blend two aligned feature maps.
The confusion that costs people time
Pt Mul is not matrix multiplication. mul = element-wise (just needs broadcastable shapes); mm/matmul = matrix product (inner dimensions must match). Type "mul," feed it a (2, 3) and a (3, 4), and you'll get a broadcast error instead of a (2, 4) product - the shapes are "wrong" for element-wise because there's no inner-dimension concept at all. If you're doing linear algebra, use Pt Mat Mul or Pt Mm.
Installing
Pt Mul ships in the HowToSD/ComfyUI-Pt-Wrapper pack under the "Data Analysis" menu. 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 the training side; this node needs only PyTorch, already present. 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 (2)
| Name | Type | Default | Description |
|---|---|---|---|
| tens_a | TENSOR | — | |
| tens_b | TENSOR | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TENSOR | TENSOR | — |