Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion vllm/model_executor/models/qwen3_5_mtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
)
from vllm.model_executor.models.qwen3_next import (
QwenNextMixtureOfExperts,
_all_gather_hidden_and_residual,
_is_shared_expert_fse_compatible,
)
from vllm.sequence import IntermediateTensors
Expand Down Expand Up @@ -150,7 +151,8 @@ def forward(
residual = intermediate_tensors["residual"]

current_step_idx = spec_step_idx % self.num_mtp_layers
hidden_states, residual = self.layers[current_step_idx](
mtp_layer = self.layers[current_step_idx]
hidden_states, residual = mtp_layer(
positions=positions,
hidden_states=hidden_states,
residual=residual,
Expand All @@ -161,6 +163,13 @@ def forward(
{"hidden_states": hidden_states, "residual": residual}
)

if mtp_layer.use_attn_reduce_scatter_for_moe:
hidden_states, residual = _all_gather_hidden_and_residual(
hidden_states,
residual,
positions.shape[-1],
self.config.hidden_size,
)
hidden_states, _ = self.norm(hidden_states, residual)
return hidden_states

Expand Down
11 changes: 10 additions & 1 deletion vllm/model_executor/models/qwen3_next_mtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
Qwen3NextModel,
Qwen3NextRMSNorm,
QwenNextMixtureOfExperts,
_all_gather_hidden_and_residual,
)
from vllm.sequence import IntermediateTensors
from vllm.transformers_utils.configs.qwen3_next import Qwen3NextConfig
Expand Down Expand Up @@ -130,7 +131,8 @@ def forward(
residual = intermediate_tensors["residual"]

current_step_idx = spec_step_idx % self.num_mtp_layers
hidden_states, residual = self.layers[current_step_idx](
mtp_layer = self.layers[current_step_idx]
hidden_states, residual = mtp_layer(
positions=positions,
hidden_states=hidden_states,
residual=residual,
Expand All @@ -141,6 +143,13 @@ def forward(
{"hidden_states": hidden_states, "residual": residual}
)

if mtp_layer.use_attn_reduce_scatter_for_moe:
hidden_states, residual = _all_gather_hidden_and_residual(
hidden_states,
residual,
positions.shape[-1],
self.config.hidden_size,
)
hidden_states, _ = self.norm(hidden_states, residual)
return hidden_states

Expand Down
Loading