{"record":{"id":"00f4d5e5087a9743","repo":"invoke-ai/InvokeAI","slug":"invalid-cfg-scale-type-type-self-cfg-scale","errorCode":null,"errorMessage":"Invalid CFG scale type: ${type(self.cfg_scale)}","messagePattern":"Invalid CFG scale type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/cogview4_denoise.py","lineNumber":171,"sourceCode":"        ).to(device=device, dtype=dtype)\n\n    def _prepare_cfg_scale(self, num_timesteps: int) -> list[float]:\n        \"\"\"Prepare the CFG scale list.\n\n        Args:\n            num_timesteps (int): The number of timesteps in the scheduler. Could be different from num_steps depending\n            on the scheduler used (e.g. higher order schedulers).\n\n        Returns:\n            list[float]: _description_\n        \"\"\"\n        if isinstance(self.cfg_scale, float):\n            cfg_scale = [self.cfg_scale] * num_timesteps\n        elif isinstance(self.cfg_scale, list):\n            assert len(self.cfg_scale) == num_timesteps\n            cfg_scale = self.cfg_scale\n        else:\n            raise ValueError(f\"Invalid CFG scale type: {type(self.cfg_scale)}\")\n\n        return cfg_scale\n\n    def _convert_timesteps_to_sigmas(self, image_seq_len: int, timesteps: torch.Tensor) -> list[float]:\n        # The logic to prepare the timestep / sigma schedule is based on:\n        # https://github.com/huggingface/diffusers/blob/b38450d5d2e5b87d5ff7088ee5798c85587b9635/src/diffusers/pipelines/cogview4/pipeline_cogview4.py#L575-L595\n        # The default FlowMatchEulerDiscreteScheduler configs are based on:\n        # https://huggingface.co/THUDM/CogView4-6B/blob/fb6f57289c73ac6d139e8d81bd5a4602d1877847/scheduler/scheduler_config.json\n        # This implementation differs slightly from the original for the sake of simplicity (differs in terminal value\n        # handling, not quantizing timesteps to integers, etc.).\n\n        def calculate_timestep_shift(\n            image_seq_len: int, base_seq_len: int = 256, base_shift: float = 0.25, max_shift: float = 0.75\n        ) -> float:\n            m = (image_seq_len / base_seq_len) ** 0.5\n            mu = m * max_shift + base_shift\n            return mu\n","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/cogview4_denoise.py#L153-L189","documentation":"_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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nnode.cfg_scale = None\n// after\nnode.cfg_scale = 7.5  # or [7.5] * num_timesteps","handlingStrategy":"type-guard","validationCode":"if not isinstance(node.cfg_scale, (float, list)):\n    node.cfg_scale = 7.5\nelif isinstance(node.cfg_scale, list) and len(node.cfg_scale) != num_timesteps:\n    node.cfg_scale = node.cfg_scale[:num_timesteps] or 7.5","typeGuard":"def is_valid_cfg_scale(v) -> bool:\n    return isinstance(v, float) or (isinstance(v, list) and all(isinstance(x, (int, float)) for x in v))","tryCatchPattern":"try:\n    output = node.invoke(context)\nexcept (ValueError, AssertionError) as e:\n    if \"CFG scale\" in str(e):\n        node.cfg_scale = 7.5\n        output = node.invoke(context)\n    else:\n        raise","preventionTips":["Always initialize cfg_scale with a float default","Validate config values before assigning to the node","Never pass None or tensors into cfg_scale"],"tags":["validation","types","denoise","cogview4"],"backgroundTag":"invalid-argument-type","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}