{"record":{"id":"3849339836381c3f","repo":"ultralytics/ultralytics","slug":"invalid-device-type-upper-device-device-re","errorCode":null,"errorMessage":"Invalid {device_type.upper()} 'device={device}' requested. Backend is not available.","messagePattern":"Invalid (.+?) 'device=(.+?)' requested\\. Backend is not available\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ultralytics/utils/torch_utils.py","lineNumber":262,"sourceCode":"        if device.type not in {\"cuda\", \"npu\", \"xpu\"}:\n            return device  # other torch.device inputs pass through; accelerator inputs canonicalize and validate below\n    elif str(device).startswith((\"tpu\", \"intel\", \"vulkan\")):\n        return device\n\n    s = f\"Ultralytics {__version__} 🚀 Python-{PYTHON_VERSION} torch-{TORCH_VERSION} \"\n    device = parse_device(device)\n\n    if device.startswith((\"npu\", \"xpu\")):\n        device_type = device.split(\":\", 1)[0]\n        if device_type == \"npu\":\n            try:\n                import torch_npu  # noqa\n            except ImportError:\n                raise ValueError(\n                    f\"Invalid NPU 'device={device}'. Install 'torch_npu' at https://github.com/Ascend/pytorch\"\n                )\n        if not hasattr(torch, device_type):\n            raise ValueError(f\"Invalid {device_type.upper()} 'device={device}' requested. Backend is not available.\")\n        backend = get_torch_device_backend(device_type)\n        if not backend.is_available():\n            raise ValueError(f\"Invalid {device_type.upper()} 'device={device}' requested. Backend is not available.\")\n\n        requested = [\"0\"] if device == device_type else device[4:].split(\",\")\n        indices = [int(x) for x in requested if x.isdigit()]\n        if not indices or len(indices) != len(requested) or len(indices) != len(set(indices)):\n            raise ValueError(\n                f\"Invalid {device_type.upper()} 'device={device}' format. \"\n                f\"Use '{device_type}', '{device_type}:0', or '{device_type}:0,1'.\"\n            )\n        n = backend.device_count()\n        if any(idx >= n for idx in indices):\n            raise ValueError(\n                f\"Invalid {device_type.upper()} 'device={device}' requested. Only {n} device(s) available.\"\n            )\n\n        if len(indices) == 1:","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/ultralytics/ultralytics/blob/0449ea011cfd6c9a0d50a0bf1043aca5190cd476/ultralytics/utils/torch_utils.py#L244-L280","documentation":"After the torch_npu import gate, select_device checks hasattr(torch, device_type). If torch itself lacks the attribute (torch.npu / torch.xpu), the compiled torch build does not include that backend at all, so the requested device type cannot exist regardless of hardware.","triggerScenarios":"device='npu' with torch_npu importable but a torch build where torch.npu is not patched in (broken install order); device='xpu' (Intel) on a stock CPU/CUDA torch build that has no torch.xpu.","commonSituations":"Standard pip torch (cpu/cu121 wheels) with device='xpu' — torch.xpu only exists in Intel-extended builds; partially upgraded torch/torch_npu pairs.","solutions":["For NPU: reinstall a matched torch + torch_npu pair (torch_npu patches torch.npu on import).","For XPU: install an Intel-extension PyTorch build (intel-extension-for-pytorch / a torch with XPU support) matching your GPU driver.","Confirm backend presence first: python -c \"import torch; print(hasattr(torch, 'xpu'))\".","Otherwise fall back to device='cpu' or a CUDA device on supported hardware."],"exampleFix":"# before\nYOLO('yolo11n.pt', device='xpu')  # on stock cuda torch: ValueError, backend not available\n\n# after\n# install torch with XPU support (Intel build), then:\nYOLO('yolo11n.pt', device='xpu')\n# otherwise:\nYOLO('yolo11n.pt', device='cpu')","handlingStrategy":"validation","validationCode":"import torch\n\ndef backend_in_torch(device_type: str) -> bool:\n    return hasattr(torch, device_type)  # 'npu' or 'xpu'\n\nif str(device).startswith(('npu', 'xpu')) and not backend_in_torch(str(device).split(':')[0]):\n    device = 'cpu'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use torch builds from the hardware vendor (Ascend torch+torch_npu pairs, Intel XPU torch builds) — stock wheels lack these attributes.","Probe hasattr(torch, 'xpu'/'npu') in startup checks on heterogeneous clusters."],"tags":["device","xpu","npu","pytorch-build","backend"],"backgroundTag":null,"analyzedSha":"0449ea011cfd6c9a0d50a0bf1043aca5190cd476","analyzedAt":"2026-08-15T02:34:13.413Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}