invoke-ai/InvokeAI · error · ValueError
cfg_scale list has {len(self.cfg_scale)} values but the mode
Error message
cfg_scale list has {len(self.cfg_scale)} values but the model is configured for {num_timesteps} steps. Provide one CFG value per configured step (or a single float). What it means
The Krea-2 denoise invocation accepts cfg_scale either as a single float (broadcast to all steps) or as a per-step list. `_prepare_cfg_scale` throws when a list is provided whose length does not equal the model's configured number of timesteps, because CFG values are consumed one per denoising step.
Source
Thrown at invokeai/app/invocations/krea2_denoise.py:210
def _get_noise(self, height: int, width: int, dtype: torch.dtype, device: torch.device, seed: int) -> torch.Tensor:
rand_device = "cpu"
return torch.randn(
1,
KREA2_LATENT_CHANNELS,
int(height) // LATENT_SCALE_FACTOR,
int(width) // LATENT_SCALE_FACTOR,
device=rand_device,
dtype=torch.float32,
generator=torch.Generator(device=rand_device).manual_seed(seed),
).to(device=device, dtype=dtype)
def _prepare_cfg_scale(self, num_timesteps: int) -> list[float]:
if isinstance(self.cfg_scale, float):
return [self.cfg_scale] * num_timesteps
if isinstance(self.cfg_scale, list):
if len(self.cfg_scale) != num_timesteps:
raise ValueError(
f"cfg_scale list has {len(self.cfg_scale)} values but the model is configured for "
f"{num_timesteps} steps. Provide one CFG value per configured step (or a single float)."
)
return self.cfg_scale
raise ValueError(f"Invalid CFG scale type: {type(self.cfg_scale)}")
@staticmethod
def _should_apply_cfg_for_step(cfg_scale: float, *, has_negative_conditioning: bool) -> bool:
return has_negative_conditioning and cfg_scale > 1.0
@staticmethod
def _validate_effective_schedule(*, start_idx: int, end_idx: int) -> None:
if end_idx <= start_idx:
raise ValueError(
"The requested denoising range does not contain any effective denoising steps at the configured "
"step count. Increase denoising_end, decrease denoising_start, or increase steps."
)
View on GitHub (pinned to 0b6a024f2f)
Solutions
- Make the cfg_scale list length exactly equal to the `steps` value passed to the denoise invocation.
- Replace the list with a single float if the same CFG should apply to every step.
- Compute the list programmatically from num_timesteps (e.g. interpolate a schedule) instead of hard-coding it.
Example fix
// before steps=20; cfg_scale=[3.0, 3.5, 4.0] // after (option A) steps=20; cfg_scale=3.5 // after (option B) cfg_scale=[3.0 + 0.05*i for i in range(20)] # len == steps
Defensive patterns
Strategy: validation
Validate before calling
if isinstance(cfg_scale, list) and len(cfg_scale) != steps:
raise ValueError(f"cfg_scale list length {len(cfg_scale)} must equal steps {steps}") Type guard
def is_valid_cfg_scale(cfg_scale, steps: int) -> bool:
if isinstance(cfg_scale, float):
return True
return isinstance(cfg_scale, list) and len(cfg_scale) == steps and all(isinstance(v, float) for v in cfg_scale) Try / catch
try:
out = invoke_krea2_denoise(cfg_scale=cfg_scale, steps=steps)
except ValueError as e:
if "cfg_scale list has" in str(e):
cfg_scale = float(cfg_scale[0]) if isinstance(cfg_scale, list) else cfg_scale
out = invoke_krea2_denoise(cfg_scale=cfg_scale, steps=steps)
else:
raise Prevention
- Derive per-step CFG lists from the steps value programmatically, never hard-code.
- Update CFG schedules whenever the steps setting changes.
- Prefer a single float unless per-step scheduling is intentional.
When it happens
Trigger: Setting the invocation's cfg_scale input to a list like [3.0, 4.0] while running with steps=20, or changing `steps` after authoring a per-step CFG list sized for the old step count.
Common situations: Users copying a per-step CFG schedule from an example with a different steps value; workflow authors tweaking step count without updating the CFG list; programmatic graph generation computing the list before the final step count is known.
Related errors
- per_layer_weights must be comma-separated numbers: {e}
- per_layer_weights must have exactly {_NUM_TEXT_LAYERS} value
- per_layer_weights must contain only finite values.
- cfg_scale values must be finite.
- shift must be finite.
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/dc8b6320a98814fe.
Report an issue: GitHub.