invoke-ai/InvokeAI · error · ValueError

unrecognized device {self.unet.device}

Error message

unrecognized device {self.unet.device}

What it means

_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.

Source

Thrown at invokeai/backend/stable_diffusion/diffusers_pipeline.py:225

        # non-sliced torch-sdp implementation. This keeps things working on MPS at the cost of increased peak memory
        # utilization.
        if torch.backends.mps.is_available():
            return

        # The remainder if this code is called when attention_type=='auto'.
        if self.unet.device.type in ("cuda", "xpu"):
            if is_xformers_available() and prefer_xformers:
                self.enable_xformers_memory_efficient_attention()
                return
            # torch-sdp is the default in diffusers.
            return

        if self.unet.device.type == "cpu" or self.unet.device.type == "mps":
            mem_free = psutil.virtual_memory().free
        elif self.unet.device.type == "cuda":
            mem_free, _ = torch.cuda.mem_get_info(TorchDevice.normalize(self.unet.device))
        else:
            raise ValueError(f"unrecognized device {self.unet.device}")
        # input tensor of [1, 4, h/8, w/8]
        # output tensor of [16, (h/8 * w/8), (h/8 * w/8)]
        bytes_per_element_needed_for_baddbmm_duplication = latents.element_size() + 4
        max_size_required_for_baddbmm = (
            16
            * latents.size(dim=2)
            * latents.size(dim=3)
            * latents.size(dim=2)
            * latents.size(dim=3)
            * bytes_per_element_needed_for_baddbmm_duplication
        )
        if max_size_required_for_baddbmm > (mem_free * 3.0 / 4.0):  # 3.3 / 4.0 is from old Invoke code
            self.enable_attention_slicing(slice_size="max")
        elif torch.backends.mps.is_available():
            # diffusers recommends always enabling for mps
            self.enable_attention_slicing(slice_size="max")
        else:
            self.disable_attention_slicing()

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Run on CUDA, CPU, or MPS hardware, which are the supported device types.
  2. If using a plugin device like xpu, patch/extend _adjust_memory_efficient_attention to handle its memory query.
  3. Disable memory-efficient attention sizing path (e.g. set attention to a fixed backend) to avoid the branch.
  4. Check the --device CLI/config value for typos so it normalizes to 'cuda' or 'cpu'.

Example fix

// before
pipeline.to(torch.device("xpu"))
// after
pipeline.to(torch.device("cuda"))  # or "cpu" / "mps"
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED_DEV_TYPES = {"cpu", "mps", "cuda"}
assert unet.device.type in SUPPORTED_DEV_TYPES, f"unsupported device {unet.device}"

Type guard

def is_supported_device(d: torch.device) -> bool:
    return d.type in {"cpu", "mps", "cuda"}

Try / catch

try:
    latents = pipeline.latents_from_embeddings(...)
except ValueError as e:
    if "unrecognized device" in str(e):
        pipeline = pipeline.to(torch.device("cuda"))
        latents = pipeline.latents_from_embeddings(...)

Prevention

When it happens

Trigger: 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'.

Common situations: Running InvokeAI on non-CUDA accelerators (Intel XPU, Ascend NPU) via PyTorch device plugins; passing an unusual --device value; typos in device configuration.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/a5ef1590101b9932. Report an issue: GitHub.