CLIP Math
Fuse two text encoders like it's a checkpoint merge
- V
- F
- Expression
- stack
- CLIP
- STACK
Everyone merges checkpoints. Almost nobody merges CLIP models, even though the text encoder shapes your prompt understanding just as much as the UNet shapes the image. CLIP Math from More Math is the node that makes it easy: you feed it two or more CLIP models and a formula, and it blends their weights into a single patched CLIP.
What it's for
If you've ever downloaded a checkpoint whose text encoder was trained for a different style or language set, you know the pain: prompts land slightly off until you swap in a different CLIP. Merging two text encoders - say one strong on anatomical terms and one strong on art style - gives you both without retraining anything. The default expression I0*(1-F0)+I1*F0 is a straight weighted blend of CLIP V0 and V1 by float F0. Want the fusion to favor one encoder in early layers and another later? That's an if on the layer key inside the expression, because you have the same full expression language here that the model merge node has.
Under the hood it's the shared model-like implementation: the node walks the union of state-dict keys across all input CLIPs, evaluates your formula per tensor, and applies the result as patches on a clone of the base CLIP. Missing layers broadcast from whichever input provides them.
Inputs and outputs
V is the autogrow list of CLIPs (V0, V1, ...), F the floats (F0, ...), Expression the formula. length_mismatch handles differing layer counts - default error, with tile, pad, and do nothing; the tooltip notes that for model-like nodes this "usually defaults to broadcast (zero for missing layers)."
Outputs are CLIP and STACK. The merged CLIP feeds the same places a CLIP feeds: a CLIP Text Encode node, a prompt encoder, or back into the checkpoint pipeline.
Installing it
Standard for 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 find "More math" in ComfyUI Manager. Only dependency beyond torch is antlr4-python3-runtime. No models to download.
Notes and gotchas
Two things to keep in mind. First, this is the autogrow (_ag_) version - the pack also ships a legacy mrmth_CLIPMathNode with fixed a/b/c/d inputs, which is deprecated. Workflows you find in the wild may use either; both work, but new work should use this one. Second, CLIP merge is subtle: a formula that looks reasonable on paper can produce a text encoder that's worse than either parent, and you won't see it until you compare prompt adherence. Test at low cost - a couple of prompts, a fixed seed - before committing. The pack is new and solo-maintained, so this is early-adopter territory, but for anyone doing serious checkpoint engineering, being able to write the text-encoder merge as an expression is genuinely new ground.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| V | COMFY_AUTOGROW_V3 | — | |
| F | COMFY_AUTOGROW_V3 | — | |
| Expression | STRING,SYNTAX_TREE | V0 | Expression to apply on weights |
| length_mismatch | COMBO | error | How to handle mismatched layer counts. |
| use_compute_device | BOOLEAN | true | Temporarily copies CLIP patch tensors to the compute device for math and moves the patches back afterwards. |
| stackopt | STACK | Access stack between nodes |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| CLIP | CLIP | — |
| STACK | STACK | — |