Routed output
×The weighted sum of the selected experts.
- shape
- [B batch, T positions, 7168 d]
Sources
Contextual evidence from Weighted expert sum
The MoE layer flattens positions into one token axis, hands them to the fused experts, which also run the router, and restores the shape.
deepseek_v2.py 411–434 ↗ · vllm-project/vllm @ 5df63a7203cd
Excerpt
def forward(
self,
hidden_states: torch.Tensor,
already_sequence_parallel: bool = False,
) -> torch.Tensor:
num_tokens, hidden_dim = hidden_states.shape
hidden_states = hidden_states.view(-1, hidden_dim)
# Chunk the hidden states so they aren't replicated across TP ranks.
# This avoids duplicate computation in self.experts.
if self.is_sequence_parallel and not already_sequence_parallel:
hidden_states = sequence_parallel_chunk(hidden_states)
final_hidden_states = self.experts(
hidden_states=hidden_states, router_logits=hidden_states
)
if self.is_sequence_parallel and not already_sequence_parallel:
final_hidden_states = tensor_model_parallel_all_gather(
final_hidden_states, 0
)
final_hidden_states = final_hidden_states[:num_tokens]
return final_hidden_states.view(num_tokens, hidden_dim)