invoke-ai/InvokeAI · error · ValueError

Unsupported cfg_scale type: {type(cfg_scale)}

Error message

Unsupported cfg_scale type: {type(cfg_scale)}

What it means

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.

Source

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

        cls, cfg_scale: float | list[float], timesteps: list[float], cfg_scale_start_step: int, cfg_scale_end_step: int
    ) -> list[float]:
        """Prepare the cfg_scale schedule.

        - Clips the cfg_scale schedule based on cfg_scale_start_step and cfg_scale_end_step.
        - If cfg_scale is a list, then it is assumed to be a schedule and is returned as-is.
        - If cfg_scale is a scalar, then a linear schedule is created from cfg_scale_start_step to cfg_scale_end_step.
        """
        # num_steps is the number of denoising steps, which is one less than the number of timesteps.
        num_steps = len(timesteps) - 1

        # Normalize cfg_scale to a list if it is a scalar.
        cfg_scale_list: list[float]
        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 "

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Pass cfg_scale as a float (e.g. 4.5) or a list of floats with exactly num_steps entries.
  2. Cast the value before the call: cfg_scale = float(cfg_scale) or [float(x) for x in values].
  3. Validate the parsed workflow JSON so cfg_scale is a number, not a string.

Example fix

// before
prep_cfg_scale(cfg_scale=5) // int
// after
prep_cfg_scale(cfg_scale=5.0) // float
Defensive patterns

Strategy: validation

Validate before calling

if not (isinstance(cfg_scale, float) or (isinstance(cfg_scale, list) and all(isinstance(x, float) for x in cfg_scale))):
    raise ValueError("cfg_scale must be float or list[float]")
cfg_scale = float(cfg_scale)

Type guard

def is_valid_cfg_scale(v) -> bool:
    return isinstance(v, float) or (isinstance(v, list) and len(v) > 0 and all(isinstance(x, float) for x in v))

Try / catch

try:
    cfg_list = denoise.prep_cfg_scale(cfg_scale, num_steps)
except ValueError as e:
    if 'Unsupported cfg_scale type' in str(e):
        cfg_list = denoise.prep_cfg_scale(float(cfg_scale), num_steps)
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.

Related errors


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