From a5d4a264dd2e05d09ab03e7fe113c6cde3096736 Mon Sep 17 00:00:00 2001 From: JiangWeixiang <854746559@qq.com> Date: Tue, 28 Apr 2026 13:39:23 +0800 Subject: [PATCH] [Bugfix ] fix bailing_moe_linear (#40859) Signed-off-by: ghphotoframe <854746559@qq.com> (cherry picked from commit ed57f771923703998a17ad656536ffb460447a2c) --- .../layers/mamba/mamba_utils.py | 3 -- .../models/bailing_moe_linear.py | 28 ++++++++++--------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/vllm/model_executor/layers/mamba/mamba_utils.py b/vllm/model_executor/layers/mamba/mamba_utils.py index a5a30502b21..c1fd81e40e3 100644 --- a/vllm/model_executor/layers/mamba/mamba_utils.py +++ b/vllm/model_executor/layers/mamba/mamba_utils.py @@ -55,9 +55,6 @@ class MambaStateDtypeCalculator: model_dtype: ModelDType | torch.dtype, mamba_cache_dtype: MambaDType, ) -> tuple[torch.dtype, ...]: - # TODO (tdoublep) requires testing - if mamba_cache_dtype == "float32": - raise ValueError("fp32 state for minimax is not yet supported") state_dtype = get_kv_cache_torch_dtype(mamba_cache_dtype, model_dtype) return (state_dtype,) diff --git a/vllm/model_executor/models/bailing_moe_linear.py b/vllm/model_executor/models/bailing_moe_linear.py index e26adc17430..55ea1bad44d 100644 --- a/vllm/model_executor/models/bailing_moe_linear.py +++ b/vllm/model_executor/models/bailing_moe_linear.py @@ -17,6 +17,7 @@ from vllm.distributed import ( ) from vllm.forward_context import get_forward_context from vllm.logger import init_logger +from vllm.model_executor.custom_op import PluggableLayer from vllm.model_executor.layers.fla.ops.layernorm_guard import ( RMSNormGated, layernorm_fn, @@ -211,7 +212,6 @@ class BailingMoeV25MLAAttention(nn.Module): max_position=max_position, is_neox_style=False, rope_parameters=rope_parameters or None, - dtype=torch.float32, ) # Build MLAModules for MultiHeadLatentAttentionWrapper @@ -425,14 +425,18 @@ class BailingGroupRMSNormGate(RMSNormGated): param.data.copy_(loaded_weight[shard].contiguous()) -class BailingMoELinearAttention(nn.Module, MambaBase): - """ - Bailing MoE Linear Attention implementation using minimax backend. +# --8<-- [start:bailing_moe_linear_attention] +@PluggableLayer.register("bailing_moe_linear_attention") +class BailingMoELinearAttention(PluggableLayer, MambaBase): + """Pluggable Bailing MoE Linear Attention layer which allows OOT backends + to add custom implementations. - This implements the linear attention mechanism from sglang, adapted for vLLM's - v1 engine with MambaBase interface support. + This implements the linear attention mechanism from sglang, adapted for + vLLM's v1 engine with MambaBase interface support. """ + # --8<-- [end:bailing_moe_linear_attention] + @property def mamba_type(self) -> str: return "linear_attention" @@ -569,7 +573,6 @@ class BailingMoELinearAttention(nn.Module, MambaBase): self.head_dim, max_position=self.max_position_embeddings, is_neox_style=True, - dtype=torch.float32, rope_parameters=rope_parameters or None, ) @@ -754,8 +757,6 @@ class BailingMoELinearAttention(nn.Module, MambaBase): def _decode_infer(self, q, k, v, kv_cache, state_indices_tensor, attn_metadata): """Handle decode (single token per sequence).""" - num_prefill_tokens = attn_metadata.num_prefill_tokens - num_prefills = attn_metadata.num_prefills hidden = linear_attention_decode( q, k, @@ -763,10 +764,10 @@ class BailingMoELinearAttention(nn.Module, MambaBase): kv_cache, self.tp_slope, state_indices_tensor, - q_start=num_prefill_tokens, - q_end=None, - slot_start=num_prefills, - slot_end=None, + q_start=0, + q_end=attn_metadata.num_decode_tokens, + slot_start=0, + slot_end=attn_metadata.num_decodes, block_size=32, ) return hidden @@ -1149,6 +1150,7 @@ class BailingMoeV25ForCausalLM(nn.Module, HasInnerState, IsHybrid, SupportsPP): config.vocab_size, config.hidden_size, quant_config=quant_config, + prefix=maybe_prefix(prefix, "lm_head"), ) self.logits_processor = LogitsProcessor(config.vocab_size) else: