sgl-project/sglang · error · NotImplementedError

FA4 path does not support rotary embedding.

Error message

FA4 path does not support rotary embedding.

What it means

The sm120 FA4 kvcache path does not fuse rotary embedding; passing rotary_cos, rotary_sin, or rotary_seqlens raises NotImplementedError.

Source

Thrown at python/sglang/kernels/ops/attention/flash_attention_v4_sm120.py:244

    sm_margin: int = 0,
    sinks: Optional[torch.Tensor] = None,
    score_mod: Optional[Callable] = None,
    aux_tensors: Optional[list] = None,
    sfq: Optional[torch.Tensor] = None,
    sfk: Optional[torch.Tensor] = None,
    sfv: Optional[torch.Tensor] = None,
    rel_bias: Optional[torch.Tensor] = None,
    rel_bias_prep_cache: Optional[dict] = None,
    return_softmax_lse: bool = False,
    out: Optional[torch.Tensor] = None,
    max_seqlen_k: Optional[int] = None,
    **_: object,
):
    _validate_out_contract(out)
    if k is not None or v is not None:
        raise NotImplementedError("FA4 does not support updating KV cache in-place.")
    if rotary_cos is not None or rotary_sin is not None or rotary_seqlens is not None:
        raise NotImplementedError("FA4 path does not support rotary embedding.")
    if cache_batch_idx is not None or cache_leftpad is not None:
        raise NotImplementedError(
            "FA4 path does not support non-consecutive batch indices or left padding."
        )
    if isinstance(cache_seqlens, int):
        cache_seqlens = torch.full(
            (k_cache.shape[0],), cache_seqlens, dtype=torch.int32, device=k_cache.device
        )

    forward_arch = get_forward_arch(q.device) if get_forward_arch is not None else None
    if (
        forward_arch is not None
        and not return_softmax_lse
        and softcap in (None, 0.0)
        and all(
            value is None
            for value in (
                qv,

View on GitHub (pinned to 0132848349)

Solutions

  1. Apply rope to q (and k before cache write) outside the kernel
  2. Pass rotary_* as None
  3. Fall back to a backend with fused rope

Example fix

# before
out = fa.flash_attn_with_kvcache(q, None, None, kc, vc, cache_seqlens=s, rotary_cos=cos, rotary_sin=sin)
# after
q = apply_rotary(q, cos, sin)
out = fa.flash_attn_with_kvcache(q, None, None, kc, vc, cache_seqlens=s)
Defensive patterns

Strategy: validation

Validate before calling

assert rotary_cos is None and rotary_sin is None and rotary_seqlens is None

Prevention

When it happens

Trigger: Calling flash_attn_with_kvcache with any rotary_* argument non-None on the FA4 sm120 backend.

Common situations: Backend-agnostic wrappers forwarding rope tensors from FA2-style call sites.

Related errors


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