VAE Math
Merge VAEs with the same per-layer expression trick as Model Math
- a
- b
- c
- d
- VAE
VAE Math is Model Math's smaller sibling: it merges up to four VAEs by running a math expression over their weights. The default a*(1-w)+b*w blends VAE a with VAE b by weight w, which is the same interpolation core ComfyUI's model merge uses, applied to the encoder/decoder instead of the diffusion model. If your images come out grey or washed out and you've been swapping VAEs to fix it, this is how you'd blend two VAEs into one instead of choosing between them.
How it works
A VAE, like a diffusion model, is a pile of weights in a state_dict. This node iterates over the union of weight keys across all input VAEs, binds each layer's weights to a, b, c, d (missing layers get zeros), and evaluates your expression with the usual floats (w, x, y, z) and layer variables (L/layer, LC/layer_count, K/key). The result per layer is diffed against the base VAE, and only the differences become patches applied to a clone of a.
Practically, that means a*(1-w)+b*w gives you a standard weighted blend, and more elaborate expressions let you, say, blend only certain layer ranges. It's real, non-destructive merging - the base VAE is cloned, so your input files never change.
The inputs that matter
a- the main VAE (base), required.b,c,d- optional additional VAEs.Model- the expression applied to the weights. (Yes, the field is literally calledModelhere - an author quirk carried over from the model node.) Defaulta*(1-w)+b*w.length_mismatch-tile/error/pad, defaulterror; the tooltip notes this usually ends up broadcasting for model-like inputs.w,x,y,z- floats.
Output is a single VAE, ready for a VAEDecode.
Installing it
Part of More Math (mcDandy/more_math). ComfyUI Manager - search "More Math" - or:
cd ComfyUI/custom_nodes
git clone https://github.com/mcDandy/more_math
cd more_math
pip install -r requirements.txt
Restart. Dependencies are just antlr4-python3-runtime and torch, no downloads. Needs a current ComfyUI.
Where people get burned
The same class of traps as Model Math, at smaller scale. Merging VAEs of different architectures zero-fills the gaps and produces nonsense - blend VAEs from the same family (same SD 1.5/XL/Flux lineage). And there's the performance note: it evaluates the expression per layer, so it's not instant, though VAEs are far smaller than diffusion models, so this is the fast merge node in the pack.
Worth knowing the context for why you'd bother at all: a mismatched or missing VAE is the classic cause of grey, washed-out output, and standard practice is just to load the right VAE. Blending becomes useful when you want a middle ground - a VAE that keeps one's color character and another's stability. That's a genuine niche, and this node is the clean way to get there. Like its model counterpart, the classic form is deprecated in favor of an autogrow variant; both ship and work.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| a | VAE | Main VAE (base) | |
| Model | STRING | a*(1-w)+b*w | Expression to apply on weights |
| length_mismatch | COMBO | error | How to handle mismatched layer counts. For models, this usually defaults to broadcast (zero for missing layers). |
| bopt | VAE | Optional 2nd VAE | |
| copt | VAE | Optional 3rd VAE | |
| dopt | VAE | Optional 4th VAE | |
| wopt | FLOAT | 0.00 | — |
| xopt | FLOAT | 0.00 | — |
| yopt | FLOAT | 0.00 | — |
| zopt | FLOAT | 0.00 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| VAE | VAE | — |