Nodes/comfyui-meancache-z/MeanCache (Z-Image)
ComfyUI Node

MeanCache (Z-Image)

MeanCache's step-skipping, demystified

By facok·Created 7 months ago·Updated 7 months ago· 37
MeanCache (Z-Image)
  • model
  • Patched Model
presetBalanced
cache_devicecpu
rel_l1_thresh0.30
skip_budget0.30
start_step2
end_step-1
enable_pssptrue
peak_threshold0.15
adaptive_ktrue
debugfalse

Here's the pitch: MeanCache (Z-Image) is a single node that wraps your Z-Image model and quietly skips a chunk of the denoising steps - no fine-tuning, no API, no extra model downloads. You get somewhere between 1.3x and 2x faster generation, and the images come out looking basically the same. That's the whole deal, and for the crowd generating on Z-Image Base it's worth a look.

The name sounds like magic, but the mechanism is more honest than the marketing. Z-Image is a flow-matching model, which means at every step it predicts a velocity - a direction to move through latent space - and walks toward the image. Flow-matching trajectories are near-straight lines, and that's exactly what makes step-skipping safe. The MeanCache algorithm, from UnicomAI's research (the same trick that got linked from the official Tongyi-MAI Z-Image README), exploits the fact that velocity changes smoothly along that line. Instead of calling the full model every step, it keeps the last few velocities around and estimates how they're trending using a JVP (Jacobian-vector product) via finite differences. Then it extrapolates: if the extrapolated velocity is close enough to what a real evaluation would give (measured by an L_K stability metric), it skips the model call entirely and reuses the cached velocity. Cached velocities stand in for full evaluations, and you never notice.

A PSSP scheduler ("Peak-Suppressed Shortest Path") decides which steps actually get computed rather than skipping on a fixed pattern - it protects the steps where velocity changes fast. The whole thing is a drop-in patch: the node wraps the model's forward pass via ComfyUI's model wrapper mechanism and hands you a Patched Model output that goes straight into your sampler.

The inputs that actually matter

Three inputs do the real work. The rest you can ignore until you're curious.

  • model - your Z-Image checkpoint, straight from the loader. Nothing special.
  • preset - Quality (~1.3x), Balanced (~1.5x, the default), Speed (~1.75x), Turbo (~2.0x), or Custom. Balanced is a sane starting point; Quality is there when you can see the skipping.
  • cache_device - cpu (default) or cuda. CPU stores the velocity cache in system RAM, which saves VRAM but adds a little transfer overhead. cuda is faster but eats VRAM. On a 12GB card, leave it on cpu.

If you flip to Custom, the knobs that matter are rel_l1_thresh (the skip threshold - lower means fewer skips, 0.2–0.4 is the sweet spot), skip_budget (max fraction of steps you'll allow skipped), and start_step (protects early steps that form image structure). There's also enable_pssp, peak_threshold, adaptive_k, and debug, which prints a per-step log so you can watch it decide. The output is one thing: Patched Model, which wires into the model socket of your KSampler exactly where the unpatched model would have gone.

Installing it

No model downloads, no heavy dependencies - the only thing the pack actually imports beyond ComfyUI itself is torch, which you already have. Via ComfyUI Manager, search "comfyui-meancache-z". Or:

cd ComfyUI/custom_nodes
git clone https://github.com/facok/comfyui-meancache-z

Then restart ComfyUI. The README technically tells you to copy the folder by hand, but git clone does the same thing with the benefit of git pull later.

The one thing that bites everyone

Use this on Z-Image Base, not Turbo. This is the whole game. Turbo is already distilled down to 8 steps - there's barely anything left to skip, and people report literally no speedup (sometimes a 10% slowdown from the overhead). Base is the non-distilled model that needs 25–50 steps, which is precisely where skipping 30–40% of evaluations pays off. If you're generating on Turbo, you've already won the step lottery; this node has nothing to give you.

The other real complaint you'll see: images coming out "undercooked" with weird colors regardless of preset. That's almost always this same mistake - Turbo in, or a preset too aggressive for the content. Drop to Quality or Balanced, or nudge rel_l1_thresh toward the conservative end. And watch the console: when sampling finishes it prints something like [MeanCache] Sampling complete (Balanced): 35 steps, 14 skipped, 21 computed (40.0% skip rate, ~1.67x speedup) - if you're not seeing a meaningful skip rate, you're on the wrong model.

One more subtle thing: the code fingerprints the applied patches, so switching LoRAs between generations invalidates the cache. That's by design - cached velocities from one LoRA don't transfer to another. Just re-run; it sorts itself out.

Categorymodel_patches/acceleration

Inputs (11)

NameTypeDefaultDescription
modelMODELThe Z-Image model to accelerate with MeanCache.
presetCOMBOBalancedAcceleration preset. Quality (~1.3x): conservative, minimal skipping. Balanced (~1.5x): good speed/quality tradeoff. Speed (~1.75x): aggressive skipping. Turbo (~2.0x): maximum speed, may reduce quality. Custom: use manual parameters below.
cache_deviceCOMBOcpuDevice for storing velocity cache. 'cpu' = saves VRAM, slight transfer overhead. 'cuda' = faster access but uses more VRAM.
rel_l1_threshoptFLOAT0.300.05–0.8[Custom only] Relative L1 threshold for skip decision. Lower = more quality, fewer skips. Higher = more speedup, potential quality loss. Recommended: 0.2-0.4
skip_budgetoptFLOAT0.300–0.75[Custom only] Maximum fraction of steps to skip. 0.3 = up to 30% speedup potential. Set to 0.0 to disable skipping.
start_stepoptINT20–20[Custom only] Step index to begin caching (0-indexed). Early steps form image structure and should not be skipped.
end_stepoptINT-1-1–100[Custom only] Step index to stop caching. -1 = cache until the end.
enable_psspoptBOOLEANtrue[Custom only] Enable Peak-Suppressed Shortest Path scheduling. PSSP optimally allocates compute budget across steps.
peak_thresholdoptFLOAT0.150.05–0.6[Custom only] Maximum allowed single-step velocity deviation. Lower = more conservative, higher = more aggressive.
adaptive_koptBOOLEANtrue[Custom only] Dynamically select JVP lookback steps K based on sigma. Early steps use small K (captures rapid changes), later steps use large K (smoother estimates). Based on official MeanCache edge_order patterns.
debugoptBOOLEANfalseEnable debug logging to console. Shows per-step skip/compute decisions and L_K values.

Outputs (1)

NameTypeDescription
Patched ModelMODELModel with MeanCache acceleration applied. Use with any compatible sampler.