Router

Softmax over the 4

×

Turn the 4 chosen scores into weights that sum to one.

Gi=ezi Eisel∑jezj Ejsel{\htmlData{light=output normalize}{G_{i}}}=\frac{e^{z_i}\,{\htmlData{light=selected select}{E^{\mathrm{sel}}_i}}}{\sum_{j}e^{z_j}\,{\htmlData{light=selected select}{E^{\mathrm{sel}}_j}}}
in
zz [B batch, T positions, 128 experts]EselE^{\mathrm{sel}} [B batch, T positions, 128 experts]
out
GG [B batch, T positions, 128 experts]
Explanation

Unselected experts get weight zero, so each position’s weights sum to one.

Sources

In codetorch.nn.functional.softmax(experts.values, dim=1) · 316

Open pinned code ↗

Direct evidence

The MLP block’s forward: normalise; score the experts; take the 4 highest scores and their experts; softmax over those 4; run each chosen expert’s first matrix and bias, the activation, its second matrix and bias; sum the 4 outputs by their weights; add to the block’s input.

model.py 312–336 ↗ · openai/gpt-oss @ 5681a6b65526

Excerpt
    def forward(self, x: torch.Tensor) -> torch.Tensor:
        t = self.norm(x)
        g = self.gate(t)
        experts = torch.topk(g, k=self.experts_per_token, dim=-1, sorted=True)
        expert_weights = torch.nn.functional.softmax(experts.values, dim=1)
        expert_indices = experts.indices

        # MLP #1
        mlp1_weight = self.mlp1_weight[expert_indices, ...]
        mlp1_bias = self.mlp1_bias[expert_indices, ...]
        t = torch.einsum("beck,bk->bec", mlp1_weight, t) + mlp1_bias
        t = swiglu(t, limit=self.swiglu_limit)

        # MLP #2
        mlp2_weight = self.mlp2_weight[expert_indices, ...]
        mlp2_bias = self.mlp2_bias[expert_indices, ...]
        t = torch.einsum("beck,bek->bec", mlp2_weight, t)
        if self.world_size > 1:
            dist.all_reduce(t, op=dist.ReduceOp.SUM)
        t += mlp2_bias

        # Weighted sum of experts
        t = torch.einsum("bec,be->bc", t, expert_weights)

        return x + t