Nodes/More Math/VAE Math
ComfyUI Node

VAE Math

The VAE merger nobody else bothered to make

By mcDandy·Created about a year ago·Updated 3 days ago· 5
VAE Math
  • V
  • F
  • Expression
  • stack
  • VAE
  • STACK
length_mismatcherror
use_compute_devicetrue

ComfyUI will merge your checkpoints and, with the right pack, your CLIPs - but try to merge two VAEs and you're on your own. VAE Math from More Math fills that gap: it takes two or more VAEs, runs a formula over their weights, and hands you a blended VAE. It's the least-hyped node in the pack and quietly one of the more unusual ones.

What it's for

VAE merges are a real thing people attempt: mixing a VAE with strong detail retention and one with better color handling, or blending a fine-tuned VAE into a base model's decoder without touching the encoder. The default expression is the pack's standard I0*(1-F0)+I1*F0 - a weighted blend of VAE V0 and VAE V1 by float F0. Because it's the same expression engine as the model and CLIP merge nodes, you can get as specific as you like: blend encoder and decoder blocks differently, or weight layers by name with if.

Mechanically it's the shared model-like implementation: union of state-dict keys across all input VAEs, one expression evaluation per tensor, patches applied to a clone. Missing layers broadcast from whichever VAE has them.

Inputs and outputs

V is the autogrow VAE list (V0, V1, ...), F the floats, Expression the formula. length_mismatch defaults to error (with tile, pad, do nothing) for mismatched layer counts; like the other model-like nodes, missing layers broadcast as zeros.

Outputs are VAE and STACK. The result feeds any VAE slot - VAE Encode, VAE Decode, or straight into a checkpoint pipeline where ComfyUI will happily use your merged VAE.

Installing it

Identical to the rest of the pack:

cd ComfyUI/custom_nodes
git clone https://github.com/mcDandy/more_math
cd more_math
pip install -r requirements.txt

Restart ComfyUI, or install "More math" via ComfyUI Manager. Dependency is antlr4-python3-runtime on top of torch. No downloads, no models.

Gotchas

A merged VAE is the easiest thing in the world to break and the hardest to notice - a subtly wrong decoder doesn't crash, it just makes images slightly mushy or slightly banded. So test a merged VAE by decoding the same latent through the parent VAEs and the merged one, side by side, before you trust it. Also: VAE weight magnitudes can differ between models, so a naive 0.5/0.5 blend can land outside the sensible range; clamp and remap are right there in the expression language if you need to tame it. And as with everything in this pack, it's new and solo-maintained, so pin the version once you find a blend you like.

CategoryMore math

Inputs (6)

NameTypeDefaultDescription
VCOMFY_AUTOGROW_V3
FCOMFY_AUTOGROW_V3
ExpressionSTRING,SYNTAX_TREEV0Expression to apply on weights
length_mismatchCOMBOerrorHow to handle mismatched layer counts. For models, this usually defaults to broadcast (zero for missing layers).
use_compute_deviceBOOLEANtrueTemporarily copies VAE tensors to the compute device for math and moves the patches back afterwards.
stackoptSTACKAccess stack between nodes

Outputs (2)

NameTypeDescription
VAEVAE
STACKSTACK