ComfyUI Node

Pt Neg

Flip every sign in a tensor at once

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

Pt Neg is the negation node in the HowToSD/ComfyUI-Pt-Wrapper pack - a wrapper around torch.neg that flips the sign of every element. One tensor in, a negated tensor out. It's the kind of node that looks too trivial to justify an article, but it's genuinely one of the most-used math primitives once you're doing any amount of tensor work in a graph, because so many other things are built on top of it.

When you'd reach for it

Negation shows up in boring, essential places. The one you'll actually hit in this pack: flipping losses or scores so you can minimize or maximize the same quantity. If you're training and some loss is being reported as a "higher is better" score, multiplying by −1 turns it into a "lower is better" loss you can plug straight into a training node. It's also how you invert a gradient direction in a pinch, how you turn a tensor of errors into a tensor of corrections, and how you flip a comparison when you're too lazy to reorder your operands - neg(a) > b is the same as a < -b. And of course, if you built a constant with Pt Full and want its negative, this is the two-node way to get it.

How it works

Element-wise -x, keeping the shape and dtype of the input. It works on any numeric tensor type, but not on booleans - -True isn't a thing in PyTorch, so feed it floats or ints. The operation is lazy like everything in torch; the actual flip happens when the tensor gets consumed, so there's no real cost to adding a Neg node mid-graph.

The inputs

  • tens_a - the tensor to negate.

The output is a TENSOR of the same shape and dtype, with every element sign-flipped. That's the whole node.

Installing the pack

Pt Neg ships in the pack's "Data Analysis" (tensor math) category. Install through ComfyUI Manager by searching "ComfyUI-Pt-Wrapper", or manually:

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

Restart ComfyUI. The pack installs a pile of ML dependencies (transformers, datasets, peft, scikit-learn, gensim…), so budget time for the first Manager install. No model downloads are needed for tensor ops.

Common issues

  • Boolean input - negating a bool tensor errors. Cast to a numeric dtype first.
  • Unsigned ints - negating uint8 is asking for trouble; the semantics of unsigned negation are rarely what you want. Use a signed dtype.
  • Nothing else goes wrong - honestly, this node is one operation. The failure modes are almost entirely upstream (feeding it the wrong tensor). If the result looks wrong, check what you gave it.
  • Support reality check - Pt-Wrapper is a single-author educational pack with essentially zero footprint on r/comfyui or r/StableDiffusion. It's a well-documented learning tool, but you're on the author's node reference and example workflows, not a community, when you're stuck.
CategoryData Analysis

Inputs (1)

NameTypeDefaultDescription
tens_aTENSOR

Outputs (1)

NameTypeDescription
TENSORTENSOR