sgl-project/sglang · error · KeyError

No kernels registered for op {op!r}

Error message

No kernels registered for op {op!r}

What it means

Raised by sglang's kernel registry (select_kernel) when the requested operation name has no KernelSpec entries registered at all. The registry is a dict keyed by op name; a lookup for an unregistered or misspelled op returns nothing and this KeyError fires. It is a programmer/API-usage error, not an environment error.

Source

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

    Parameters
    ----------
    op:
        Operator id, ``"<group>.<name>"``.
    backend:
        Required only when ``op`` has more than one backend *usable on the
        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} "

View on GitHub (pinned to 0132848349)

Solutions

  1. Check the exact spelling of the op constant against the registry keys (inspect via the kernels registry API or grep for the registration).
  2. Ensure the module containing the kernel's @register decorator is imported before select_kernel is called.
  3. If the op genuinely does not exist in your sglang version, upgrade/downgrade to a version that registers it, or register your own KernelSpec.

Example fix

// before
spec = select_kernel("fused_moe6")  # typo

// after
from sglang.kernels.registry import registry
print(list(registry.keys()))  # find the correct op name
spec = select_kernel(correct_op_name)
Defensive patterns

Strategy: validation

Validate before calling

from sglang.kernels.selector import select_kernel
from sglang.kernels.registry import registry

def op_registered(op) -> bool:
    return op in registry and len(registry[op]) > 0

Try / catch

try:
    spec = select_kernel(op)
except KeyError as e:
    raise ValueError(f"Unsupported kernel op; registered: {sorted(registry)}") from e

Prevention

When it happens

Trigger: Calling select_kernel(op) or the internal _resolve() with an op string that was never registered via the kernels registry — e.g. a typo ('moe_align' vs 'moe_aliged_sorted_ids'), or a newly-introduced op whose registration decorator/entry was never executed (module not imported).

Common situations: Using an op name from a newer/older sglang version where the op doesn't exist yet; forgetting to import the module that registers the kernel; unit tests (test_unknown_op_or_backend_raises) exercise this path deliberately.

Related errors


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