sgl-project/sglang · error · KeyError
No '{backend.value}' backend registered for op {op!r}
Error message
No '{backend.value}' backend registered for op {op!r} What it means
Raised by select_kernel when the op IS registered but none of its registered KernelSpecs use the explicitly requested backend. This happens when the caller forces backend=<Backend.X> but that backend was never registered for this op (e.g. asking for a triton kernel when only a CUDA one exists).
Source
Thrown at python/sglang/kernels/selector.py:65
current device*; selects which one. Otherwise optional.
Raises
------
KeyError
If ``op`` is unknown, or if ``backend`` is requested but not registered.
ValueError
If ``op`` has multiple device-eligible backends and ``backend`` is not
given, or if none are eligible on this platform.
"""
specs = registry.get(op)
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"View on GitHub (pinned to 0132848349)
Solutions
- Query the registered backends for the op (e.g. [s.backend for s in registry.get(op, [])]) and pass one of those, or omit backend= to let device-eligibility auto-select.
- If you need that backend, verify the sglang version supports it for this op and the optional dependency is installed, then register/upgrade accordingly.
- Guard backend overrides behind a capability check instead of assuming availability.
Example fix
# before
spec = select_kernel(op, backend=Backend.TRITON)
# after
specs = registry.get(op, [])
if any(s.backend == Backend.TRITON for s in specs):
spec = select_kernel(op, backend=Backend.TRITON)
else:
spec = select_kernel(op) # auto-select eligible backend Defensive patterns
Strategy: validation
Validate before calling
from sglang.kernels.registry import registry
def backend_available(op, backend) -> bool:
return any(s.backend == backend for s in registry.get(op, []))
spec = select_kernel(op, backend=b) if backend_available(op, b) else select_kernel(op) Try / catch
try:
spec = select_kernel(op, backend=backend)
except KeyError:
spec = select_kernel(op) # fall back to auto-selection Prevention
- Never hard-code a backend without checking registry contents.
- Treat backend= as an override, with auto-select fallback.
- Test backend overrides on the minimum (single-backend) CI environment.
When it happens
Trigger: select_kernel(op, backend=Backend.TRITON) where the op's specs list only contains, say, Backend.SGL_KERNEL / Backend.FLASHINFER / Backend.TORCH. Also triggered deliberately in test_unknown_op_or_backend_raises.
Common situations: Hard-coding a backend for portability or benchmarking when that op was never implemented in that backend; version drift where a backend implementation was removed or renamed between sglang releases.
Related errors
- No kernels registered for op {op!r}
- op {op!r} has multiple backends usable on device {platform.d
- op {op!r} has no backend usable on device {platform.device.v
- KernelSpec.target must be 'module:attr', got {self.target!r}
- LoRA with name {lora_name} does not exist. Loaded LoRAs: {se
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/8bb11e8bfbbb18fb.
Report an issue: GitHub.