[Spec Decode] Support SWA + DFlash for MiMo (#46104)

This commit is contained in:
Benjamin Chislett
2026-06-30 20:34:47 -07:00
committed by GitHub
parent 3406e8f83d
commit 9969466a59
4 changed files with 243 additions and 25 deletions
+16 -3
View File
@@ -53,7 +53,12 @@ from vllm.sequence import IntermediateTensors
from vllm.v1.attention.backend import AttentionType
from vllm.v1.attention.backends.registry import AttentionBackendEnum
from .interfaces import MixtureOfExperts, SupportsPP
from .interfaces import (
EagleModelMixin,
MixtureOfExperts,
SupportsEagle3,
SupportsPP,
)
from .utils import (
AutoWeightsLoader,
PPMissingLayer,
@@ -539,7 +544,7 @@ def _shard_fp8_qkv_proj(
@support_torch_compile
class MiMoV2Model(nn.Module):
class MiMoV2Model(nn.Module, EagleModelMixin):
def __init__(self, *, vllm_config: VllmConfig, prefix: str = ""):
super().__init__()
@@ -602,10 +607,16 @@ class MiMoV2Model(nn.Module):
hidden_states = intermediate_tensors["hidden_states"]
residual = intermediate_tensors["residual"]
aux_hidden_states = self._maybe_add_hidden_state(
[], self.start_layer, hidden_states, residual
)
for idx, layer in enumerate(
islice(self.layers, self.start_layer, self.end_layer)
):
hidden_states, residual = layer(positions, hidden_states, residual)
self._maybe_add_hidden_state(
aux_hidden_states, idx + 1, hidden_states, residual
)
if not get_pp_group().is_last_rank:
return IntermediateTensors(
@@ -614,6 +625,8 @@ class MiMoV2Model(nn.Module):
hidden_states, _ = self.norm(hidden_states, residual)
if len(aux_hidden_states) > 0:
return hidden_states, aux_hidden_states
return hidden_states
def get_expert_mapping(self) -> list[tuple[str, str, int, str]]:
@@ -822,7 +835,7 @@ class MiMoV2Model(nn.Module):
return True
class MiMoV2FlashForCausalLM(nn.Module, SupportsPP, MixtureOfExperts):
class MiMoV2FlashForCausalLM(nn.Module, SupportsPP, MixtureOfExperts, SupportsEagle3):
packed_modules_mapping = {
"qkv_proj": ["q_proj", "k_proj", "v_proj"],
"gate_up_proj": ["gate_proj", "up_proj"],