{"record":{"id":"0e317e44599547b0","repo":"invoke-ai/InvokeAI","slug":"generation-devices-requested-device-str-but-o-0e317e","errorCode":null,"errorMessage":"generation_devices requested '{device_str}', but only {torch.xpu.device_count()} XPU device(s) are available (valid indices 0-{torch.xpu.device_count() - 1}).","messagePattern":"generation_devices requested '(.+?)', but only (.+?) XPU device\\(s\\) are available \\(valid indices 0-(.+?)\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/util/devices.py","lineNumber":307,"sourceCode":"        seen: set[str] = set()\n        for device_str in device_strs:\n            device = cls.normalize(device_str)\n            # Fail fast on a CUDA device that doesn't exist, rather than starting a worker pinned to\n            # it that only errors cryptically at the first tensor allocation. (\"auto\" only generates\n            # valid indices, so this just validates explicitly-configured devices.)\n            if device.type == \"cuda\":\n                if not torch.cuda.is_available():\n                    raise ValueError(f\"generation_devices requested '{device_str}', but no CUDA device is available.\")\n                if device.index is not None and device.index >= torch.cuda.device_count():\n                    raise ValueError(\n                        f\"generation_devices requested '{device_str}', but only {torch.cuda.device_count()} \"\n                        f\"CUDA device(s) are available (valid indices 0-{torch.cuda.device_count() - 1}).\"\n                    )\n            elif device.type == \"xpu\":\n                if not _xpu_is_available():\n                    raise ValueError(f\"generation_devices requested '{device_str}', but no XPU device is available.\")\n                if device.index is not None and device.index >= torch.xpu.device_count():\n                    raise ValueError(\n                        f\"generation_devices requested '{device_str}', but only {torch.xpu.device_count()} \"\n                        f\"XPU device(s) are available (valid indices 0-{torch.xpu.device_count() - 1}).\"\n                    )\n            elif device.type == \"mps\" and not torch.backends.mps.is_available():\n                raise ValueError(f\"generation_devices requested '{device_str}', but MPS is not available.\")\n            if str(device) not in seen:\n                seen.add(str(device))\n                devices.append(device)\n        return devices\n\n    @classmethod\n    def normalize(cls, device: Union[str, torch.device]) -> torch.device:\n        \"\"\"Add the device index to CUDA and XPU devices.\"\"\"\n        device = torch.device(device)\n        if device.index is None and device.type == \"cuda\" and torch.cuda.is_available():\n            device = torch.device(device.type, torch.cuda.current_device())\n        elif device.index is None and device.type == \"xpu\" and _xpu_is_available():\n            device = torch.device(device.type, torch.xpu.current_device())","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/util/devices.py#L289-L325","documentation":"XPU analog of the CUDA index check: XPU is available, but the requested index is >= torch.xpu.device_count(). The message enumerates the valid index range so configs can be corrected directly.","triggerScenarios":"Configuring generation_devices 'xpu:1' or higher when torch.xpu.device_count() returns fewer devices — e.g. one Intel GPU present but config copied from a two-GPU host.","commonSituations":"Intel GPU missing/detached at boot, container device passthrough exposing fewer XPUs, or configs copied across machines with different GPU counts.","solutions":["Set the device to an in-range index (e.g. xpu:0) or use 'auto'","Check torch.xpu.device_count() and the host's Intel GPU enumeration (clinfo/xpu-smi)","Fix device visibility (e.g. device passthrough settings) if an XPU should exist"],"exampleFix":"// before\ngeneration_devices: [\"xpu:1\"]  # only one Intel GPU visible\n// after\ngeneration_devices: [\"xpu:0\"]","handlingStrategy":"validation","validationCode":"import torch\nfor d in generation_devices:\n    if d.startswith(\"xpu:\"):\n        idx = int(d.split(\":\")[1])\n        if idx >= torch.xpu.device_count():\n            raise SystemExit(f\"{d} invalid: only {torch.xpu.device_count()} XPU device(s)\")","typeGuard":"def xpu_index_in_range(device_str: str) -> bool:\n    if not device_str.startswith(\"xpu:\"):\n        return True\n    return int(device_str.split(\":\")[1]) < torch.xpu.device_count()","tryCatchPattern":"try:\n    devices = DeviceService.get_generation_devices(cfg.generation_devices)\nexcept ValueError as e:\n    if \"XPU device(s) are available\" in str(e):\n        log.warning(\"Requested XPU index out of range; using auto\")\n        devices = DeviceService.get_generation_devices([\"auto\"])\n    else:\n        raise","preventionTips":["Match xpu indices to torch.xpu.device_count() on the actual host","Re-validate configs after hardware or container passthrough changes","Use xpu-smi/clinfo to confirm visible Intel GPUs","Prefer 'auto' unless pinning is required"],"tags":["config","xpu","device-index","validation"],"backgroundTag":"invalid-cuda-device-index","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}