invoke-ai/InvokeAI · error · RuntimeError

{fn_name} failed

Error message

{fn_name} failed

What it means

_enumerate implements Level Zero's two-call enumeration pattern: first ask for the device count, then fill an array. A non-zero result code from the first (count) call raises this RuntimeError, indicating the zeDevice/zeSysman enumeration function itself failed (driver error, uninitialized loader, or permission problem).

Source

Thrown at invokeai/backend/util/level_zero.py:173

    Level Zero's enumeration order is only meaningfully comparable to torch's ``xpu:N`` ordering
    when both see the same set. If the counts disagree (``ZE_AFFINITY_MASK``, a flat/composite
    tile hierarchy, a non-Intel Level Zero driver in the list), decline to answer rather than risk
    mislabelling a device.
    """
    devices: list[ctypes.c_void_p] = []
    for driver in _enumerate(lib, driver_get):
        devices += _enumerate(lib, device_get, driver)
    return devices if len(devices) == torch.xpu.device_count() else None


def _enumerate(lib: ctypes.CDLL, fn_name: str, parent: Optional[ctypes.c_void_p] = None) -> list[ctypes.c_void_p]:
    """Level Zero's two-call enumeration: ask for the count, then fill an array."""
    fn = getattr(lib, fn_name)
    count = ctypes.c_uint32(0)
    head = [parent] if parent is not None else []
    if fn(*head, ctypes.byref(count), None) != 0:
        raise RuntimeError(f"{fn_name} failed")
    if count.value == 0:
        return []
    arr = (ctypes.c_void_p * count.value)()
    if fn(*head, ctypes.byref(count), arr) != 0:
        raise RuntimeError(f"{fn_name} failed")
    return list(arr[: count.value])


def _probe_integrated_flags() -> Optional[dict[int, bool]]:
    lib = _load_loader()
    if lib is None:
        return None
    try:
        if lib.zeInit(0) != 0:
            return None
        devices = _enumerate_devices(lib, "zeDriverGet", "zeDeviceGet")
        if devices is None:
            return None

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Check GPU driver health (dmesg for i915/xe errors) and reload or update the Intel GPU driver
  2. Ensure the container/host exposes GPU devices (/dev/dri/*) and renders group access
  3. Confirm the level-zero loader version matches the installed driver

Example fix

// before (docker)
docker run invokeai
// after
docker run --device /dev/dri --group-add $(getent group render | cut -d: -f3) invokeai
Defensive patterns

Strategy: retry

Validate before calling

import ctypes
lib = ctypes.CDLL("libze_loader.so.1")
if not hasattr(lib, fn_name):
    raise RuntimeError("loader missing fn")
# check GPU present first:
import os
if not os.path.exists("/dev/dri"):
    raise RuntimeError("no GPU devices exposed")

Type guard

def gpu_accessible():
    import os
    return any(p.startswith("card") for p in os.listdir("/dev/dri")) if os.path.isdir("/dev/dri") else False

Try / catch

for attempt in range(3):
    try:
        devices = enumerate_devices(lib)
        break
    except RuntimeError as e:
        logger.warning("enumeration attempt %d failed: %s", attempt, e)
        time.sleep(1)
else:
    devices = []

Prevention

When it happens

Trigger: The first ze*Enumerate* call returns a non-zero result code — e.g. driver not initialized, zeInit not performed, GPU inaccessible, or Level Zero driver failure during _enumerate_devices/_init_sysman.

Common situations: Intel GPU driver crashes or being reset; running in containers without /dev/dri device access; incompatible level-zero loader/driver pairs.

Related errors


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