Nodes/More Math/Conditioning math
ComfyUI Node

Conditioning math

Blend two prompts with a math expression instead of another node

By mcDandy·Created about a year ago·Updated 3 days ago· 5
Conditioning math
  • a
  • b
  • c
  • d
  • CONDITIONING
Tensora*(1-w)+b*w
pooled_outputa*(1-w)+b*w
length_mismatcherror
w0.00
x0.00
y0.00
z0.00

Conditioning math is the node you reach for when you want to crossfade between two prompts - or four - without stacking another "Conditioning Average" node and hoping the semantics line up. It takes up to four CONDITIONING inputs and runs a math expression over them. The default expression is a*(1-w)+b*w, which is exactly a weighted blend: at w=0 you get all of a, at w=1 all of b, in between a mix. If you've ever wanted a prompt to fade into another one across a video or a series of images, this is the tool.

How it works

A conditioning isn't a single tensor - it's a list of (tensor, metadata) pairs, where the tensor is the token embedding for a prompt and the metadata carries things like the pooled output. This node runs your Tensor expression over the embedding of the first segment, and a separate expression, pooled_output, over the pooled vector if the conditioning has one (SDXL and Flux-style pipelines do). Any extra segments are passed through untouched.

Inside the expression you get the usual variables - a, b, c, d for the conditionings, w, x, y, z as free float sliders - plus a few positional ones: B/batch, T/batch_count, N/channel_count, and per-dimension index tensors. That's how you'd do something like a per-token or per-position blend instead of a uniform one.

The inputs that matter

  • a - your primary conditioning (required). b, c, d are optional.
  • Tensor - the expression for the embedding itself. Default a*(1-w)+b*w.
  • pooled_output - the expression for the pooled vector. Same default; leave it alone unless you know why you're changing it.
  • length_mismatch - tile (repeat shorter inputs), error (default, throw if segment counts differ), or pad (zero-fill).
  • w, x, y, z - the float knobs your expression references.

Output is a single CONDITIONING that feeds straight into a KSampler or whatever sampler you're using.

Installing it

This comes from the More Math pack. Easiest path is ComfyUI Manager - search "More Math" and hit install. Manual route:

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

Then restart ComfyUI. The only dependencies are antlr4-python3-runtime and torch - no model downloads, no giant wheels. One gotcha: the pack is written against ComfyUI's newer custom-node API, so it needs a reasonably current ComfyUI. If the nodes don't show up after install, update ComfyUI first before you start hunting for conflicts.

Where people get burned

The length_mismatch default is error, and it's there for a reason: plug in conditionings with different segment counts and you'll get a ValueError the moment the graph runs. Switch to tile or pad if you're deliberately mixing different sources.

The other classic gotcha is expecting it to modify the whole conditioning. It doesn't - only the first segment gets re-evaluated, and pooled_output only matters when the conditioning actually carries a pooled vector. If your blend behaves differently than you expected on a model with multiple text encoders, that's why. Keep w in the 0–1 range for a sane crossfade; the math lets you push past it, and the result is usually just mush.

One honest caveat: the node is marked deprecated in the pack source, replaced by an autogrow variant with the same display name (more conditioning inputs, same expression language). Both still ship and work - search "Conditioning math" in the node menu and you may see both. The classic form described here is fine for what it does, but if you're starting a new workflow, check whether the newer one is already sitting in your palette.

Categorysd

Inputs (11)

NameTypeDefaultDescription
aCONDITIONING
TensorSTRINGa*(1-w)+b*wExpression for tensor part (image composition)
pooled_outputSTRINGa*(1-w)+b*wExpression for pooled output (condensed representation)
length_mismatchCOMBOerrorHow to handle mismatched conditioning segment counts. tile: repeat shorter inputs; error: raise error on mismatch; pad: treat missing as zero.
boptCONDITIONING
coptCONDITIONING
doptCONDITIONING
woptFLOAT0.00
xoptFLOAT0.00
yoptFLOAT0.00
zoptFLOAT0.00

Outputs (1)

NameTypeDescription
CONDITIONINGCONDITIONING