invoke-ai/InvokeAI · error · ValueError

Invalid cfg_scale_start_step. Out of range: {cfg_scale_start

Error message

Invalid cfg_scale_start_step. Out of range: {cfg_scale_start_step}.

What it means

After resolving negative indices, prep_cfg_scale validates that cfg_scale_start_step lies within [0, num_steps). A value outside that range would index outside the per-step cfg list, so the invocation raises with the offending value.

Source

Thrown at invokeai/app/invocations/flux_denoise.py:653

        if isinstance(cfg_scale, float):
            cfg_scale_list = [cfg_scale] * num_steps
        elif isinstance(cfg_scale, list):
            cfg_scale_list = cfg_scale
        else:
            raise ValueError(f"Unsupported cfg_scale type: {type(cfg_scale)}")
        assert len(cfg_scale_list) == num_steps

        # Handle negative indices for cfg_scale_start_step and cfg_scale_end_step.
        start_step_index = cfg_scale_start_step
        if start_step_index < 0:
            start_step_index = num_steps + start_step_index
        end_step_index = cfg_scale_end_step
        if end_step_index < 0:
            end_step_index = num_steps + end_step_index

        # Validate the start and end step indices.
        if not (0 <= start_step_index < num_steps):
            raise ValueError(f"Invalid cfg_scale_start_step. Out of range: {cfg_scale_start_step}.")
        if not (0 <= end_step_index < num_steps):
            raise ValueError(f"Invalid cfg_scale_end_step. Out of range: {cfg_scale_end_step}.")
        if start_step_index > end_step_index:
            raise ValueError(
                f"cfg_scale_start_step ({cfg_scale_start_step}) must be before cfg_scale_end_step "
                + f"({cfg_scale_end_step})."
            )

        # Set values outside the start and end step indices to 1.0. This is equivalent to disabling cfg_scale for those
        # steps.
        clipped_cfg_scale = [1.0] * num_steps
        clipped_cfg_scale[start_step_index : end_step_index + 1] = cfg_scale_list[start_step_index : end_step_index + 1]

        return clipped_cfg_scale

    def _prep_inpaint_mask(self, context: InvocationContext, latents: torch.Tensor) -> torch.Tensor | None:
        """Prepare the inpaint mask.

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Set cfg_scale_start_step within 0 <= start < num_steps for the current step count.
  2. Use a negative index only as far back as -num_steps (e.g. -1 for the last step).
  3. Recompute the step range from num_steps before calling prep_cfg_scale.

Example fix

// before
prep_cfg_scale(num_steps=8, cfg_scale_start_step=10) // out of range
// after
prep_cfg_scale(num_steps=8, cfg_scale_start_step=0) // in range
Defensive patterns

Strategy: validation

Validate before calling

if not (0 <= cfg_scale_start_step < num_steps or -num_steps <= cfg_scale_start_step < 0):
    raise ValueError('cfg_scale_start_step out of range')

Type guard

def is_valid_start_step(step: int, num_steps: int) -> bool:
    return -num_steps <= step < num_steps

Try / catch

try:
    cfg_list = denoise.prep_cfg_scale(cfg_scale, num_steps, cfg_scale_start_step=s, cfg_scale_end_step=e)
except ValueError as e:
    if 'Invalid cfg_scale_start_step' in str(e):
        cfg_list = denoise.prep_cfg_scale(cfg_scale, num_steps, cfg_scale_start_step=0, cfg_scale_end_step=e)
    else:
        raise

Prevention

When it happens

Trigger: Calling prep_cfg_scale with a start step >= num_steps or < -num_steps (e.g. start_step=10 when only 8 steps are configured); a mismatch between the step slider value in a workflow and the actual step count.

Common situations: Reducing the number of steps in a workflow without updating cfg_scale_start_step; copying per-step CFG settings from another workflow with more steps; hand-editing workflow JSON.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/00df70773d9d82ab. Report an issue: GitHub.