Skip to content

predict_with_cfg use_zero_init early-exit returns 2-tuple, callers expect 3-tuple #2010

Description

@laurigates

Bug

predict_with_cfg returns a 2-tuple from its use_cfg_zero_star + use_zero_init early-exit branch, while every caller unpacks 3 values. The result is ValueError: not enough values to unpack (expected 3, got 2) on the very first sampling step (idx == 0) whenever a workflow enables both cfg_zero_star and use_zero_init on WanVideoExperimentalArgs.

Repro

WanVideoExperimentalArgs widgets:

  • cfg_zero_star = True
  • use_zero_init = True
  • zero_star_steps = 0 (the default)

Wire the resulting EXPERIMENTALARGS into WanVideoSamplerExtraArgs.experimental_args, then into either WanVideoSamplerv2.extra_args or the v1 WanVideoSampler. Run any I2V or T2V graph. Crash on step 0:

File ".../custom_nodes/ComfyUI-WanVideoWrapper/nodes_sampler.py", line 2485, in process
    noise_pred, noise_pred_ovi, self.cache_state = predict_with_cfg(
ValueError: not enough values to unpack (expected 3, got 2)

Root cause

In nodes_sampler.py at the top of predict_with_cfg (HEAD main line 1172, equivalent to line 1179 in my local copy):

if use_cfg_zero_star and (idx <= zero_star_steps) and use_zero_init:
    return z*0, None

Every other return inside predict_with_cfg (and the final default at the end) returns a 3-tuple (noise_pred, noise_pred_ovi, cache_state). This one early-exit returns 2 values. The WanVideoSampler.process callsite at line 2485 unpacks 3.

This is the same shape of bug as #1454 (where the HUMO branch was fixed in October), but on a different code path that escaped the fix.

Proposed fix

 if use_cfg_zero_star and (idx <= zero_star_steps) and use_zero_init:
-    return z*0, None
+    return z*0, None, cache_state

Pass cache_state through unchanged — at the zero-init step there is no actual cache update to record, so returning the input cache state is the natural identity. I have been running this patch locally for a Wan 2.2 Remix I2V workflow and it produces correct output (the step-0 noise prediction is zeroed as the CFG-Zero* design intends, and subsequent steps proceed normally).

Happy to open a PR if useful.

Environment

  • ComfyUI-WanVideoWrapper: HEAD main (verified the bug is still present in the current nodes_sampler.py at the URL https://raw.githubusercontent.com/kijai/ComfyUI-WanVideoWrapper/main/nodes_sampler.py)
  • Sampler: WanVideoSamplerv2 (also reproduces with v1 WanVideoSampler)
  • Models: any Wan 2.2 14B (reproduced with FX-FeiHou Remix HIGH/LOW fp8)
  • Triggers regardless of attention mode (sageattn, radial_sage_attention)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions