{"record":{"id":"b9c508e13d77f7bc","repo":"invoke-ai/InvokeAI","slug":"unrecognized-device-latents-device","errorCode":null,"errorMessage":"unrecognized device {latents.device}","messagePattern":"unrecognized device (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/util/attention.py","lineNumber":30,"sourceCode":"\ndef auto_detect_slice_size(latents: torch.Tensor) -> str:\n    bytes_per_element_needed_for_baddbmm_duplication = latents.element_size() + 4\n    max_size_required_for_baddbmm = (\n        16\n        * latents.size(dim=2)\n        * latents.size(dim=3)\n        * latents.size(dim=2)\n        * latents.size(dim=3)\n        * bytes_per_element_needed_for_baddbmm_duplication\n    )\n    if latents.device.type in {\"cpu\", \"mps\"}:\n        mem_free = psutil.virtual_memory().free\n    elif latents.device.type == \"cuda\":\n        mem_free, _ = torch.cuda.mem_get_info(latents.device)\n    elif latents.device.type == \"xpu\":\n        mem_free, _ = TorchDevice.xpu_mem_get_info(latents.device)\n    else:\n        raise ValueError(f\"unrecognized device {latents.device}\")\n\n    if max_size_required_for_baddbmm > (mem_free * 3.0 / 4.0):\n        return \"max\"\n    elif torch.backends.mps.is_available():\n        return \"max\"\n    else:\n        return \"balanced\"\n","sourceCodeStart":12,"sourceCodeEnd":38,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/util/attention.py#L12-L38","documentation":"auto_detect_slice_size measures free memory to choose a slice size for attention, but only knows CPU, CUDA and XPU devices. If the latents tensor sits on any other device type (e.g. a privateuseone/NPU backend), the else branch raises this ValueError.","triggerScenarios":"Calling _adjust_memory_efficient_attention (or code that calls auto_detect_slice_size) with a tensor on a device type outside cpu/cuda/xpu — typically an exotic accelerator backend registered with torch but unsupported here.","commonSituations":"Running on non-standard hardware (NPU, Vulkan, custom backend builds) where the pipeline fell back to 'auto' device selection; misconfigured device env vars forcing an unsupported device.","solutions":["Run generation on a supported device: cpu, cuda, or xpu","Patch/extend auto_detect_slice_size to handle your device type with an appropriate mem_get_info","Explicitly configure the device to cuda/mps so this memory check path is not hit"],"exampleFix":"// before\nlatents = latents.to(\"privateuseone\")\nresult = _adjust_memory_efficient_attention(latents, ...)\n// after\nlatents = latents.to(\"cuda\")\nresult = _adjust_memory_efficient_attention(latents, ...)","handlingStrategy":"type-guard","validationCode":"supported = {\"cpu\", \"cuda\", \"xpu\"}\nassert latents.device.type in supported, f\"device {latents.device.type} not supported for auto slice sizing\"\n","typeGuard":"def is_supported_device(t: torch.Tensor) -> bool:\n    return t.device.type in (\"cpu\", \"cuda\", \"xpu\")","tryCatchPattern":"try:\n    result = _adjust_memory_efficient_attention(latents, max_size=...)\nexcept ValueError as e:\n    if \"unrecognized device\" in str(e):\n        latents = latents.to(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n        result = _adjust_memory_efficient_attention(latents, max_size=...)\n    else:\n        raise","preventionTips":["Restrict pipelines to cpu/cuda/xpu/mps devices","Set explicit device config instead of relying on auto-detection with exotic backends","Extend the memory check if adding a new backend","Smoke-test on target hardware before deploying"],"tags":["device","torch","memory","unsupported-hardware"],"backgroundTag":"unsupported-device-type","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}