sgl-project/sglang · error · ValueError

Conflicting kernel registration for op {spec.op!r}, backend

Error message

Conflicting kernel registration for op {spec.op!r}, backend {spec.backend.value!r}: {other.target!r} != {spec.target!r}

What it means

The kernel registry forbids two different registrations for the same (op, backend) pair with different targets — the second, conflicting spec raises this so that implementation selection never depends on import order.

Source

Thrown at python/sglang/kernels/registry.py:35

class KernelRegistry:
    """Maps ``"<group>.<name>"`` operator ids to their :class:`KernelSpec` list."""

    def __init__(self) -> None:
        self._by_op: Dict[str, List[KernelSpec]] = defaultdict(list)

    def register(self, spec: KernelSpec) -> KernelSpec:
        """Register ``spec``.

        Re-registering an identical spec is idempotent so that module reloads
        during tests remain safe. A different spec for the same ``(op,
        backend)`` pair is rejected because silently replacing it makes the
        selected implementation depend on import order.
        """
        existing = self._by_op[spec.op]
        for other in existing:
            if other.backend == spec.backend:
                if other != spec:
                    raise ValueError(
                        f"Conflicting kernel registration for op {spec.op!r}, "
                        f"backend {spec.backend.value!r}: "
                        f"{other.target!r} != {spec.target!r}"
                    )
                return spec
        existing.append(spec)
        return spec

    def get(self, op: str) -> List[KernelSpec]:
        """All registered specs for ``op`` (empty list if none)."""
        return list(self._by_op.get(op, ()))

    def get_backend(self, op: str, backend: KernelBackend) -> KernelSpec:
        """The spec for ``op`` provided by ``backend``.

        Raises ``KeyError`` if no such implementation is registered.
        """
        for spec in self._by_op.get(op, ()):

View on GitHub (pinned to 0132848349)

Solutions

  1. Remove the duplicate registration; register each (op, backend) exactly once.
  2. If overriding is intended, unregister/replace the existing spec first or use a distinct op id.
  3. Check for re-imported modules or plugin entry points that duplicate built-in registrations.

Example fix

// before
register_kernel(KernelSpec(op='allreduce', backend=Backend.TRITON, target=my_impl))
register_kernel(KernelSpec(op='allreduce', backend=Backend.TRITON, target=other_impl))  # conflict
// after
register_kernel(KernelSpec(op='allreduce', backend=Backend.TRITON, target=my_impl))  # single registration
Defensive patterns

Strategy: try-catch

Validate before calling

if registry.has(op) and any(s.backend == backend for s in registry._by_op.get(op, ())):
    # already registered, skip

Try / catch

try:
    register_kernel(spec)
except ValueError as e:
    if 'Conflicting kernel registration' not in str(e): raise

Prevention

When it happens

Trigger: Calling register_kernel twice for the same op id and backend with a different target function — e.g. a plugin overriding a built-in kernel, or duplicated registration after a module refactor/re-import.

Common situations: Custom backend plugins that re-register existing ops; stale imports after file moves causing the same spec to be registered with a relocated target; monkey-patching via registration instead of explicit override.

Related errors


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