ComfyUI Node Runs on cloud

VAEMergeKJ

Blend two VAEs, if they're actually the same shape

By kijai·Created 3 years ago·Updated 2 days ago· 3,030
VAEMergeKJ
  • vae_1
  • vae_2
  • vae
ratio0.50

Checkpoint merging is a familiar idea - blend two models' weights and get something in between. This node applies the same trick to just the VAE: a straight weighted average of two VAEs' weights, controlled by a single ratio. It's a narrow, niche move. Most people pick a VAE for their model family and never think about it again. But if you've ever run two VAE variants side by side and noticed one fixes color banding while the other keeps saturation better, this is the node that lets you stop choosing and split the difference instead.

How it works

The node's own description is blunt and correct: it merges two VAEs "by weighted-averaging their weights," where ratio is the weight toward vae_2 - 0.0 gives you pure vae_1, 1.0 gives you pure vae_2, and anything in between is a literal tensor-level blend. The important constraint, also stated directly: both VAEs must share the same architecture - matching state dict keys and matching tensor shapes. This isn't a soft recommendation, it's a hard requirement for a weighted average to even be computable.

That constraint matters more than it sounds like it should, because VAE architecture varies a lot across model families, not just across fine-tunes of the same family. SDXL's VAE declares 4 latent channels; Flux, Wan, and Qwen-Image all moved to 16-channel VAEs to carry far more detail through the latent space. Different channel counts mean structurally different tensors - you can't average an SDXL VAE against a Flux VAE any more than you could average a 4-cylinder engine against a V8 and expect it to run. This node is for merging two VAEs that come from the same family: two SDXL VAE fine-tunes, two Wan VAE variants, and so on - not for mixing across generations of models.

The inputs and output that matter

Three inputs, and they're all there is:

  • vae_1 and vae_2 - the two VAEs to blend. Load each with a standard VAE loader first.
  • ratio (default 0.5, range 0.0–1.0) - how far toward vae_2 the blend leans. 0.5 is a straight 50/50 average.

The single output, vae, wires into VAE Decode or VAE Encode exactly like any other loaded VAE - nothing downstream needs to know it's a blend.

How to install it

Part of the KJNodes pack. Through ComfyUI Manager: search "KJNodes for ComfyUI," install, restart. Manually: cd ComfyUI/custom_nodes && git clone https://github.com/kijai/ComfyUI-KJNodes, then pip install -r ComfyUI-KJNodes/requirements.txt (portable Windows build: python_embeded\python.exe -m pip install -r ...), then restart. No extra models or dependencies specific to this node - it's pure tensor math on VAEs you've already got.

Common issues & troubleshooting

An error mentioning mismatched keys or shapes. That's the architecture constraint biting - your two VAEs aren't from the same family. A common mistake is trying to merge a base model's VAE against a VAE meant for a completely different architecture generation; check that both actually belong to the same model line before wiring them in.

The blend doesn't look meaningfully different from either source. A raw weighted average of weights isn't the same as blending the two VAEs' outputs - it's averaging the numbers that produce those outputs, which doesn't always move visual quality proportionally with ratio. Don't assume 0.7 looks "70% like vae_2" - compare actual decoded images at a few ratio values rather than trusting the number alone.

You're not sure this is worth doing at all. Fair - it usually isn't. This is a tool for the specific situation where you've already identified two VAE options that each solve half a problem. If you haven't hit that wall, you don't need this node.

CategoryKJNodes/vae

Inputs (3)

NameTypeDefaultDescription
vae_1VAE
vae_2VAE
ratioFLOAT0.500–1

Outputs (1)

NameTypeDescription
vaeVAE