{"record":{"id":"a5ef1590101b9932","repo":"invoke-ai/InvokeAI","slug":"unrecognized-device-self-unet-device","errorCode":null,"errorMessage":"unrecognized device {self.unet.device}","messagePattern":"unrecognized device (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/stable_diffusion/diffusers_pipeline.py","lineNumber":225,"sourceCode":"        # non-sliced torch-sdp implementation. This keeps things working on MPS at the cost of increased peak memory\n        # utilization.\n        if torch.backends.mps.is_available():\n            return\n\n        # The remainder if this code is called when attention_type=='auto'.\n        if self.unet.device.type in (\"cuda\", \"xpu\"):\n            if is_xformers_available() and prefer_xformers:\n                self.enable_xformers_memory_efficient_attention()\n                return\n            # torch-sdp is the default in diffusers.\n            return\n\n        if self.unet.device.type == \"cpu\" or self.unet.device.type == \"mps\":\n            mem_free = psutil.virtual_memory().free\n        elif self.unet.device.type == \"cuda\":\n            mem_free, _ = torch.cuda.mem_get_info(TorchDevice.normalize(self.unet.device))\n        else:\n            raise ValueError(f\"unrecognized device {self.unet.device}\")\n        # input tensor of [1, 4, h/8, w/8]\n        # output tensor of [16, (h/8 * w/8), (h/8 * w/8)]\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 max_size_required_for_baddbmm > (mem_free * 3.0 / 4.0):  # 3.3 / 4.0 is from old Invoke code\n            self.enable_attention_slicing(slice_size=\"max\")\n        elif torch.backends.mps.is_available():\n            # diffusers recommends always enabling for mps\n            self.enable_attention_slicing(slice_size=\"max\")\n        else:\n            self.disable_attention_slicing()","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/stable_diffusion/diffusers_pipeline.py#L207-L243","documentation":"_adjust_memory_efficient_attention picks a free-memory measurement source by device type: psutil for cpu/mps, torch.cuda.mem_get_info for cuda. Any other torch device (e.g. xpu, a torch.device with unrecognized type) has no implementation, so ValueError is raised.","triggerScenarios":"Running latents_from_embeddings or multi_diffusion_denoise on a UNet whose .device is neither cpu, mps, nor cuda — e.g. torch.device('xpu'), custom accelerator, or a device string like 'npu'.","commonSituations":"Running InvokeAI on non-CUDA accelerators (Intel XPU, Ascend NPU) via PyTorch device plugins; passing an unusual --device value; typos in device configuration.","solutions":["Run on CUDA, CPU, or MPS hardware, which are the supported device types.","If using a plugin device like xpu, patch/extend _adjust_memory_efficient_attention to handle its memory query.","Disable memory-efficient attention sizing path (e.g. set attention to a fixed backend) to avoid the branch.","Check the --device CLI/config value for typos so it normalizes to 'cuda' or 'cpu'."],"exampleFix":"// before\npipeline.to(torch.device(\"xpu\"))\n// after\npipeline.to(torch.device(\"cuda\"))  # or \"cpu\" / \"mps\"","handlingStrategy":"validation","validationCode":"SUPPORTED_DEV_TYPES = {\"cpu\", \"mps\", \"cuda\"}\nassert unet.device.type in SUPPORTED_DEV_TYPES, f\"unsupported device {unet.device}\"","typeGuard":"def is_supported_device(d: torch.device) -> bool:\n    return d.type in {\"cpu\", \"mps\", \"cuda\"}","tryCatchPattern":"try:\n    latents = pipeline.latents_from_embeddings(...)\nexcept ValueError as e:\n    if \"unrecognized device\" in str(e):\n        pipeline = pipeline.to(torch.device(\"cuda\"))\n        latents = pipeline.latents_from_embeddings(...)","preventionTips":["Stick to CUDA/CPU/MPS for InvokeAI runs","Validate --device values at startup","For third-party accelerators, patch the memory-query branch upstream of generation","Normalize device strings before pipeline.to()"],"tags":["python","valueerror","device","hardware"],"backgroundTag":"unsupported-device","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}