{"record":{"id":"c88d41dce0583fe0","repo":"sgl-project/sglang","slug":"fa4-path-does-not-support-rotary-embedding-c88d41","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_sm120.py","lineNumber":244,"sourceCode":"    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    out: Optional[torch.Tensor] = None,\n    max_seqlen_k: Optional[int] = None,\n    **_: object,\n):\n    _validate_out_contract(out)\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    forward_arch = get_forward_arch(q.device) if get_forward_arch is not None else None\n    if (\n        forward_arch is not None\n        and not return_softmax_lse\n        and softcap in (None, 0.0)\n        and all(\n            value is None\n            for value in (\n                qv,","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/flash_attention_v4_sm120.py#L226-L262","documentation":"The sm120 FA4 kvcache path does not fuse rotary embedding; passing rotary_cos, rotary_sin, or rotary_seqlens raises NotImplementedError.","triggerScenarios":"Calling flash_attn_with_kvcache with any rotary_* argument non-None on the FA4 sm120 backend.","commonSituations":"Backend-agnostic wrappers forwarding rope tensors from FA2-style call sites.","solutions":["Apply rope to q (and k before cache write) outside the kernel","Pass rotary_* as None","Fall back to a backend with fused rope"],"exampleFix":"# before\nout = fa.flash_attn_with_kvcache(q, None, None, kc, vc, cache_seqlens=s, rotary_cos=cos, rotary_sin=sin)\n# after\nq = apply_rotary(q, cos, sin)\nout = fa.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","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Apply rope outside the kernel for FA4","Feature-flag backend capabilities"],"tags":["flash-attention","fa4","sm120","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"}