invoke-ai/InvokeAI · error · ValueError
Invalid CFG scale type: ${type(self.cfg_scale)}
Error message
Invalid CFG scale type: ${type(self.cfg_scale)} What it means
_prepare_cfg_scale only accepts cfg_scale as a float (broadcast to all timesteps) or a list matching the number of timesteps. Any other type (None, str, tensor, wrong-length list handled separately) fails this check.
Source
Thrown at invokeai/app/invocations/cogview4_denoise.py:171
).to(device=device, dtype=dtype)
def _prepare_cfg_scale(self, num_timesteps: int) -> list[float]:
"""Prepare the CFG scale list.
Args:
num_timesteps (int): The number of timesteps in the scheduler. Could be different from num_steps depending
on the scheduler used (e.g. higher order schedulers).
Returns:
list[float]: _description_
"""
if isinstance(self.cfg_scale, float):
cfg_scale = [self.cfg_scale] * num_timesteps
elif isinstance(self.cfg_scale, list):
assert len(self.cfg_scale) == num_timesteps
cfg_scale = self.cfg_scale
else:
raise ValueError(f"Invalid CFG scale type: {type(self.cfg_scale)}")
return cfg_scale
def _convert_timesteps_to_sigmas(self, image_seq_len: int, timesteps: torch.Tensor) -> list[float]:
# The logic to prepare the timestep / sigma schedule is based on:
# https://github.com/huggingface/diffusers/blob/b38450d5d2e5b87d5ff7088ee5798c85587b9635/src/diffusers/pipelines/cogview4/pipeline_cogview4.py#L575-L595
# The default FlowMatchEulerDiscreteScheduler configs are based on:
# https://huggingface.co/THUDM/CogView4-6B/blob/fb6f57289c73ac6d139e8d81bd5a4602d1877847/scheduler/scheduler_config.json
# This implementation differs slightly from the original for the sake of simplicity (differs in terminal value
# handling, not quantizing timesteps to integers, etc.).
def calculate_timestep_shift(
image_seq_len: int, base_seq_len: int = 256, base_shift: float = 0.25, max_shift: float = 0.75
) -> float:
m = (image_seq_len / base_seq_len) ** 0.5
mu = m * max_shift + base_shift
return mu
View on GitHub (pinned to 0b6a024f2f)
Solutions
- Set cfg_scale to a float (e.g. 7.5) to use a constant guidance scale.
- If per-timestep control is needed, pass a list with exactly num_timesteps entries.
- Check upstream code/config that populates cfg_scale so it cannot be None or another type.
Example fix
// before node.cfg_scale = None // after node.cfg_scale = 7.5 # or [7.5] * num_timesteps
Defensive patterns
Strategy: type-guard
Validate before calling
if not isinstance(node.cfg_scale, (float, list)):
node.cfg_scale = 7.5
elif isinstance(node.cfg_scale, list) and len(node.cfg_scale) != num_timesteps:
node.cfg_scale = node.cfg_scale[:num_timesteps] or 7.5 Type guard
def is_valid_cfg_scale(v) -> bool:
return isinstance(v, float) or (isinstance(v, list) and all(isinstance(x, (int, float)) for x in v)) Try / catch
try:
output = node.invoke(context)
except (ValueError, AssertionError) as e:
if "CFG scale" in str(e):
node.cfg_scale = 7.5
output = node.invoke(context)
else:
raise Prevention
- Always initialize cfg_scale with a float default
- Validate config values before assigning to the node
- Never pass None or tensors into cfg_scale
When it happens
Trigger: Running the CogView4 denoise invocation with cfg_scale set to a non-float, non-list value, or a list whose length is not asserted equal to num_timesteps (that case asserts first).
Common situations: Programmatically constructing the node with cfg_scale=None from a config that failed to load; passing a list with the wrong length (hits the assert); downstream UI/schema mismatch sending unexpected types.
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
- denoising_start should be 0 when initial latents are not pro
- All items in a batch must have the same type
- No external provider config fields provided
- str(e)
- str(e) (ValueError from user service update, e.g. LastAdmini
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/00f4d5e5087a9743.
Report an issue: GitHub.