{"record":{"id":"471c8c58b09cea92","repo":"invoke-ai/InvokeAI","slug":"unsupported-cfg-scale-type-type-cfg-scale","errorCode":null,"errorMessage":"Unsupported cfg_scale type: {type(cfg_scale)}","messagePattern":"Unsupported cfg_scale type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/flux_denoise.py","lineNumber":640,"sourceCode":"        cls, cfg_scale: float | list[float], timesteps: list[float], cfg_scale_start_step: int, cfg_scale_end_step: int\n    ) -> list[float]:\n        \"\"\"Prepare the cfg_scale schedule.\n\n        - Clips the cfg_scale schedule based on cfg_scale_start_step and cfg_scale_end_step.\n        - If cfg_scale is a list, then it is assumed to be a schedule and is returned as-is.\n        - If cfg_scale is a scalar, then a linear schedule is created from cfg_scale_start_step to cfg_scale_end_step.\n        \"\"\"\n        # num_steps is the number of denoising steps, which is one less than the number of timesteps.\n        num_steps = len(timesteps) - 1\n\n        # Normalize cfg_scale to a list if it is a scalar.\n        cfg_scale_list: list[float]\n        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 \"","sourceCodeStart":622,"sourceCodeEnd":658,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/flux_denoise.py#L622-L658","documentation":"prep_cfg_scale accepts cfg_scale only as a float or a list of floats (one per denoise step). Any other type (int, str, None, nested list) cannot be expanded to the per-step list, so a ValueError naming the offending type is raised.","triggerScenarios":"Calling prep_cfg_scale with cfg_scale of a type other than float or list[float] (e.g. an int, string from a form field, or None); a graph passing a non-numeric field into cfg_scale.","commonSituations":"Programmatic graph construction passing an int or unparsed string; JSON workflow import where cfg_scale is a string; bindings/languages that treat numbers as ints by default.","solutions":["Pass cfg_scale as a float (e.g. 4.5) or a list of floats with exactly num_steps entries.","Cast the value before the call: cfg_scale = float(cfg_scale) or [float(x) for x in values].","Validate the parsed workflow JSON so cfg_scale is a number, not a string."],"exampleFix":"// before\nprep_cfg_scale(cfg_scale=5) // int\n// after\nprep_cfg_scale(cfg_scale=5.0) // float","handlingStrategy":"validation","validationCode":"if not (isinstance(cfg_scale, float) or (isinstance(cfg_scale, list) and all(isinstance(x, float) for x in cfg_scale))):\n    raise ValueError(\"cfg_scale must be float or list[float]\")\ncfg_scale = float(cfg_scale)","typeGuard":"def is_valid_cfg_scale(v) -> bool:\n    return isinstance(v, float) or (isinstance(v, list) and len(v) > 0 and all(isinstance(x, float) for x in v))","tryCatchPattern":"try:\n    cfg_list = denoise.prep_cfg_scale(cfg_scale, num_steps)\nexcept ValueError as e:\n    if 'Unsupported cfg_scale type' in str(e):\n        cfg_list = denoise.prep_cfg_scale(float(cfg_scale), num_steps)\n    else:\n        raise","preventionTips":["Coerce numeric workflow fields to float before use","Validate workflow JSON types at import time","Never pass ints, strings, or None into cfg_scale"],"tags":["cfg-scale","type-error","flux","validation"],"backgroundTag":"invalid-argument-type","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}