{"record":{"id":"d58a3c2e67618190","repo":"invoke-ai/InvokeAI","slug":"generation-devices-requested-device-str-but-n","errorCode":null,"errorMessage":"generation_devices requested '{device_str}', but no CUDA device is available.","messagePattern":"generation_devices requested '(.+?)', but no CUDA device is available\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/util/devices.py","lineNumber":297,"sourceCode":"            if legacy_device != \"auto\":\n                device_strs: list[str] = [legacy_device]\n            else:\n                device_strs = [str(device) for device in cls._auto_generation_devices()]\n        elif not generation_devices:\n            return []\n        else:\n            device_strs = list(generation_devices)\n\n        devices: list[torch.device] = []\n        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)","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/util/devices.py#L279-L315","documentation":"get_generation_devices normalizes each configured generation device and fails fast on explicitly requested CUDA devices when CUDA is entirely unavailable. This prevents workers from starting pinned to a device that would only fail at first tensor allocation.","triggerScenarios":"Configuring generation_devices to a cuda:* device string (via config or update_runtime_config) on a machine with no CUDA support — no NVIDIA driver, CPU-only torch build, or CUDA_VISIBLE_DEVICES masking all devices.","commonSituations":"Copying a GPU machine's config to a CPU-only host or CI runner; installing the CPU-only torch wheel; driver not loaded / nvidia modules missing; CUDA_VISIBLE_DEVICES=\"\" set in the environment.","solutions":["Change generation_devices in the config to 'auto', 'cpu', or 'mps' as appropriate for the host","Install a CUDA-enabled torch build and the NVIDIA driver if a GPU is present","Check nvidia-smi and CUDA_VISIBLE_DEVICES; clear masking env vars","Update legacy pinned device settings after migrating hardware"],"exampleFix":"// before\ngeneration_devices: [\"cuda:0\"]   # on CPU-only host\n// after\ngeneration_devices: [\"auto\"]","handlingStrategy":"validation","validationCode":"import torch\nif any(str(d).startswith(\"cuda\") for d in generation_devices) and not torch.cuda.is_available():\n    generation_devices = [\"auto\"]  # or [\"cpu\"]\n","typeGuard":"def is_cuda_config_valid(devices: list[str]) -> bool:\n    import torch\n    return all(not d.startswith(\"cuda\") for d in devices) or torch.cuda.is_available()","tryCatchPattern":"try:\n    devices = DeviceService.get_generation_devices(cfg.generation_devices)\nexcept ValueError as e:\n    if \"no CUDA device is available\" in str(e):\n        log.warning(\"CUDA unavailable; falling back to CPU\")\n        devices = DeviceService.get_generation_devices([\"auto\"])\n    else:\n        raise","preventionTips":["Check torch.cuda.is_available() before pinning cuda devices in config","Avoid copying GPU configs across hosts; use 'auto' where possible","Verify drivers and CUDA-enabled torch builds (not CPU-only wheels)","Check CUDA_VISIBLE_DEVICES isn't masking GPUs"],"tags":["config","cuda","device","gpu-unavailable"],"backgroundTag":"cuda-not-available","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}