Router

Expert scores

×

One learned score vector and bias per expert: 128 scores per position.

z=xffnWr+br{\htmlData{light=logits scores}{z}}={\htmlData{light=input}{x_{\mathrm{ffn}}}}W_{r}+b_{r}
in
xffnx_{\mathrm{ffn}} [B batch, T positions, 2880 d]
out
zz [B batch, T positions, 128 experts]

A matrix of 128 × 2,880 and a bias of 128, bfloat16 (model.py 271–273).

Parameters368,768 × 18 layers

368,768 parameters per instance.

ComponentCalculationParameters
Weight matrix2,880 × 128368,640
Output bias128
Per-instance total368,768

The reference module holds the weight output by input, [out, in].

One in each of the 18 window layers, each with its own weights.

Sources

In codeself.gate(t) · 314

Open pinned code ↗

Direct evidence

The MLP block: an RMSNorm; a router, a linear map with bias from the width to 128 experts; per expert, a first matrix to twice the inner width with a bias, and a second matrix back to the width with a bias.

model.py 259–310 ↗ · openai/gpt-oss @ 5681a6b65526

Excerpt
class MLPBlock(torch.nn.Module):
    def __init__(
        self,
        config: ModelConfig,
        device: torch.device | None = None,
    ):
        super().__init__()
        self.num_experts = config.num_experts
        self.experts_per_token = config.experts_per_token
        self.swiglu_limit = config.swiglu_limit
        self.world_size = dist.get_world_size() if dist.is_initialized() else 1
        self.norm = RMSNorm(config.hidden_size, device=device)
        self.gate = torch.nn.Linear(
            config.hidden_size, config.num_experts, device=device, dtype=torch.bfloat16
        )
        assert config.intermediate_size % self.world_size == 0
        self.mlp1_weight = torch.nn.Parameter(
            torch.empty(
                (
                    config.num_experts,
                    config.intermediate_size * 2 // self.world_size,
                    config.hidden_size,
                ),
                device=device,
                dtype=torch.bfloat16,
            )
        )
        self.mlp1_bias = torch.nn.Parameter(
            torch.empty(
                (config.num_experts, config.intermediate_size * 2 // self.world_size),
                device=device,
                dtype=torch.bfloat16,
            )
        )
        self.mlp2_weight = torch.nn.Parameter(
            torch.empty(
                (
                    config.num_experts,
                    config.hidden_size,
                    config.intermediate_size // self.world_size,
                ),
                device=device,
                dtype=torch.bfloat16,
            )
        )
        self.mlp2_bias = torch.nn.Parameter(
            torch.empty(
                (config.num_experts, config.hidden_size),
                device=device,
                dtype=torch.bfloat16,
            )
        )

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