{"record":{"id":"90d7d354987e26e4","repo":"invoke-ai/InvokeAI","slug":"unexpected-dtype-dtype","errorCode":null,"errorMessage":"Unexpected dtype '{dtype}'.","messagePattern":"Unexpected dtype '(.+?)'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/spandrel_image_to_image_model.py","lineNumber":99,"sourceCode":"        if not isinstance(model, ImageModelDescriptor):\n            raise ValueError(\n                f\"Loaded a spandrel model of type '{type(model)}'. Only image-to-image models are supported \"\n                \"('ImageModelDescriptor').\"\n            )\n\n        return cls(spandrel_model=model)\n\n    def supports_dtype(self, dtype: torch.dtype) -> bool:\n        \"\"\"Check if the model supports the given dtype.\"\"\"\n        if dtype == torch.float16:\n            return self._spandrel_model.supports_half\n        elif dtype == torch.bfloat16:\n            return self._spandrel_model.supports_bfloat16\n        elif dtype == torch.float32:\n            # All models support float32.\n            return True\n        else:\n            raise ValueError(f\"Unexpected dtype '{dtype}'.\")\n\n    def get_model_type_name(self) -> str:\n        \"\"\"The model type name. Intended for logging / debugging purposes. Do not rely on this field remaining\n        consistent over time.\n        \"\"\"\n        return str(type(self._spandrel_model.model))\n\n    def to(\n        self,\n        device: Optional[torch.device] = None,\n        dtype: Optional[torch.dtype] = None,\n        non_blocking: bool = False,\n    ) -> None:\n        \"\"\"Note: Some models have limited dtype support. Call supports_dtype(...) to check if the dtype is supported.\n        Note: The non_blocking parameter is currently ignored.\"\"\"\n        # TODO(ryand): spandrel.ImageModelDescriptor.to(...) does not support non_blocking. We will have to access the\n        # model directly if we want to apply this optimization.\n        self._spandrel_model.to(device=device, dtype=dtype)","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/spandrel_image_to_image_model.py#L81-L117","documentation":"supports_dtype checks whether the loaded spandrel model supports half, bfloat16, or float32 precision by delegating to the underlying descriptor's supports_* flags. Any dtype outside torch.float16, torch.bfloat16, torch.float32 (e.g. float64, int types) has no mapping and raises ValueError.","triggerScenarios":"Calling supports_dtype(dtype) with a dtype other than torch.float16/bfloat16/float32, typically from _load_model when converting the model to an unexpected precision.","commonSituations":"Passing dtype strings ('fp16') instead of torch dtype objects; config or variant plumbing delivering torch.float64 or a quantized dtype; custom code selecting dtype = latents.dtype when latents are not a float16/32 type.","solutions":["Only pass torch.float16, torch.bfloat16, or torch.float32 to supports_dtype.","Convert the requested dtype first (e.g. dtype = torch.float16 if dtype not in allowed set).","Check upstream code that derives dtype so it can't produce exotic values.","Catch ValueError and fall back to torch.float32, which all models support."],"exampleFix":"// before\nmodel.supports_dtype(torch.float64)\n// after\nallowed = {torch.float16, torch.bfloat16, torch.float32}\ndtype = dtype if dtype in allowed else torch.float32\nmodel.supports_dtype(dtype)","handlingStrategy":"validation","validationCode":"SUPPORTED = {torch.float16, torch.bfloat16, torch.float32}\nif dtype not in SUPPORTED:\n    dtype = torch.float32","typeGuard":"def is_supported_dtype(dtype) -> bool:\n    return dtype in {torch.float16, torch.bfloat16, torch.float32}","tryCatchPattern":"try:\n    ok = model.supports_dtype(dtype)\nexcept ValueError:\n    ok = model.supports_dtype(torch.float32)  # universal fallback","preventionTips":["Always derive dtype from the allowed set {fp16, bf16, fp32}","Never pass string dtypes; convert with getattr(torch, s) and validate","Default to float32 when unsure","Log the resolved dtype before loading"],"tags":["python","valueerror","dtype","precision"],"backgroundTag":"unsupported-dtype","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}