{"record":{"id":"56ffa27a816e61bb","repo":"sgl-project/sglang","slug":"only-ver-3-is-supported-for-musa-fa3","errorCode":null,"errorMessage":"Only ver=3 is supported for MUSA FA3.","messagePattern":"Only ver=3 is supported for MUSA FA3\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/hardware_backend/musa/attention/flashattention_backend.py","lineNumber":160,"sourceCode":"    softmax_scale: Optional[float] = None,\n    causal: bool = False,\n    window_size: Tuple[int, int] = (-1, -1),\n    attention_chunk: int = 0,\n    softcap: float = 0.0,\n    rotary_interleaved: bool = True,\n    scheduler_metadata: Optional[torch.Tensor] = None,\n    num_splits: int = 0,\n    pack_gqa=None,\n    sm_margin: int = 0,\n    return_softmax_lse: bool = False,\n    sinks=None,\n    score_mod=None,\n    aux_tensors=None,\n    ver=3,\n):\n    \"\"\"MUSA flash_attn_with_kvcache wrapper that auto-injects scheduler_metadata.\"\"\"\n    if ver != 3:\n        raise ValueError(\"Only ver=3 is supported for MUSA FA3.\")\n\n    if scheduler_metadata is None and _CURRENT_BACKEND is not None:\n        backend = _CURRENT_BACKEND\n        # Ensure backend has been properly set up for this call\n        if backend._current_layer is not None:\n            page_size = k_cache.shape[1] if k_cache is not None else 1\n            scheduler_metadata = _compute_scheduler_metadata(\n                backend=backend,\n                cu_seqlens_q=cu_seqlens_q,\n                cu_seqlens_k_new=cu_seqlens_k_new,\n                cache_seqlens=cache_seqlens,\n                max_seqlen_q=max_seqlen_q,\n                page_size=page_size,\n                causal=causal,\n                window_size=window_size,\n                num_splits=num_splits,\n            )\n","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/hardware_backend/musa/attention/flashattention_backend.py#L142-L178","documentation":"SGLang's MUSA flash-attention wrapper, flash_attn_with_kvcache, is a thin reimplementation of the v3 API for Moore Threads MUSA GPUs and only implements the ver=3 code path; any other ver argument is rejected up front.","triggerScenarios":"Calling flash_attn_with_kvcache(..., ver=2) (or any non-3 value) — usually code written against the upstream flash-attn API that explicitly passes ver=2, or a copied attention kernel defaulting ver differently.","commonSituations":"Porting attention backends from CUDA FA2 to MUSA; shared code paths that select ver based on capability detection and land on 2; third-party kernels calling the wrapper with explicit ver.","solutions":["Pass ver=3 or simply omit the argument (default is ver=3)","If you need FA2-style behavior on MUSA, use the non-FA3 MUSA backend path instead of this wrapper","Audit copied kernel code for hardcoded ver=2"],"exampleFix":"# before\nflash_attn_with_kvcache(q, k, v, ..., ver=2)\n# after\nflash_attn_with_kvcache(q, k, v, ..., ver=3)  # or omit ver","handlingStrategy":"validation","validationCode":"ver = 3  # MUSA wrapper only implements ver=3\nif ver != 3:\n    raise ValueError(\"MUSA FA3 wrapper requires ver=3\")\nout = flash_attn_with_kvcache(q, k, v, ..., ver=ver)","typeGuard":null,"tryCatchPattern":"try:\n    out = flash_attn_with_kvcache(..., ver=requested_ver)\nexcept ValueError as e:\n    if \"ver=3\" in str(e):\n        out = flash_attn_with_kvcache(..., ver=3)  # retry with supported ver\n    else:\n        raise","preventionTips":["Omit ver (defaults to 3) when calling the MUSA wrapper","Don't port CUDA FA2 call sites verbatim to MUSA","Centralize ver selection behind a backend capability flag"],"tags":["musa","flash-attention","moore-threads","sglang"],"backgroundTag":"unsupported-api-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}