Nodes/ComfyUI-latent-ops/LatentOperationAdd
ComfyUI Node

LatentOperationAdd

Add two latents together — but only when something applies the op

By hnmr293·Created about a year ago·Updated about a year ago· 2
LatentOperationAdd
  • value
  • op

Latent arithmetic is the unglamorous core of a lot of advanced workflows - add a detail latent back, mix two encodings, inject structure. LatentOperationAdd does the "add two latents" part. But here's the thing the name hides: it doesn't add anything at the moment you run it. It hands back a recipe.

This is the defining pattern of hnmr293's ComfyUI-latent-ops pack, and it's worth understanding before you touch any of the LatentOperation nodes, because it'll save you a genuine "why is this not connected" headache.

How it works

Feed it a LATENT in the value input, and the op output isn't a latent - it's a Python closure. The closure captures value, and when it's finally called with a target latent, it returns target + value, elementwise. Everything else in the pack that says "Operation" works the same way: each node builds one small function (latent → transformed latent) and hands it out as a custom LATENT_OPERATION type.

The catch, and it's an important one: this pack ships no node that applies an op to a latent. There's no "Apply" node in the repo. So wiring op straight into VAE Decode won't work - the types don't match, and the frontend will refuse to connect them. The intended setup is that you feed the op output into a consumer node that accepts a LATENT_OPERATION input (the author's own workflows use one), or you write a tiny custom node that calls op(latent["samples"]). If you don't have a consumer, this node is inert no matter what you do.

What matters

  • value - a LATENT to add. It must be broadcastable with the latent you eventually apply the op to; same spatial dims is the safe assumption.
  • op - the only output. A deferred operation, not a result.

Installing it

Same pack, same trivial install: no requirements.txt, no model downloads, pure torch. ComfyUI Manager → search "ComfyUI-latent-ops" → install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/hnmr293/ComfyUI-latent-ops

Restart ComfyUI; it's under hnmr/latent_ops.

Troubleshooting

If your graph complains about an unconnectable op output, that's the design, not a bug - you're missing the apply step. If the values are wildly wrong once applied, the culprit is almost always shape: two latents that don't broadcast cleanly add into nonsense. And if you expected value to be a number, you grabbed the wrong node - the constant-offset version is LatentOperationAddBroadcast. Same idea, but the value is a plain FLOAT you can tune without another encode step.

Categoryhnmr/latent_ops

Inputs (1)

NameTypeDefaultDescription
valueLATENT

Outputs (1)

NameTypeDescription
opLATENT_OPERATION