sgl-project/sglang · error · ValueError

op {op!r} has no backend usable on device {platform.device.v

Error message

op {op!r} has no backend usable on device {platform.device.value!r} (registered: {[s.backend.value for s in specs]})

What it means

Raised when an op has multiple registered backends but, after hard-filtering by device eligibility via spec.is_available(platform), none can run on the current device. This is an environment/platform mismatch: e.g. kernels registered only for CUDA while running on CPU/ROCm, or the backend's optional package is not importable.

Source

Thrown at python/sglang/kernels/selector.py:76

    if not specs:
        raise KeyError(f"No kernels registered for op {op!r}")

    if backend is not None:
        for spec in specs:
            if spec.backend == backend:
                return spec
        raise KeyError(f"No '{backend.value}' backend registered for op {op!r}")

    if len(specs) == 1:
        return specs[0]

    # Multiple backends: hard-filter by device eligibility.
    platform = _platform()
    eligible = [s for s in specs if s.is_available(platform)]
    if len(eligible) == 1:
        return eligible[0]
    if not eligible:
        raise ValueError(
            f"op {op!r} has no backend usable on device {platform.device.value!r} "
            f"(registered: {[s.backend.value for s in specs]})"
        )
    raise ValueError(
        f"op {op!r} has multiple backends usable on device "
        f"{platform.device.value!r} ({[s.backend.value for s in eligible]}); "
        f"pass backend=... to choose one"
    )


@lru_cache(maxsize=None)
def _resolve(op: str, backend: Optional[KernelBackend]) -> Callable:
    return select_kernel(op, backend=backend).load()


def get_kernel(op: str, backend: Optional[KernelBackend] = None) -> Callable:
    """Resolve ``op`` to a callable kernel and cache it.

View on GitHub (pinned to 0132848349)

Solutions

  1. Install the optional backend package the op needs (e.g. the flashinfer or sgl-kernel wheel matching your torch/CUDA version).
  2. Verify the runtime device matches what the kernels support (CUDA available, correct compute capability); run on supported hardware.
  3. If you have a working backend for your device, pass backend= explicitly so eligibility filtering is skipped only when that backend is registered.

Example fix

# before (on a host where flashinfer/cuda kernels unavailable)
spec = select_kernel(op)

# after
pip install flashinfer  # or sgl-kernel matching your torch build
spec = select_kernel(op)
Defensive patterns

Strategy: fallback

Validate before calling

from sglang.kernels.registry import registry
from sglang.kernels.platform import _platform

p = _platform()
eligible = [s for s in registry.get(op, []) if s.is_available(p)]
if not eligible:
    raise SystemExit(f"No kernel backend for {op} on {p.device}; install flashinfer/sgl-kernel")

Try / catch

try:
    spec = select_kernel(op)
except ValueError as e:
    if 'no backend usable' in str(e):
        use_pure_torch_fallback()  # e.g. torch-native implementation
    else:
        raise

Prevention

When it happens

Trigger: select_kernel(op) with no explicit backend on a machine where every registered backend's is_available(platform) returns False — missing flashinfer/sgl-kernel packages, running on a device none of the specs target (CPU host, unsupported GPU arch).

Common situations: Running sglang on non-CUDA hardware or a container without the compiled kernel wheels; CI machines without GPUs; a new backend whose availability check fails due to an uninstalled dependency.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/69361b1cc9660dd3. Report an issue: GitHub.