Exchange Ema
Swap in the EMA weights before you merge — they're usually the better half
- model (delta|param|weight)
- recipe
Some SD1.5 checkpoints ship two copies of every weight inside one file: the "online" weights the training loop actually stepped, and the EMA (exponential moving average) weights - a smoothed, delayed-average version that almost always generates better-looking images. Most UIs just quietly use the online weights and you never notice the second copy exists. This node makes the hidden copy mergeable: Exchange Ema takes a model recipe and swaps each weight for its EMA counterpart (or back), so you can merge with the good half instead of the default half.
How it works
The node looks for the EMA twin of each key. In the standard SD1.5 layout, training saves model.diffusion_model.* and model_ema.diffusion_model* alongside each other. Exchange Ema Mecha Recipe walks the model's keys and, for every tensor, substitutes the matching EMA key (stripping the prefix and dots - the EMA dict uses a flattened naming, so model_ema.diffusion_modelinput_blocks style keys). Anything without an EMA twin passes through untouched. The swap is implemented as an sd-mecha merge method, so it's lazy and streaming like everything else in the pack: it doesn't load the whole checkpoint, just shuffles keys on the fly while a Mecha Merger executes the recipe.
Inputs:
model (delta|param|weight)- a model recipe, typically fromModel Mecha Recipe. It accepts any merge space, though it's most useful on a plain weight.
Output: one recipe (MECHA_RECIPE) with the EMA weights in place of the online ones. Run it through Exchange Ema again and you get the originals back - it's its own inverse.
Why you'd want this
Two workflows, both worth it:
- Merge with the EMA weights. If the checkpoint's EMA half is the pretty one (it usually is - EMA averages out the late-training wobble), swap before a
Weighted SumorAdd Differenceand the whole merge inherits that quality. - Extract the EMA difference as a delta. Subtract the non-EMA model from the EMA-swapped one and you get the "EMA delta" - a recipe that represents exactly what the smoothing changed. That's a surprisingly useful ingredient for fine corrections, and the kind of thing the mecha Discord's chaos-lab crowd actually experiments with.
The merge_checkpointing toggle caches the swapped branch on CPU in fp16 for repeated runs, as with every recipe node in this pack.
Install & gotchas
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 after. Dependency is sd-mecha==1.1.7.
The catch, honestly: this swap is implemented for the SD1.5 key layout, and SDXL-era checkpoints generally dropped the dual-weight convention - if your model has no model_ema.* keys, this node is a no-op that just passes the model through. That's not a bug; there's simply nothing to swap. Also, if you're swapping then merging with a different checkpoint, remember the swap only applies to this branch of the graph - you'd want to swap each model that carries EMA weights, not just one.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| model (delta|param|weight) | MECHA_RECIPE | — | |
| merge_checkpointingopt | BOOLEAN | false | Speeds 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)
| Name | Type | Description |
|---|---|---|
| recipe | MECHA_RECIPE | — |