Nodes/ComfyUI-ZML-Image/ZML_动态CFG脚本
ComfyUI Node

ZML_动态CFG脚本

Switch CFG mid-sampling — start bold, finish clean

By zml-w·Created about a year ago·Updated 2 months ago· 218
ZML_动态CFG脚本
  • 上一个脚本
  • 脚本
触发时机0.5
目标CFG4.0

High CFG gives you crisp, prompt-faithful images but also burned-out colors and oversaturation; low CFG gives you natural tones but mushier adherence. The community's long-standing fix is dynamic CFG: sample with a strong CFG early, then drop to a gentler value for the back half so you keep the structure and lose the fried look. This node is the ZML pack's version - a script node that tells the sampler to switch CFG at a chosen progress point.

How it works

Like the pack's other script nodes, this one doesn't touch pixels itself. It outputs a ZML_SCRIPT instruction - {"type": "dynamic_cfg", "timing": 触发时机, "target_cfg": 目标CFG} - which the ZML_K sampler consumes. The sampler precomputes the trigger step from your timing (0.0–1.0 × total steps), then clones the model and patches its CFG function so that every step after the trigger uses the target CFG instead of the widget value. A timing of 0.0 applies the new CFG immediately from step one.

The "dynamic CFG" technique itself is well-trodden in the community - it's the same idea behind several popular samplers and CFG-shaping extensions. What this node adds is that it's a chainable, declarative step in a script pipeline: stack it with a contrast script and a noise script, all feeding one sampler.

The inputs

  • 触发时机 - progress where CFG switches, 0.0–1.0, default 0.5.
  • 目标CFG - the CFG to switch to and hold. Default 4, which is the classic "finish low" value.
  • 上一个脚本 - chain previous script nodes here so multiple adjustments run in one pass.

Output: 脚本 (ZML_SCRIPT), which goes to the script socket on a ZML sampler.

Installing

cd ComfyUI/custom_nodes
git clone https://github.com/zml-w/ComfyUI-ZML-Image

restart, or ComfyUI Manager. Translation patch: https://github.com/zml-w/ZZZ_ZML_English_Patch.

Common issues

The big one is dependency: this only works with a ZML sampler. There are plenty of standalone dynamic-CFG extensions that patch a stock KSampler, and this node is not one of them - wire it to a normal sampler and the script is silently ignored. Second, the switch is a hard cut, not a ramp: at 0.5 with target 4, step 50 of 100 jumps straight from CFG 8 to CFG 4, and that step can visibly change texture. If you see a seam, push the trigger later (0.7) or lower the gap. And remember your starting CFG comes from the sampler widget, not this node - you're only setting the destination. Keep the widget high and let this node do the landing.

Categoryimage/ZML_图像/采样器相关

Inputs (3)

NameTypeDefaultDescription
触发时机FLOAT0.50–1在该进度时切换CFG
目标CFGFLOAT4.00–100触发后,采样CFG将变更为此数值并保持
上一个脚本optZML_SCRIPT

Outputs (1)

NameTypeDescription
脚本ZML_SCRIPT