{"record":{"id":"dc8b6320a98814fe","repo":"invoke-ai/InvokeAI","slug":"cfg-scale-list-has-len-self-cfg-scale-values-bu","errorCode":null,"errorMessage":"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).","messagePattern":"cfg_scale list has (.+?) values but the model is configured for (.+?) steps\\. Provide one CFG value per configured step \\(or a single float\\)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/krea2_denoise.py","lineNumber":210,"sourceCode":"\n    def _get_noise(self, height: int, width: int, dtype: torch.dtype, device: torch.device, seed: int) -> torch.Tensor:\n        rand_device = \"cpu\"\n        return torch.randn(\n            1,\n            KREA2_LATENT_CHANNELS,\n            int(height) // LATENT_SCALE_FACTOR,\n            int(width) // LATENT_SCALE_FACTOR,\n            device=rand_device,\n            dtype=torch.float32,\n            generator=torch.Generator(device=rand_device).manual_seed(seed),\n        ).to(device=device, dtype=dtype)\n\n    def _prepare_cfg_scale(self, num_timesteps: int) -> list[float]:\n        if isinstance(self.cfg_scale, float):\n            return [self.cfg_scale] * num_timesteps\n        if isinstance(self.cfg_scale, list):\n            if len(self.cfg_scale) != num_timesteps:\n                raise ValueError(\n                    f\"cfg_scale list has {len(self.cfg_scale)} values but the model is configured for \"\n                    f\"{num_timesteps} steps. Provide one CFG value per configured step (or a single float).\"\n                )\n            return self.cfg_scale\n        raise ValueError(f\"Invalid CFG scale type: {type(self.cfg_scale)}\")\n\n    @staticmethod\n    def _should_apply_cfg_for_step(cfg_scale: float, *, has_negative_conditioning: bool) -> bool:\n        return has_negative_conditioning and cfg_scale > 1.0\n\n    @staticmethod\n    def _validate_effective_schedule(*, start_idx: int, end_idx: int) -> None:\n        if end_idx <= start_idx:\n            raise ValueError(\n                \"The requested denoising range does not contain any effective denoising steps at the configured \"\n                \"step count. Increase denoising_end, decrease denoising_start, or increase steps.\"\n            )\n","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/krea2_denoise.py#L192-L228","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nsteps=20; cfg_scale=[3.0, 3.5, 4.0]\n// after (option A)\nsteps=20; cfg_scale=3.5\n// after (option B)\ncfg_scale=[3.0 + 0.05*i for i in range(20)]  # len == steps","handlingStrategy":"validation","validationCode":"if isinstance(cfg_scale, list) and len(cfg_scale) != steps:\n    raise ValueError(f\"cfg_scale list length {len(cfg_scale)} must equal steps {steps}\")","typeGuard":"def is_valid_cfg_scale(cfg_scale, steps: int) -> bool:\n    if isinstance(cfg_scale, float):\n        return True\n    return isinstance(cfg_scale, list) and len(cfg_scale) == steps and all(isinstance(v, float) for v in cfg_scale)","tryCatchPattern":"try:\n    out = invoke_krea2_denoise(cfg_scale=cfg_scale, steps=steps)\nexcept ValueError as e:\n    if \"cfg_scale list has\" in str(e):\n        cfg_scale = float(cfg_scale[0]) if isinstance(cfg_scale, list) else cfg_scale\n        out = invoke_krea2_denoise(cfg_scale=cfg_scale, steps=steps)\n    else:\n        raise","preventionTips":["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."],"tags":["invokeai","krea2","cfg","validation"],"backgroundTag":"invalid-parameter-value","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}