Nodes/AnimateDiff Evolved/Custom CFG Keyframe πŸŽ­πŸ…πŸ…“
ComfyUI Node Runs on cloud

Custom CFG Keyframe πŸŽ­πŸ…πŸ…“

Scheduling your CFG scale to change mid-clip

By KosinkadinkΒ·Created 3 years agoΒ·Updated 8 days agoΒ· 3,519
Custom CFG Keyframe πŸŽ­πŸ…πŸ…“
  • prev_custom_cfg
  • cfg_extras
  • CUSTOM_CFG
β—„cfg8.0β–Ί
β—„start_percent0.000β–Ί
β—„guarantee_steps1β–Ί

Your KSampler's CFG slider sets one value for the whole run. This node lets you schedule CFG to change at specific points during sampling instead - the same keyframe idea ADE_AnimateDiffKeyframe applies to motion strength, applied here to guidance scale. Chain several of these together (each declaring a start_percent and a cfg value) and you get a CFG curve across your clip rather than one flat number.

It's a real technique some AnimateDiff users lean on to fight a specific symptom: burned-in, over-contrasted frames later in a clip when CFG stays high the whole way through. Dropping CFG partway through sampling - rather than fighting it with prompt changes - is one lever for that, though it's worth treating as one tool among several rather than a guaranteed fix.

How it works

Each ADE_CustomCFGKeyframeSimple marks a point in the sampling timeline (start_percent) where a new cfg value takes over, staying in effect until the next keyframe in the chain. You build the chain by feeding one keyframe's output into the next one's prev_custom_cfg input, and the whole assembled chain plugs into Sample Settings' custom_cfg slot - which only takes effect once it's wired through to your loader or Use Evolved Sampling, replacing whatever fixed CFG you'd otherwise set on the KSampler itself.

The inputs and outputs that matter

Required: cfg (default 8 - a normal SD 1.5 CFG value, since this replaces your sampler's own CFG setting once wired in), start_percent (default 0, range 0–1), and guarantee_steps (default 1) - the same protection ADE_AnimateDiffKeyframe has, ensuring this keyframe gets at least this many steps before a nearby one crowds it out.

Optional: prev_custom_cfg (type CUSTOM_CFG) to chain the previous keyframe in, building a multi-point schedule, and cfg_extras (type CFG_EXTRAS) for additional CFG-related modifiers from another node in the pack. Output is CUSTOM_CFG, feeding the next keyframe's prev_custom_cfg or Sample Settings' custom_cfg slot.

How to install it

Standard for the pack - ComfyUI Manager, search AnimateDiff Evolved by Kosinkadink, or:

cd ComfyUI/custom_nodes && git clone https://github.com/Kosinkadink/ComfyUI-AnimateDiff-Evolved

No model download for this node - it's sampling configuration on top of whatever checkpoint and motion setup you already have.

Common issues & troubleshooting

Set this up but your KSampler's own CFG slider still seems to be what's controlling output. Confirm the chain actually reaches Sample Settings' custom_cfg input, and Sample Settings itself is wired into your loader or Use Evolved Sampling. If that connection is missing, your KSampler's own CFG value is still the one in effect - this system only overrides it once fully wired through.

Built a multi-point schedule and the transitions look abrupt. There's no built-in crossfade between one keyframe's cfg and the next - it's a hard switch at start_percent, the same way ADE_AnimateDiffKeyframe behaves for motion. If you want a gentler ramp, add more keyframes with smaller CFG steps between them rather than one big jump.

Not sure this is worth the setup versus just picking one CFG value. For most clips, it isn't - a single well-chosen CFG on your KSampler covers the common case fine. This is worth reaching for specifically when you've identified a concrete problem (late-clip burn-in, a scene that needs looser guidance partway through) that a flat CFG value doesn't solve.

CategoryAnimate Diff πŸŽ­πŸ…πŸ…“/sample settings/custom cfg

Inputs (5)

NameTypeDefaultDescription
cfgFLOAT8.00–100β€”
start_percentFLOAT0.0000–1β€”
guarantee_stepsINT10–9007199254740991β€”
prev_custom_cfgoptCUSTOM_CFGβ€”
cfg_extrasoptCFG_EXTRASβ€”

Outputs (1)

NameTypeDescription
CUSTOM_CFGCUSTOM_CFGβ€”