{"record":{"id":"bfac7911bb81073a","repo":"sgl-project/sglang","slug":"fa4-path-does-not-support-rotary-embedding","errorCode":null,"errorMessage":"FA4 path does not support rotary embedding.","messagePattern":"FA4 path does not support rotary embedding\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/attention/flash_attention_v4.py","lineNumber":266,"sourceCode":"    scheduler_metadata=None,\n    num_splits: int = 0,\n    pack_gqa: Optional[bool] = None,\n    sm_margin: int = 0,\n    sinks: Optional[torch.Tensor] = None,\n    score_mod: Optional[Callable] = None,\n    aux_tensors: Optional[list] = None,\n    sfq: Optional[torch.Tensor] = None,\n    sfk: Optional[torch.Tensor] = None,\n    sfv: Optional[torch.Tensor] = None,\n    rel_bias: Optional[torch.Tensor] = None,\n    rel_bias_prep_cache: Optional[dict] = None,\n    return_softmax_lse: bool = False,\n    **_: object,\n):\n    if k is not None or v is not None:\n        raise NotImplementedError(\"FA4 does not support updating KV cache in-place.\")\n    if rotary_cos is not None or rotary_sin is not None or rotary_seqlens is not None:\n        raise NotImplementedError(\"FA4 path does not support rotary embedding.\")\n    if cache_batch_idx is not None or cache_leftpad is not None:\n        raise NotImplementedError(\n            \"FA4 path does not support non-consecutive batch indices or left padding.\"\n        )\n    if isinstance(cache_seqlens, int):\n        cache_seqlens = torch.full(\n            (k_cache.shape[0],), cache_seqlens, dtype=torch.int32, device=k_cache.device\n        )\n\n    result = flash_attn_varlen_func(\n        q=q,\n        k=k_cache,\n        v=v_cache,\n        qv=qv,\n        cu_seqlens_q=cu_seqlens_q,\n        seqused_k=cache_seqlens,\n        max_seqlen_q=max_seqlen_q,\n        page_table=page_table,","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/flash_attention_v4.py#L248-L284","documentation":"The FA4 path does not implement rotary embedding fused into the attention kernel. Passing rotary_cos/rotary_sin/rotary_seqlens raises NotImplementedError.","triggerScenarios":"Calling flash_attn_with_kvcache(rotary_cos=..., rotary_sin=..., ...) or with rotary_seqlens on the FA4 backend.","commonSituations":"Attention wrappers that always pass rope tensors (as FA2/FA3 accept them) when the model uses rotary position embeddings.","solutions":["Apply rotary embedding to q (and pre-rotated k in the cache) before calling FA4","Pass rotary_cos/rotary_sin/rotary_seqlens as None","Use FA2/FA3 backend if fused rope is needed"],"exampleFix":"# before\nout = fa4.flash_attn_with_kvcache(q, k, v, kc, vc, cache_seqlens=s, rotary_cos=cos, rotary_sin=sin)\n# after\nq = apply_rotary(q, cos, sin)\nout = fa4.flash_attn_with_kvcache(q, None, None, kc, vc, cache_seqlens=s)","handlingStrategy":"validation","validationCode":"assert rotary_cos is None and rotary_sin is None and rotary_seqlens is None, 'apply rope before FA4'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Apply rope to q before the FA4 call","Guard backend-specific kwargs behind backend feature flags"],"tags":["flash-attention","fa4","rotary-embedding","unsupported-operation"],"backgroundTag":"unsupported-feature-in-backend","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}