diff --git a/vllm/model_executor/layers/attention/mla_attention.py b/vllm/model_executor/layers/attention/mla_attention.py index 8d9a674319..e1cb20d2e7 100644 --- a/vllm/model_executor/layers/attention/mla_attention.py +++ b/vllm/model_executor/layers/attention/mla_attention.py @@ -818,14 +818,14 @@ class MLAAttention(nn.Module, AttentionLayerBase): attn_out, lse, get_dcp_group(), - is_lse_base_on_e=True, + is_lse_base_on_e=self.impl.lse_base_on_e, ) else: attn_out = cp_lse_ag_out_rs( attn_out, lse, get_dcp_group(), - is_lse_base_on_e=True, + is_lse_base_on_e=self.impl.lse_base_on_e, ) # v_up projection diff --git a/vllm/v1/attention/backend.py b/vllm/v1/attention/backend.py index 61a4e521c4..22c6a38228 100644 --- a/vllm/v1/attention/backend.py +++ b/vllm/v1/attention/backend.py @@ -756,6 +756,17 @@ class AttentionImplBase(ABC, Generic[T]): # Some features like decode context parallelism require the softmax lse. can_return_lse_for_decode: bool = False + # Base of the logarithm used by this backend when returning softmax lse. + # True => natural log (lse = ln(sum(exp(qk)))) + # -- e.g. Triton MLA, FlashAttention, FlashMLA, Cutlass MLA + # False => base 2 (lse = log2(sum(exp(qk)))) + # -- e.g. FlashInfer trtllm-gen MLA + # The DCP combine kernel (cp_lse_ag_out_rs / dcp_a2a_lse_reduce in + # vllm/v1/attention/ops/common.py) branches on this via its IS_BASE_E + # constexpr; getting it wrong silently corrupts the cross-shard + # softmax denominator. + lse_base_on_e: bool = True + # Whether the attention impl supports Prefill Context Parallelism. supports_pcp: bool = False # Whether the attention impl(or ops) supports MTP diff --git a/vllm/v1/attention/backends/mla/flashinfer_mla.py b/vllm/v1/attention/backends/mla/flashinfer_mla.py index 07e2e44140..3216b24db7 100644 --- a/vllm/v1/attention/backends/mla/flashinfer_mla.py +++ b/vllm/v1/attention/backends/mla/flashinfer_mla.py @@ -114,6 +114,13 @@ g_fi_workspace = torch.zeros( class FlashInferMLAImpl(MLACommonImpl[MLACommonMetadata]): can_return_lse_for_decode: bool = True + # trtllm-gen MLA decode emits LSE in log2 (per flashinfer's own + # reference at flashinfer/trace/templates/attention.py:81: + # `logsumexp / log(2.0)`). Override the AttentionImplBase default + # so MLAAttention's DCP combine branches on the correct base + # (IS_BASE_E=False uses tl.exp2/tl.log2 natively, avoiding an FP + # multiply per decode step). + lse_base_on_e: bool = False def __init__( self,