{"record":{"id":"8bb11e8bfbbb18fb","repo":"sgl-project/sglang","slug":"no-backend-value-backend-registered-for-op-op-8bb11e","errorCode":null,"errorMessage":"No '{backend.value}' backend registered for op {op!r}","messagePattern":"No '(.+?)' backend registered for op (.+?)","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/selector.py","lineNumber":65,"sourceCode":"        current device*; selects which one. Otherwise optional.\n\n    Raises\n    ------\n    KeyError\n        If ``op`` is unknown, or if ``backend`` is requested but not registered.\n    ValueError\n        If ``op`` has multiple device-eligible backends and ``backend`` is not\n        given, or if none are eligible on this platform.\n    \"\"\"\n    specs = registry.get(op)\n    if not specs:\n        raise KeyError(f\"No kernels registered for op {op!r}\")\n\n    if backend is not None:\n        for spec in specs:\n            if spec.backend == backend:\n                return spec\n        raise KeyError(f\"No '{backend.value}' backend registered for op {op!r}\")\n\n    if len(specs) == 1:\n        return specs[0]\n\n    # Multiple backends: hard-filter by device eligibility.\n    platform = _platform()\n    eligible = [s for s in specs if s.is_available(platform)]\n    if len(eligible) == 1:\n        return eligible[0]\n    if not eligible:\n        raise ValueError(\n            f\"op {op!r} has no backend usable on device {platform.device.value!r} \"\n            f\"(registered: {[s.backend.value for s in specs]})\"\n        )\n    raise ValueError(\n        f\"op {op!r} has multiple backends usable on device \"\n        f\"{platform.device.value!r} ({[s.backend.value for s in eligible]}); \"\n        f\"pass backend=... to choose one\"","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/selector.py#L47-L83","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nspec = select_kernel(op, backend=Backend.TRITON)\n\n# after\nspecs = registry.get(op, [])\nif any(s.backend == Backend.TRITON for s in specs):\n    spec = select_kernel(op, backend=Backend.TRITON)\nelse:\n    spec = select_kernel(op)  # auto-select eligible backend","handlingStrategy":"validation","validationCode":"from sglang.kernels.registry import registry\n\ndef backend_available(op, backend) -> bool:\n    return any(s.backend == backend for s in registry.get(op, []))\n\nspec = select_kernel(op, backend=b) if backend_available(op, b) else select_kernel(op)","typeGuard":null,"tryCatchPattern":"try:\n    spec = select_kernel(op, backend=backend)\nexcept KeyError:\n    spec = select_kernel(op)  # fall back to auto-selection","preventionTips":["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."],"tags":["kernels","backend-selection","registry","sglang"],"backgroundTag":"requested-backend-not-available","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}