{"record":{"id":"a42643fcbc694cc1","repo":"sgl-project/sglang","slug":"invalid-attention-backend-for-current-platform-de","errorCode":null,"errorMessage":"Invalid attention backend for {current_platform.device_name}","messagePattern":"Invalid attention backend for (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/attention/selector.py","lineNumber":341,"sourceCode":"    elif selected_backend is None and len(supported_attention_backends) == 1:\n        selected_backend = next(iter(supported_attention_backends))\n    elif selected_backend is not None and not _is_backend_supported(\n        selected_backend, supported_attention_backends\n    ):\n        supported_attention_backends_str = [\n            supported_attention_backend.__str__()\n            for supported_attention_backend in supported_attention_backends\n        ]\n        raise ValueError(\n            f\"Attention backend '{selected_backend}' is not supported by this \"\n            f\"attention layer; supported backends: {supported_attention_backends_str}\"\n        )\n\n    attention_cls = current_platform.get_attn_backend_cls_str(\n        selected_backend, head_size, dtype\n    )\n    if not attention_cls:\n        raise ValueError(\n            f\"Invalid attention backend for {current_platform.device_name}\"\n        )\n    return cast(type[AttentionBackend], resolve_obj_by_qualname(attention_cls))\n\n\ndef _is_backend_supported(\n    selected_backend: AttentionBackendEnum,\n    supported_attention_backends: set[AttentionBackendEnum],\n) -> bool:\n    if selected_backend in supported_attention_backends:\n        return True\n    if selected_backend == AttentionBackendEnum.TORCH_CUDNN_SDPA:\n        return AttentionBackendEnum.TORCH_SDPA in supported_attention_backends\n    if selected_backend == AttentionBackendEnum.DYNAMIC_CUDNN_SDPA:\n        return (\n            AttentionBackendEnum.FA in supported_attention_backends\n            and AttentionBackendEnum.TORCH_SDPA in supported_attention_backends\n        )","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/attention/selector.py#L323-L359","documentation":"Raised when current_platform.get_attn_backend_cls_str returns a falsy value, meaning the selected backend name has no registered implementation class string for the active platform/device. It signals a backend/platform mismatch rather than a missing module.","triggerScenarios":"Calling _cached_get_attn_backend/get_attn_backend with a backend name that the current platform's registry does not map to any class (e.g. a CUDA-only backend on CPU/NPU, or a typo'd/renamed backend name).","commonSituations":"Running on a non-CUDA device with a CUDA backend name; backend renamed between versions; platform detection picking the wrong device.","solutions":["Use a backend supported by current_platform.device_name (check the platform's backend mapping)","Fix the backend name spelling / update to the new name after a version change","Set the correct platform/device env so detection matches your hardware"],"exampleFix":"# before (on CPU)\nget_attn_backend(\"fa3\", ...)\n# after\nget_attn_backend(\"torch_native\" if current_platform.device_name==\"cpu\" else \"fa3\", ...)","handlingStrategy":"validation","validationCode":"cls_str = current_platform.get_attn_backend_cls_str(selected_backend, head_size, dtype)\nif not cls_str:\\n    raise SystemExit(f'{selected_backend} unavailable on {current_platform.device_name}')","typeGuard":null,"tryCatchPattern":"try:\\n    backend_cls = get_attn_backend(name, ...)\\nexcept ValueError as e:\\n    if 'Invalid attention backend' in str(e):\\n        # pick a platform-portable default\\n        backend_cls = get_attn_backend('triton', ...)","preventionTips":["Map device->supported backends in deployment config","Verify platform detection env (e.g. CUDA_VISIBLE_DEVICES) before launch","Use device-conditional backend selection"],"tags":["attention-backend","platform-mismatch","device-support"],"backgroundTag":"backend-selection-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}