{"record":{"id":"3f26d5a57fbf8754","repo":"deepset-ai/haystack","slug":"unknown-device-type-string-string","errorCode":null,"errorMessage":"Unknown device type string '{string}'","messagePattern":"Unknown device type string '(.+?)'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/utils/device.py","lineNumber":50,"sourceCode":"    XPU = \"xpu\"\n\n    def __str__(self) -> str:\n        return self.value\n\n    @staticmethod\n    def from_str(string: str) -> \"DeviceType\":\n        \"\"\"\n        Create a device type from a string.\n\n        :param string:\n            The string to convert.\n        :returns:\n            The device type.\n        \"\"\"\n        mapping = {e.value: e for e in DeviceType}\n        _type = mapping.get(string)\n        if _type is None:\n            raise ValueError(f\"Unknown device type string '{string}'\")\n        return _type\n\n\n@dataclass\nclass Device:\n    \"\"\"\n    A generic representation of a device.\n\n    :param type:\n        The device type.\n    :param id:\n        The optional device id.\n    \"\"\"\n\n    type: DeviceType\n    id: int | None = field(default=None)\n\n    def __init__(self, type: DeviceType, id: int | None = None) -> None:  # noqa:A002","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/utils/device.py#L32-L68","documentation":"DeviceType.from_str raises ValueError when the string passed does not match any DeviceType value ('cpu', 'cuda', 'mps', 'xpu', 'disk'). Device strings must be exactly one of the known device type identifiers.","triggerScenarios":"Calling DeviceType.from_str with a misspelled or unsupported string ('gpu', 'CPU', 'cuda:0' — the id must be stripped, 'cuda0'), or indirectly via Device.from_str/ComponentDevice.from_str and HF device map conversion with unrecognized device names.","commonSituations":"Users writing 'gpu' in pipeline config where 'cuda' is required; passing 'cuda:0' instead of separating type and id; hardware-specific devices (e.g. 'npu') unsupported by this Haystack version.","solutions":["Use one of the exact supported strings: 'cpu', 'cuda', 'mps', 'xpu', 'disk'","Strip the device index from inputs like 'cuda:0' — pass type 'cuda' and id 0 to Device(type, id)","Check DeviceType enum values (haystack.utils.device.DeviceType) for the list supported by your version","Upgrade Haystack if you need a newer device type"],"exampleFix":"// before\ndev = DeviceType.from_str(\"cuda:0\")\n// after\nfrom haystack.utils.device import Device, DeviceType\ndev = Device(DeviceType.from_str(\"cuda\"), 0)  # or Device.from_str(\"cuda:0\")","handlingStrategy":"validation","validationCode":"VALID = {\"cpu\", \"cuda\", \"mps\", \"xpu\", \"disk\"}\ndef is_valid_device_string(s: str) -> bool:\n    return s.lower() in VALID\n# for indexed strings use Device.from_str which splits type/id","typeGuard":"def is_device_type_str(s: object) -> bool:\n    return isinstance(s, str) and s.lower() in {\"cpu\", \"cuda\", \"mps\", \"xpu\", \"disk\"}","tryCatchPattern":"try:\n    dtype = DeviceType.from_str(s)\nexcept ValueError as e:\n    print(f\"{s!r} is not a supported device type; use cpu/cuda/mps/xpu/disk\")\n    dtype = DeviceType.CPU","preventionTips":["Use exact enum value strings, lowercased, without ':index'","Use Device.from_str for strings with indices like 'cuda:0'","Consult DeviceType values for your installed haystack version"],"tags":["device","pytorch","gpu","value-error"],"backgroundTag":"invalid-device-string","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}