N Average
The honest average for merging more than two models
- models (delta|param|weight)
- recipe
N Average (class N Average Mecha Recipe) is the merge method for the question everyone asks after their second model: "what if I just average a whole bunch of them?" It takes a list of recipes and returns their equal-weight average - the honest, boring, surprisingly hard-to-beat baseline of model merging.
Why "N" and not just "average"? Because it's built to average an arbitrary number of models, not just two. Two-model averaging you can do with Weighted Sum at alpha 0.5. N Average is what you reach for when the answer is "I have five fine-tunes and I want their centroid."
How it works
The math is a numerically-stable running average, done as a chain of lerps rather than a single big sum-then-divide: it takes the first model, then for each next model blends it in with weight 1/i. That gives each of the N models exactly 1/N of the final result, but it never has to materialize the sum of all N tensors at once - which matters on big models and small VRAM.
Inputs that matter:
- models (delta|param|weight) (
MECHA_RECIPE_LIST) - the recipes to average. Wire them through aMecha Recipe List(orSubtract Recipe Listif you want to average deltas). All of them should live in the same merge space, or the recipe won't validate. - recipe (output) - the averaged model in whatever space you fed in. Send it to Mecha Merger and you're done.
A couple of practical notes. If all your inputs are full checkpoints (weight space), the output is a full averaged checkpoint. If they're deltas, the output is an averaged delta - and you'll need to add a base back before merging into a usable model. And because this is a recipe node, everything is lazy: no merge actually happens until the graph runs, and sd-mecha streams tensors key by key, so averaging four SDXL models doesn't need four SDXL models' worth of VRAM at once.
Install
This node is part of the Mecha Merge Node Pack (ljleb/comfy-mecha):
- ComfyUI Manager → Install Custom Nodes → search "mecha" → Mecha Merge Node Pack, or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/ljleb/comfy-mecha.git
pip install -r comfy-mecha/requirements.txt
Restart ComfyUI. The pack pins a single dependency, sd-mecha==1.1.7; nothing here downloads model files.
Common issues
- Empty or single-item lists behave exactly like you'd fear. An empty list fails; a single model comes out basically unchanged. That's fine - it's just not what the node is for.
- Mixing architectures breaks it. Averaging SD1 and SDXL "works" in the sense that keys match up sometimes, but the tensors won't be the same shape and the merge will fail or produce garbage. Average within one family.
- Averages wash out character. This is the eternal caveat with N Average: the output is the center of your inputs, which means it's usually the least distinctive of them. That's the point when you want a stable base, and the weakness when you wanted a personality.
For many people, N Average is the entire merge workflow: throw three or four good fine-tunes at it, take the centroid, done. It won't win you any merging awards, but it's reliable, it's streaming-friendly, and it's the baseline every fancier method is secretly competing against.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| models (delta|param|weight)opt | MECHA_RECIPE_LIST | — | |
| 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 | — |