{"record":{"id":"00df70773d9d82ab","repo":"invoke-ai/InvokeAI","slug":"invalid-cfg-scale-start-step-out-of-range-cfg-s","errorCode":null,"errorMessage":"Invalid cfg_scale_start_step. Out of range: {cfg_scale_start_step}.","messagePattern":"Invalid cfg_scale_start_step\\. Out of range: (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/flux_denoise.py","lineNumber":653,"sourceCode":"        if isinstance(cfg_scale, float):\n            cfg_scale_list = [cfg_scale] * num_steps\n        elif isinstance(cfg_scale, list):\n            cfg_scale_list = cfg_scale\n        else:\n            raise ValueError(f\"Unsupported cfg_scale type: {type(cfg_scale)}\")\n        assert len(cfg_scale_list) == num_steps\n\n        # Handle negative indices for cfg_scale_start_step and cfg_scale_end_step.\n        start_step_index = cfg_scale_start_step\n        if start_step_index < 0:\n            start_step_index = num_steps + start_step_index\n        end_step_index = cfg_scale_end_step\n        if end_step_index < 0:\n            end_step_index = num_steps + end_step_index\n\n        # Validate the start and end step indices.\n        if not (0 <= start_step_index < num_steps):\n            raise ValueError(f\"Invalid cfg_scale_start_step. Out of range: {cfg_scale_start_step}.\")\n        if not (0 <= end_step_index < num_steps):\n            raise ValueError(f\"Invalid cfg_scale_end_step. Out of range: {cfg_scale_end_step}.\")\n        if start_step_index > end_step_index:\n            raise ValueError(\n                f\"cfg_scale_start_step ({cfg_scale_start_step}) must be before cfg_scale_end_step \"\n                + f\"({cfg_scale_end_step}).\"\n            )\n\n        # Set values outside the start and end step indices to 1.0. This is equivalent to disabling cfg_scale for those\n        # steps.\n        clipped_cfg_scale = [1.0] * num_steps\n        clipped_cfg_scale[start_step_index : end_step_index + 1] = cfg_scale_list[start_step_index : end_step_index + 1]\n\n        return clipped_cfg_scale\n\n    def _prep_inpaint_mask(self, context: InvocationContext, latents: torch.Tensor) -> torch.Tensor | None:\n        \"\"\"Prepare the inpaint mask.\n","sourceCodeStart":635,"sourceCodeEnd":671,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/flux_denoise.py#L635-L671","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set cfg_scale_start_step within 0 <= start < num_steps for the current step count.","Use a negative index only as far back as -num_steps (e.g. -1 for the last step).","Recompute the step range from num_steps before calling prep_cfg_scale."],"exampleFix":"// before\nprep_cfg_scale(num_steps=8, cfg_scale_start_step=10) // out of range\n// after\nprep_cfg_scale(num_steps=8, cfg_scale_start_step=0) // in range","handlingStrategy":"validation","validationCode":"if not (0 <= cfg_scale_start_step < num_steps or -num_steps <= cfg_scale_start_step < 0):\n    raise ValueError('cfg_scale_start_step out of range')","typeGuard":"def is_valid_start_step(step: int, num_steps: int) -> bool:\n    return -num_steps <= step < num_steps","tryCatchPattern":"try:\n    cfg_list = denoise.prep_cfg_scale(cfg_scale, num_steps, cfg_scale_start_step=s, cfg_scale_end_step=e)\nexcept ValueError as e:\n    if 'Invalid cfg_scale_start_step' in str(e):\n        cfg_list = denoise.prep_cfg_scale(cfg_scale, num_steps, cfg_scale_start_step=0, cfg_scale_end_step=e)\n    else:\n        raise","preventionTips":["Recompute step indices whenever the step count changes","Use negative indices (-1 for last step) instead of hard-coded positions","Clamp indices to [-num_steps, num_steps-1] before invoking"],"tags":["cfg-scale","range-error","flux","validation"],"backgroundTag":"index-out-of-range","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}