Nodes/Latent Tools/LTLatentOp
ComfyUI Node

LTLatentOp

Do Math on Your Latents Without Leaving the Graph

By Machines-of-Disruption·Created about a year ago·Updated 8 months ago· 27
LTLatentOp
  • latent
  • LATENT
op
arg0.000

LTLatentOp applies a unary math operation to a latent's samples: add, mul, pow, exp, abs, clamp_bottom, clamp_top, norm, mean, std, sigmoid, or nop. It's the pack's "tune-up" node - you generate noise, then reshape its statistics before you ever hit the sampler. Think of it as the adjustment layer for the latent space.

This is where the pack stops being a novelty and starts being a toolkit. Generate a Gaussian noise with LTGaussianLatent, blend it, load a saved pattern, and then use LTLatentOp to fix whatever drifted. The author's examples show an abs pass turning a clean gaussian into a half-wave rectified mess that the model then interprets in weird, occasionally gorgeous ways.

How it works

Every op is a direct torch call on latent["samples"] - no model involved, no weights, effectively free. The ones worth knowing by heart:

  • norm - z-score the whole latent: zero mean, unit variance. This is the "fix it" button for a latent whose stats drifted away from what the model expects.
  • mean - shifts so the actual mean equals arg.
  • std - rescales so the actual standard deviation equals arg.
  • clamp_bottom / clamp_top - clip values to arg.
  • add, mul, pow, exp, sigmoid - the exotic shaping tools.
  • nop - literally nothing. Handy for keeping a branch alive without changing values.

The inputs that matter

  • latent - input LATENT.
  • op - the 12-way dropdown.
  • arg - the float argument, with a tooltip that saves you confusion: ignored for exp, abs, norm, and sigmoid. Don't go looking for a value that isn't used.

Where people get burned

The mean and std ops are not the same thing as the mean/std inputs on LTGaussianLatent. Those generate noise with a target distribution; these recompute and fix the distribution of whatever latent is already sitting there. Easy to mix up, so keep it straight: generator vs. editor.

Also remember every op changes the noise that the sampler sees. If you normalize a noise you carefully shaped with a specific std, you've just thrown away the shaping - chain ops deliberately (generate → clamp → norm) rather than on a whim.

Installing it

Part of xl0's Latent Tools pack. ComfyUI Manager → search Latent Tools → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/xl0/latent-tools

Restart, and it's under LatentTools. The pack's only dependency is lovely-tensors (Manager installs it; manual cloners may need pip install lovely-tensors). No model files - this node is pure tensor arithmetic and runs in milliseconds.

CategoryLatentTools

Inputs (3)

NameTypeDefaultDescription
latentLATENT
opCOMBO12 options: add, mul, pow, exp, abs, clamp_bottom, +6
argFLOAT0.000-99999–99999Ignored for exp, abs, normalize and sigmoid

Outputs (1)

NameTypeDescription
LATENTLATENT