Shared-expert gate
×One learned vector scores each position: one gate logit for the shared expert.
- in
- [B batch, 1 position, 8192 d]
- out
- [B batch, 1 position, 1 one]
Parameters8,192 × 69 layers
8,192 parameters per instance.
| Component | Parameters |
|---|---|
| Weight matrix | 8,192 |
This projection has no bias parameter.
The reference module holds the weight output by input, [out, in].
One in each of the 69 GDN layers, each with its own weights.
Sources
In codeself.shared_expert_gate(hidden_states_reshaped) · 905
Direct evidence
The MoE block holds the router, the experts, a shared expert of shared_expert_intermediate_size and a one-output shared-expert gate; the shared expert’s output is multiplied by the sigmoid of that gate and added to the experts’ output.
modeling_qwen3_5_moe.py 890–909 ↗ · huggingface/transformers @ 18329f106538
Excerpt
class Qwen3_5MoeSparseMoeBlock(nn.Module):
def __init__(self, config):
super().__init__()
self.gate = Qwen3_5MoeTopKRouter(config)
self.experts = Qwen3_5MoeExperts(config)
self.shared_expert = Qwen3_5MoeMLP(config, intermediate_size=config.shared_expert_intermediate_size)
self.shared_expert_gate = torch.nn.Linear(config.hidden_size, 1, bias=False)
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
batch_size, sequence_length, hidden_dim = hidden_states.shape
hidden_states_reshaped = hidden_states.view(-1, hidden_dim)
shared_expert_output = self.shared_expert(hidden_states_reshaped)
_, routing_weights, selected_experts = self.gate(hidden_states_reshaped)
expert_output = self.experts(hidden_states_reshaped, selected_experts, routing_weights)
shared_expert_output = F.sigmoid(self.shared_expert_gate(hidden_states_reshaped)) * shared_expert_output
expert_output = expert_output + shared_expert_output
expert_output = expert_output.reshape(batch_size, sequence_length, hidden_dim)
return expert_output