sgl-project/sglang · error · ValueError

Attention backend '{selected_backend}' is not supported by t

Error message

Attention backend '{selected_backend}' is not supported by this attention layer; supported backends: {supported_attention_backends_str}

What it means

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.

Source

Thrown at python/sglang/multimodal_gen/runtime/layers/attention/selector.py:332

) -> type[AttentionBackend]:
    from sglang.multimodal_gen.runtime.platforms import current_platform

    supported_attention_backends = set(supported_attention_backends)

    # get device-specific attn_backend
    if len(supported_attention_backends) == 0:
        # all attention backends are allowed
        pass
    elif selected_backend is None and len(supported_attention_backends) == 1:
        selected_backend = next(iter(supported_attention_backends))
    elif selected_backend is not None and not _is_backend_supported(
        selected_backend, supported_attention_backends
    ):
        supported_attention_backends_str = [
            supported_attention_backend.__str__()
            for supported_attention_backend in supported_attention_backends
        ]
        raise ValueError(
            f"Attention backend '{selected_backend}' is not supported by this "
            f"attention layer; supported backends: {supported_attention_backends_str}"
        )

    attention_cls = current_platform.get_attn_backend_cls_str(
        selected_backend, head_size, dtype
    )
    if not attention_cls:
        raise ValueError(
            f"Invalid attention backend for {current_platform.device_name}"
        )
    return cast(type[AttentionBackend], resolve_obj_by_qualname(attention_cls))


def _is_backend_supported(
    selected_backend: AttentionBackendEnum,
    supported_attention_backends: set[AttentionBackendEnum],
) -> bool:

View on GitHub (pinned to 0132848349)

Solutions

  1. Use a backend from the error message's supported list
  2. Remove the explicit backend override and let the selector choose
  3. Update the layer's supported_attention_backends if you are intentionally adding support (maintainer action)

Example fix

# before
get_attn_backend("triton", supported=["flashinfer"], ...)
# after
get_attn_backend("flashinfer", supported=["flashinfer"], ...)
Defensive patterns

Strategy: validation

Validate before calling

assert selected_backend in {str(b) for b in supported_attention_backends}, f"{selected_backend} unsupported"

Type guard

def is_supported_backend(name: str, supported: list[str]) -> bool:\n    return name.lower() in {s.lower() for s in supported}

Try / catch

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)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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