invoke-ai/InvokeAI · error · ValueError
unrecognized device {latents.device}
Error message
unrecognized device {latents.device} What it means
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.
Source
Thrown at invokeai/backend/util/attention.py:30
def auto_detect_slice_size(latents: torch.Tensor) -> str:
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 latents.device.type in {"cpu", "mps"}:
mem_free = psutil.virtual_memory().free
elif latents.device.type == "cuda":
mem_free, _ = torch.cuda.mem_get_info(latents.device)
elif latents.device.type == "xpu":
mem_free, _ = TorchDevice.xpu_mem_get_info(latents.device)
else:
raise ValueError(f"unrecognized device {latents.device}")
if max_size_required_for_baddbmm > (mem_free * 3.0 / 4.0):
return "max"
elif torch.backends.mps.is_available():
return "max"
else:
return "balanced"
View on GitHub (pinned to 0b6a024f2f)
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
Example fix
// before
latents = latents.to("privateuseone")
result = _adjust_memory_efficient_attention(latents, ...)
// after
latents = latents.to("cuda")
result = _adjust_memory_efficient_attention(latents, ...) Defensive patterns
Strategy: type-guard
Validate before calling
supported = {"cpu", "cuda", "xpu"}
assert latents.device.type in supported, f"device {latents.device.type} not supported for auto slice sizing"
Type guard
def is_supported_device(t: torch.Tensor) -> bool:
return t.device.type in ("cpu", "cuda", "xpu") Try / catch
try:
result = _adjust_memory_efficient_attention(latents, max_size=...)
except ValueError as e:
if "unrecognized device" in str(e):
latents = latents.to("cuda" if torch.cuda.is_available() else "cpu")
result = _adjust_memory_efficient_attention(latents, max_size=...)
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The requested transition needs an estimated {estimated_mib:.
- Expected torch.Tensor for input_ids, got {type(text_input_id
- Expected torch.Tensor for prompt embeddings, got {type(promp
- {name}
- unrecognized device {self.unet.device}
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/b9c508e13d77f7bc.
Report an issue: GitHub.