ComfyUI Node

Subtract

How you build a delta, the move every good merge starts with

By ljleb·Created 3 years ago·Updated about a month ago· 101
Subtract
  • a (weight)
  • b (weight)
  • recipe
merge_checkpointingfalse

Most serious merges aren't a single blend. They're built from deltas - "what makes model B different from model A" - and deltas only exist if you can subtract one model from another. The Subtract node in comfy-mecha is exactly that: a − b, output as a difference vector.

Two required inputs, both in the (weight) space:

  • a (weight) - the model you subtract from
  • b (weight) - the model you subtract

The output is a MECHA_RECIPE in the delta space: a set of per-key differences, not a full model. That distinction is the whole point. A delta on its own isn't a usable model - it has no base to stand on - which is why mecha's validation is happy to remind you when you're about to merge a bare delta into a checkpoint. The intended move is to add it back: Subtract (B − A) → feed the delta into Add Difference or Weighted Sum on top of A, and you get "B minus A, applied at whatever strength you like."

Why you'd reach for it

This is the node behind the classic clipped add difference recipe: compute B − A, scale the delta, add it to A. It's how you do "B but fix A's style," how you isolate what one checkpoint learned, and - in a LoRA-merge workflow - how you turn a pair of models into the difference vectors that TIES and friends eat as input.

How it works

Per tensor key, a[key] − b[key], streamed one key at a time. Because subtraction is element-wise and needs no cross-key logic, it's one of the cheapest nodes in the pack memory-wise - a good first merge node to play with. It doesn't normalize, doesn't mask, doesn't scale; it's raw difference. Scale and mask come from the nodes around it.

Install

Pack-level: ComfyUI Manager → search "mecha" → Mecha Merge Node Pack, or:

cd ComfyUI/custom_nodes
git clone https://github.com/ljleb/comfy-mecha.git
pip install -r comfy-mecha/requirements.txt

Restart ComfyUI. Only dependency is sd-mecha; no model downloads.

Gotchas

The recurring beginner trap is wiring a delta straight into Mecha Merger and wondering why the output is garbage - you've built a difference vector, not a model. Always route it back through an add on top of a base. And mind the space labels: Subtract wants both inputs in (weight) space (full models), and hands you a delta. If you feed it a delta instead, you're subtracting differences from differences, which is usually not the recipe you meant. The merge_checkpointing toggle is the same as the rest of the pack: fp16 CPU caching for stable branches, don't stack with cache units.

Categorymecha

Inputs (3)

NameTypeDefaultDescription
a (weight)MECHA_RECIPE
b (weight)MECHA_RECIPE
merge_checkpointingoptBOOLEANfalseSpeeds up an entire branch of a merge graph that does not change often in exchange of memory. - true: store the first output of this recipe node on cpu memory in fp16. On subsequent workflow executions, as long as the inputs do not change, the cached keys are returned after being cast to the original device and dtype. - false: do not store the output. The recipe and its inputs will re-execute on subsequent workflow executions. Note that the memory used to checkpoint the output is distinct from the cache feature. In general, you probably want to either use this *or* a cache unit, but not both at the same time because the memory adds up. The difference between merge checkpointing and cache is that merge checkpointing completely re-merges from scratch if any input changes. Merge checkpointing is also generally much faster than cache in the fast path.

Outputs (1)

NameTypeDescription
recipeMECHA_RECIPE