ComfyUI Node

Pt Div

Pt Div — element-wise division, the humble node that saves you a step

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

PtDiv divides one tensor by another, element by element. That's it - no cleverness, no options, just tens_a / tens_b as a node. It doesn't sound like much until you need to normalize a tensor, convert pixel values to a 0–1 range, compute a ratio between two feature maps, or scale something down mid-pipeline and you realize ComfyUI's built-in math nodes weren't made for tensors. That's the gap this fills.

It's part of ComfyUI-Pt-Wrapper, HowToSD's no-code PyTorch toolkit. The Pt* arithmetic nodes are the pack's bread and butter - a whole drawer of element-wise operations (PtAdd, PtMul, PtSub, PtPow, and this one) so you can do real tensor math in the graph without a custom-script node. If the pack has a theme, it's "every torch call you'd write in a notebook, now a node."

How it works

One line under the hood: torch.div(tens_a, tens_b). Because it's torch's divide, you get broadcasting for free - tens_b can be a smaller shape that expands to match tens_a, like dividing every row of a matrix by a per-column scale vector. That broadcasting is the difference between this node being useful and being a chore.

Inputs that matter

  • tens_a - the numerator tensor.
  • tens_b - the divisor tensor. Same shape as tens_a, or broadcastable to it.

Output is a TENSOR in the same shape as tens_a. Wire it anywhere you'd feed a tensor - into a plotting node, into a loss computation, into a model input.

Installing it

ComfyUI Manager → Install Custom Nodes → search "Pt Wrapper" → install → restart, or:

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

Restart ComfyUI after. First install is slow (matplotlib, pandas, scipy, scikit-learn, transformers, datasets, pinned gensim) - this node itself needs nothing but torch.

Common issues

The classic divide-by-zero situation deserves a heads-up: with float tensors, dividing by zero doesn't error - you get inf or nan, which then quietly poisons every downstream calculation. If your output starts looking like a sea of NaN, check the divisor. Also watch dtypes: dividing two integer tensors does floor-style truncation in torch, so if you want real ratios, make sure at least one input is float. Most beginners hit that one.

CategoryData Analysis

Inputs (2)

NameTypeDefaultDescription
tens_aTENSOR
tens_bTENSOR

Outputs (1)

NameTypeDescription
TENSORTENSOR