{"record":{"id":"846b3f4a1b037004","repo":"sgl-project/sglang","slug":"flash-attn-varlen-func-op-lse-is-out-lse-op-retur","errorCode":null,"errorMessage":"flash_attn_varlen_func_op_lse is out+lse op; return_softmax_lse must be True. Use flash_attn_varlen_func_op for out-only.","messagePattern":"flash_attn_varlen_func_op_lse is out\\+lse op; return_softmax_lse must be True\\. Use flash_attn_varlen_func_op for out-only\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/attention/backends/flash_attn.py","lineNumber":261,"sourceCode":"    causal: bool = False,\n    qv: Optional[torch.Tensor] = None,\n    q_descale: Optional[torch.Tensor] = None,\n    k_descale: Optional[torch.Tensor] = None,\n    v_descale: Optional[torch.Tensor] = None,\n    window_size: Optional[List[int]] = None,\n    attention_chunk: int = 0,\n    softcap: float = 0.0,\n    num_splits: int = 1,\n    pack_gqa: Optional[bool] = None,\n    sm_margin: int = 0,\n    return_softmax_lse: bool = True,\n    sinks: Optional[torch.Tensor] = None,\n    ver: int = 4,\n) -> Tuple[torch.Tensor, torch.Tensor]:\n    if window_size is None:\n        window_size = [-1, -1]\n    if not return_softmax_lse:\n        raise ValueError(\n            \"flash_attn_varlen_func_op_lse is out+lse op; return_softmax_lse must be True. \"\n            \"Use flash_attn_varlen_func_op for out-only.\"\n        )\n    return flash_attn_varlen_func(\n        q,\n        k,\n        v,\n        cu_seqlens_q=cu_seqlens_q,\n        cu_seqlens_k=cu_seqlens_k,\n        max_seqlen_q=max_seqlen_q,\n        max_seqlen_k=max_seqlen_k,\n        seqused_q=seqused_q,\n        seqused_k=seqused_k,\n        page_table=page_table,\n        softmax_scale=softmax_scale,\n        causal=causal,\n        qv=qv,\n        q_descale=q_descale,","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/attention/backends/flash_attn.py#L243-L279","documentation":"flash_attn_varlen_func_op_lse always returns a tuple (output, softmax_lse); calling it with return_softmax_lse=False is contradictory, so it raises and points you to the out-only flash_attn_varlen_func_op.","triggerScenarios":"Calling flash_attn_varlen_func_op_lse(..., return_softmax_lse=False).","commonSituations":"Copy-paste between the two variants during refactor; a shared kwargs dict defaulting return_softmax_lse=False while the call was switched to the _lse function.","solutions":["Use flash_attn_varlen_func_op(...) for out-only results","Or pass return_softmax_lse=True to _op_lse and unpack the 2-tuple"],"exampleFix":"# before\nout = flash_attn_varlen_func_op_lse(q, k, v, cu_q, cu_k, mq, mk, return_softmax_lse=False)\n# after\nout = flash_attn_varlen_func_op(q, k, v, cu_q, cu_k, mq, mk, return_softmax_lse=False)","handlingStrategy":"validation","validationCode":"assert return_softmax_lse is True, \"_op_lse always returns (out, lse); use _op for out-only\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick the function matching the return type you want","Unpack _op_lse results as a 2-tuple"],"tags":["flash-attention","varlen","api-misuse","lse"],"backgroundTag":"wrong-api-variant-called","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}