invoke-ai/InvokeAI · error · ValueError
generation_devices requested '{device_str}', but only {torch
Error message
generation_devices requested '{device_str}', but only {torch.xpu.device_count()} XPU device(s) are available (valid indices 0-{torch.xpu.device_count() - 1}). What it means
XPU analog of the CUDA index check: XPU is available, but the requested index is >= torch.xpu.device_count(). The message enumerates the valid index range so configs can be corrected directly.
Source
Thrown at invokeai/backend/util/devices.py:307
seen: set[str] = set()
for device_str in device_strs:
device = cls.normalize(device_str)
# Fail fast on a CUDA device that doesn't exist, rather than starting a worker pinned to
# it that only errors cryptically at the first tensor allocation. ("auto" only generates
# valid indices, so this just validates explicitly-configured devices.)
if device.type == "cuda":
if not torch.cuda.is_available():
raise ValueError(f"generation_devices requested '{device_str}', but no CUDA device is available.")
if device.index is not None and device.index >= torch.cuda.device_count():
raise ValueError(
f"generation_devices requested '{device_str}', but only {torch.cuda.device_count()} "
f"CUDA device(s) are available (valid indices 0-{torch.cuda.device_count() - 1})."
)
elif device.type == "xpu":
if not _xpu_is_available():
raise ValueError(f"generation_devices requested '{device_str}', but no XPU device is available.")
if device.index is not None and device.index >= torch.xpu.device_count():
raise ValueError(
f"generation_devices requested '{device_str}', but only {torch.xpu.device_count()} "
f"XPU device(s) are available (valid indices 0-{torch.xpu.device_count() - 1})."
)
elif device.type == "mps" and not torch.backends.mps.is_available():
raise ValueError(f"generation_devices requested '{device_str}', but MPS is not available.")
if str(device) not in seen:
seen.add(str(device))
devices.append(device)
return devices
@classmethod
def normalize(cls, device: Union[str, torch.device]) -> torch.device:
"""Add the device index to CUDA and XPU devices."""
device = torch.device(device)
if device.index is None and device.type == "cuda" and torch.cuda.is_available():
device = torch.device(device.type, torch.cuda.current_device())
elif device.index is None and device.type == "xpu" and _xpu_is_available():
device = torch.device(device.type, torch.xpu.current_device())View on GitHub (pinned to 0b6a024f2f)
Solutions
- Set the device to an in-range index (e.g. xpu:0) or use 'auto'
- Check torch.xpu.device_count() and the host's Intel GPU enumeration (clinfo/xpu-smi)
- Fix device visibility (e.g. device passthrough settings) if an XPU should exist
Example fix
// before generation_devices: ["xpu:1"] # only one Intel GPU visible // after generation_devices: ["xpu:0"]
Defensive patterns
Strategy: validation
Validate before calling
import torch
for d in generation_devices:
if d.startswith("xpu:"):
idx = int(d.split(":")[1])
if idx >= torch.xpu.device_count():
raise SystemExit(f"{d} invalid: only {torch.xpu.device_count()} XPU device(s)") Type guard
def xpu_index_in_range(device_str: str) -> bool:
if not device_str.startswith("xpu:"):
return True
return int(device_str.split(":")[1]) < torch.xpu.device_count() Try / catch
try:
devices = DeviceService.get_generation_devices(cfg.generation_devices)
except ValueError as e:
if "XPU device(s) are available" in str(e):
log.warning("Requested XPU index out of range; using auto")
devices = DeviceService.get_generation_devices(["auto"])
else:
raise Prevention
- Match xpu indices to torch.xpu.device_count() on the actual host
- Re-validate configs after hardware or container passthrough changes
- Use xpu-smi/clinfo to confirm visible Intel GPUs
- Prefer 'auto' unless pinning is required
When it happens
Trigger: Configuring generation_devices 'xpu:1' or higher when torch.xpu.device_count() returns fewer devices — e.g. one Intel GPU present but config copied from a two-GPU host.
Common situations: Intel GPU missing/detached at boot, container device passthrough exposing fewer XPUs, or configs copied across machines with different GPU counts.
Related errors
- generation_devices requested '{device_str}', but only {torch
- Invalid regex: {e}
- Invalid generation_devices value '{v}'. Use 'auto' or a list
- generation_devices cannot be an empty list. Use 'auto' or a
- base_url must not start with reserved path segment '/{first_
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/0e317e44599547b0.
Report an issue: GitHub.