Global layer

Mixture of experts

×

Each position runs 4 of 128 routed experts, weighted by the router; there is no shared expert.

Δffn=∑i=1128Gi Ei\Delta_{\mathrm{ffn}}=\sum_{i=1}^{128}G_i\,E_i
All 14 steps
Router:\text{Router:}
z=xffnWr+brz=x_{\mathrm{ffn}}W_{r}+b_{r}
Eisel=[ i∈top⁡4(z) ]E^{\mathrm{sel}}_i=\big[\,i\in\operatorname{top}_{4}(z)\,\big]
Gi=ezi Eisel∑jezj EjselG_{i}=\frac{e^{z_i}\,E^{\mathrm{sel}}_i}{\sum_{j}e^{z_j}\,E^{\mathrm{sel}}_j}
Routed expert:\text{Routed expert:}
[ g  u ]=xffnW1,i+b1,i[\,g\;u\,]=x_{\mathrm{ffn}}W_{1,i}+b_{1,i}
g=[ g  u ]0,2,4,…g=[\,g\;u\,]_{0,2,4,\ldots}
u=[ g  u ]1,3,5,…u=[\,g\;u\,]_{1,3,5,\ldots}
gˉ=min⁡(g, 7)\bar g=\min(g,\,7)
uˉ=clip⁡(u, −7, 7)\bar u=\operatorname{clip}(u,\,-7,\,7)
a=gˉ σ(1.702 gˉ)a=\bar g\,\sigma(1.702\,\bar g)
y=a⊙(uˉ+1)y=a\odot(\bar u+1)
Ei=yW2,i+b2,iE_i=yW_{2,i}+b_{2,i}
Δffn=∑i=1128Gi Ei\Delta_{\mathrm{ffn}}=\sum_{i=1}^{128}G_i\,E_i
in
xffnx_{\mathrm{ffn}} [B batch, T positions, 2880 d]
out
Δffn\Delta_{\mathrm{ffn}} [B batch, T positions, 2880 d]
Parameters3,186,524,288 × 18 layers

3,186,524,288 parameters per instance, across its learned components

ComponentCalculationParameters
Router368,768
Routed expert24,891,840 × 1283,186,155,520
Per-instance total3,186,524,288

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

Explanation

Every layer has one; the model has no dense feed-forward layer (model.py 339–349).

Sources

In codeself.mlp · MLPBlock(config)

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

The configuration the reference implementation reads: 36 layers of width 2,880; 128 experts, 4 per token, each of 2,880 inner features; swiglu_limit 7.0; 64 query and 8 key–value heads of 64; a sliding window of 128; RoPE base 150,000 over an initial context of 4,096, scaled by 32 with NTK α 1 and β 32; a vocabulary of 201,088.

config.json 1 ↗ · openai/gpt-oss-120b @ b5c939de8f75

Excerpt
{"num_hidden_layers": 36, "num_experts": 128, "experts_per_token": 4, "vocab_size": 201088, "hidden_size": 2880, "intermediate_size": 2880, "swiglu_limit": 7.0, "head_dim": 64, "num_attention_heads": 64, "num_key_value_heads": 8, "sliding_window": 128, "initial_context_length": 4096, "rope_theta": 150000, "rope_scaling_factor": 32.0, "rope_ntk_alpha": 1, "rope_ntk_beta": 32}