Nodes/ComfyUI-nodes-hnmr/StateDictMerger
ComfyUI Node

StateDictMerger

Merge two checkpoints (or three, with add-difference) without leaving ComfyUI

By CYBERLOOM-INC·Created 3 years ago·Updated 2 years ago· 11
StateDictMerger
  • model_A
  • model_B
  • model_C
  • DICT
alpha0.000
position_ids
half

Model merging is how a huge share of the checkpoints on CivitAI were born - blend two parents, get a child that inherits a bit of both, no training run required. StateDictMerger is the in-ComfyUI way to do it, working on raw weight dicts (DICTs from StateDictLoader) and producing a merged DICT you can either save or sample from immediately.

With two models plugged into model_A and model_B, it does a classic weighted sum: A*(1-alpha) + B*alpha. With alpha at 0 you get pure A; at 1, pure B; anything between is the blend. The alpha slider actually spans -1 to 2, which lets you extrapolate beyond the two parents - negative or above-1 values exaggerate the difference between them, a trick people use to push a merge further in one direction. Note the default is 0 (pure A), which confuses people who expect a 50/50 default.

Plug a third model_C in and it switches to add difference: A + alpha*(B - C). This is the "style extraction" flavor of merge - C is a base you want to subtract, B is a model built on that base, and the difference captures B's special sauce, which gets added to A. Same alpha meaning, different math.

The other two inputs handle details you should mostly leave alone until you need them. position_ids (A / B / Reset) deals with SDXL's positional embeddings - pick which parent's position ids survive, or "Reset" to rebuild them from scratch for a 77-token sequence. half (True/False) controls whether the merged weights are stored in fp16 (half the memory, standard for use) or fp32.

The merge itself is a simple per-tensor loop with a progress bar, and it prints which keys exist in only one model - harmless warnings, but worth reading if your parents were trained on different structures.

Install via ComfyUI Manager (search "ComfyUI-nodes-hnmr") or:

cd ComfyUI/custom_nodes
git clone https://github.com/CYBERLOOM-INC/ComfyUI-nodes-hnmr

Restart ComfyUI. No model files to download.

The honest caveat, grounded in years of community experience: averaging weights works, but it also produces the convergence people complain about - blend too aggressively and you get a model that's weaker at both parents' strengths. Merging is fast and free; it's also easy to overdo. To use the merged dict, wire it into Dict2Model for immediate sampling, or SaveStateDict to write a .safetensors file. And remember: this is the maintained fork of hnmr293's pack - install the CYBERLOOM-INC repo, since the original stopped getting fixes and broke on modern ComfyUI.

Categorymodel

Inputs (6)

NameTypeDefaultDescription
model_ADICT
model_BDICT
alphaFLOAT0.000-1–2
position_idsCOMBO3 options: A, B, Reset
halfCOMBO2 options: True, False
model_CoptDICT

Outputs (1)

NameTypeDescription
DICTDICT