{"record":{"id":"7c92f54b40a99fce","repo":"sgl-project/sglang","slug":"attention-backend-selected-backend-is-not-supp","errorCode":null,"errorMessage":"Attention backend '{selected_backend}' is not supported by this attention layer; supported backends: {supported_attention_backends_str}","messagePattern":"Attention backend '(.+?)' is not supported by this attention layer; supported backends: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/attention/selector.py","lineNumber":332,"sourceCode":") -> type[AttentionBackend]:\n    from sglang.multimodal_gen.runtime.platforms import current_platform\n\n    supported_attention_backends = set(supported_attention_backends)\n\n    # get device-specific attn_backend\n    if len(supported_attention_backends) == 0:\n        # all attention backends are allowed\n        pass\n    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:","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/attention/selector.py#L314-L350","documentation":"Thrown by the cached backend resolver when the explicitly selected backend is not in the layer's supported_attention_backends allow-list. This is a fail-closed guard: models that only work with specific attention implementations reject others upfront.","triggerScenarios":"Passing a selected_backend (e.g. via override) to _cached_get_attn_backend/get_attn_backend when the attention layer declares supported_attention_backends that excludes it; exercised by test_explicit_backend_rejected_by_a_model_fails_closed.","commonSituations":"User forces --attention-backend X on a model whose layers only support Y (e.g. a video model requiring a specific attention path); mixing a global backend override with a model-specific constraint.","solutions":["Use a backend from the error message's supported list","Remove the explicit backend override and let the selector choose","Update the layer's supported_attention_backends if you are intentionally adding support (maintainer action)"],"exampleFix":"# before\nget_attn_backend(\"triton\", supported=[\"flashinfer\"], ...)\n# after\nget_attn_backend(\"flashinfer\", supported=[\"flashinfer\"], ...)","handlingStrategy":"validation","validationCode":"assert selected_backend in {str(b) for b in supported_attention_backends}, f\"{selected_backend} unsupported\"","typeGuard":"def is_supported_backend(name: str, supported: list[str]) -> bool:\\n    return name.lower() in {s.lower() for s in supported}","tryCatchPattern":"try:\\n    backend = get_attn_backend(selected, supported=supported)\\nexcept ValueError as e:\\n    if 'not supported by this attention layer' in str(e):\\n        selected = str(supported[0])\\n        backend = get_attn_backend(selected, supported=supported)","preventionTips":["Fail fast at startup on backend/layer-constraint mismatches","Don't force global backend overrides on constrained models","Log the supported list in error reports"],"tags":["attention-backend","fail-closed","config-validation","multimodal"],"backgroundTag":"backend-selection-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}