Nodes/Mecha Merge Node Pack/Train Difference
ComfyUI Node

Train Difference

The mask that keeps only what a fine-tune actually learned

By ljleb·Created 2 years ago·Updated 29 days ago· 101
Train Difference
  • a (delta|param|weight)
  • b (delta|param|weight)
  • c (delta|param|weight)
  • alpha (1.0)
  • recipe
merge_checkpointingfalse

Plain weighted sums treat every tensor in a model the same. Train Difference is the opposite instinct: it computes a per-tensor weight mask that says where one model actually learned something new, and hands you that mask to drive a merge. If you've ever merged a fine-tune onto a base and felt like you got the noise with the signal, this is the node that tries to keep just the signal.

What it actually does

Train Difference sits in the "task arithmetic" family of merges - the same delta-thinking behind TIES and the other difference-based recipes. You feed it three recipes:

  • a - your base model
  • b - the fine-tune whose changes you want to keep
  • c - a reference model (often another fine-tune, or the base again)

For every tensor it computes roughly alpha * 1.8 * |b−a| / (|b−a| + |b−c|). Where the fine-tune b is very different from the base a (and that difference dominates its difference from c), the weight heads toward 1.8; where b barely moved, it heads toward zero. So the output isn't a model - it's a mask, a recipe in the "param" merge space.

Wiring it up

That mask is the input that matters: it plugs into the alpha port of a Weighted Sum Mecha Recipe. You merge a and b with the Train Difference mask as the weight, then feed the result into a Mecha Merger to get a UNet and text encoder. Load your three inputs with Mecha Model Recipe nodes (LoRAs work too, via Mecha Lora Recipe - everything here speaks MECHA_RECIPE).

The only inputs you'll normally touch are a, b, c, and alpha (default 1.0). alpha scales the whole mask; drop it to 0.5-ish if a full-strength merge looks overcooked. Each input socket is labeled with the merge spaces it accepts (delta|param|weight), which is mecha's way of validating you haven't wired a full checkpoint into a slot that wants a delta. Output is a single recipe - wire it into the alpha of a weighted sum.

Installing it

This is one node in the Mecha Merge Node Pack, by Louis-Jacob Lebel (ljleb), the same person behind the sd-mecha library that powers it. It's a specialist tool - the announcement post on r/StableDiffusion got a modest handful of upvotes and it stays that way, because model merging is a niche within a niche. Install via 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

The only dependency is sd-mecha==1.1.7. No model files to download - it merges whatever checkpoints and LoRAs you already have, one tensor at a time, which is the whole low-memory pitch.

Gotchas

Where people get burned: wiring a, b, c from incompatible architectures (an SDXL fine-tune against an SD1.5 base throws immediately - mecha's recipe validation refuses to make a mess), and treating the 1.8 scale as sacred. It's a heuristic, not a law; the community wisdom on merging is that coherence degrades fast the more parents you drag in, so start small and judge on output, not on how clever the graph looks. And note the merge_checkpointing toggle: it caches the whole branch in fp16 on CPU for fast re-runs, but you usually want it or a cache unit, not both - the memory adds up.

Categorymecha

Inputs (5)

NameTypeDefaultDescription
a (delta|param|weight)MECHA_RECIPE
b (delta|param|weight)MECHA_RECIPE
c (delta|param|weight)MECHA_RECIPE
alpha (1.0)optMECHA_RECIPE1
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