ComfyUI Node

Slerp

The merge that goes around, not through

By ljleb·Created 2 years ago·Updated 30 days ago· 101
Slerp
  • a (delta|param|weight)
  • b (delta|param|weight)
  • alpha (0.5)
  • recipe
merge_checkpointingfalse

Weighted sums move in a straight line between two models: at 50%, every tensor is exactly the midpoint. Slerp - spherical linear interpolation - doesn't take the straight line. It treats model weights as directions on a hypersphere and walks along the arc between them instead. Same endpoints, different path, and for some merges that path keeps the result from collapsing into a bland average. The Slerp node in comfy-mecha brings that to your recipe graph.

It's a merge method node: two recipe inputs in, one MECHA_RECIPE out.

  • a (delta|param|weight) and b (delta|param|weight) - the two things to interpolate. They can be full models, deltas, or params, as long as both sit in the same space.
  • alpha (0.5) - where you land along the arc. 0 returns a, 1 returns b, 0.5 is the midpoint. And because mecha lets a param be a recipe, alpha can be per-component or per-block weights if you want to slerp the UNet at 0.6 but the text encoders at 0.3.

The output is a MECHA_RECIPE. Wire it onward, or into Mecha Merger for a usable model.

How it works

The implementation normalizes both sides, finds the angle between them, and interpolates the direction along that angle while scaling by the interpolated magnitude. If the two models are degenerate - identical direction, or near-opposite - it falls back to a plain lerp so it doesn't divide by a zero sine. That's the whole algorithm, per tensor, one key at a time, which is why it runs happily in low memory like the rest of the pack.

Where slerp earns its keep

It's genuinely a "taste" thing. Some checkpoints slerp beautifully - the blend keeps more of each model's character than a weighted sum does - and some just produce mush either way. It's also a favorite in the LoRA-merge crowd as an alternative to plain addition. The honest take: run it as an experiment, keep the weighted sum as your baseline, and let the samples decide. It's one node, one toggle, and the output plugs into the same downstream nodes either way.

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

Slerping full checkpoints that are far apart in weight space can push the result toward coherent-but-degenerate behavior - the arc keeps magnitude, which isn't always what you want. And alpha as a plain number behaves exactly like a weighted sum's alpha, so if you expected a magical difference, sample first. The merge_checkpointing toggle on this node behaves like everywhere else in the pack: cache a stable branch's output in fp16 on CPU to skip re-merging on repeat runs, and don't stack it with cache units.

Categorymecha

Inputs (4)

NameTypeDefaultDescription
a (delta|param|weight)MECHA_RECIPE
b (delta|param|weight)MECHA_RECIPE
alpha (0.5)optMECHA_RECIPE0.5
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