invoke-ai/InvokeAI · error · ValueError
guidance_schedule has length {len(self.guidance_schedule)},
Error message
guidance_schedule has length {len(self.guidance_schedule)}, expected num_steps={self.num_steps} What it means
Dataclass validation in __post_init__ ensures the CFG guidance schedule has exactly one guidance value per denoising step; a mismatch would cause index errors or silently wrong guidance during sampling.
Source
Thrown at invokeai/backend/ideogram4/scheduler.py:67
"""Bundle of sampling hyperparameters for a named preset.
``guidance_schedule`` is in LOOP-INDEX order: index 0 is the LAST sampling
step (final polish), index ``num_steps - 1`` is the FIRST sampling step.
``mu`` and ``std`` are the mean and stddev of the logit-normal noise
schedule passed to ``get_schedule_for_resolution`` (as ``known_mean`` and
``std`` respectively).
See ``ideogram4.sampler_configs.PRESETS`` for the named preset registry.
"""
num_steps: int
guidance_schedule: tuple[float, ...]
mu: float
std: float = 1.0
def __post_init__(self) -> None:
if len(self.guidance_schedule) != self.num_steps:
raise ValueError(
f"guidance_schedule has length {len(self.guidance_schedule)}, expected num_steps={self.num_steps}"
)
View on GitHub (pinned to 0b6a024f2f)
Solutions
- Regenerate guidance_schedule with exactly num_steps entries (e.g. scheduler.set_timesteps / build_schedule(num_steps))
- Resample or interpolate the existing schedule to num_steps points
- Set num_steps to len(guidance_schedule) if the schedule length is authoritative
Example fix
# before Scheduler(num_steps=28, guidance_schedule=tuple(np.linspace(4, 7, 50)), ...) # after num_steps = 28 Scheduler(num_steps=num_steps, guidance_schedule=tuple(np.linspace(4, 7, num_steps)), ...)
Defensive patterns
Strategy: validation
Validate before calling
assert len(guidance_schedule) == num_steps, (
f"schedule len {len(guidance_schedule)} != num_steps {num_steps}"
)
sched = Scheduler(num_steps=num_steps, guidance_schedule=tuple(guidance_schedule), ...) Type guard
def is_valid_schedule(num_steps: int, guidance_schedule) -> bool:
return len(guidance_schedule) == num_steps Try / catch
try:
sched = Scheduler(num_steps=n, guidance_schedule=schedule, mu=mu, std=std)
except ValueError as e:
if "guidance_schedule has length" in str(e):
schedule = tuple(np.interp(
np.linspace(0, 1, n),
np.linspace(0, 1, len(schedule)), schedule))
sched = Scheduler(num_steps=n, guidance_schedule=schedule, mu=mu, std=std)
else:
raise Prevention
- Regenerate the schedule whenever num_steps changes
- Store schedule and num_steps together in one config object
- Add a unit test constructing the scheduler from every config preset
When it happens
Trigger: Constructing the scheduler dataclass with a guidance_schedule tuple whose length differs from num_steps, e.g. hand-editing steps or reusing a schedule from a different run.
Common situations: Changing num_steps in config without regenerating the schedule, loading a schedule from a checkpoint/config of another run, off-by-one when building schedules programmatically.
Related errors
- {noise_type} noise width and height must be a multiple of {m
- Unsupported noise type: {noise_type}
- Unknown subfolder strategy: {strategy_name}. Valid options:
- Unknown image subfolder strategy: {strategy}
- Invalid denoising window: start={denoising_start}, end={deno
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/142e2e2e63e35f37.
Report an issue: GitHub.