A mixture of experts keeps many feed-forward layers and sends each token through only a few. DeepSeek-V3 holds 671 billion weights but uses about 37 billion for each token. The weights grow with the number of experts; the compute grows only with the number each token visits.
Pick a model and press Next token. Watch the router light a few experts out of many, and compare the two bars. Then we build the layer piece by piece: the router, the balance loss, the seat limit, the network traffic, and the tricks that keep training stable.
You need a feed-forward layer (the SwiGLU layer from Lecture 3) and parameter counting from Lecture 2. We build the rest from zero.
Lecture 4 of Stanford CS336, Language Modeling from Scratch (Spring 2025, Percy Liang and Tatsunori Hashimoto; this lecture by Tatsunori Hashimoto). Previous: Lecture 3, Architectures and Hyperparameters. Next: Lecture 5, GPUs.
Counts are ours, from each model's published config (bf16 is 2 bytes a weight). Mixtral reports 47B and 13B; DeepSeek reports 671B and 37B. Which experts each token picks is illustrative.
Chapter 0
See why a dense layer ties its size to its cost, and how experts cut the tie
More weights make a better language model (the scaling laws of Lecture 9). But in a dense layer every token multiplies through every weight. Double the weights and you double the work for every token.
Take one feed-forward layer at Mixtral's width. It reads a vector of width d = 4,096, widens it to 14,336 and narrows it back, with three matrices (SwiGLU). That is 176 million weights. One multiply and one add are 2 FLOPs, so each token costs 352 million FLOPs here.
A mixture of experts (MoE) keeps N copies of that layer, each with its own weights. Each copy is an expert. A small router sends each token to only k of them. Call the weights of one expert Pe. Then:
W equals N times P-e, and C equals two times k times P-e.
Memory pays for all N experts. Each token pays for only k of them, at 2 FLOPs per weight. N and k are separate knobs.
Mixtral: N = 8, k = 2. W = 8 × 176 million = 1.41 billion weights. C = 2 × 2 × 176 million = 705 million FLOPs. A dense layer with 1.41 billion weights would cost 2.82 billion FLOPs a token, 4 times more.
The grey line is a dense layer: grow it and the cost grows too. The purple dot is an expert layer with the same weights. Drag the size and pick k.
One expert = one SwiGLU layer at Mixtral's size (176 million weights). The dense line grows one layer's hidden width instead. The router's cost is left out: 2 × 4,096 × N FLOPs, under 0.1% here.
Does it pay? The lecture shows three results. The Switch Transformer reached a T5 model's quality up to 7 times faster at the same compute per token. OLMoE matched its dense twin with about 3 times fewer tokens, about 2 times faster in wall-clock time. Mixtral uses 13 billion active weights; its paper reports that it matches or beats Llama 2 70B on every benchmark it tested.
The idea dates to Jacobs, Jordan, Nowlan and Hinton (1991). Shazeer et al. (2017) put up to 137 billion weights into one MoE layer. The lecture names two costs: complex systems work, and training heuristics that can be unstable.
Symptom: the MoE trains on your budget, then does not fit on the GPUs you planned for serving.
Measure: count every expert. Mixtral holds 46.7 billion weights, 93 GB in bf16. Its dense twin, Mistral 7B, holds 14.5 GB.
Fix: plan memory for all N experts, and spread them over GPUs (Chapter 5).
Chapter 1
Replace the feed-forward layer with N experts, and let a small linear layer pick which ones each token uses
A Transformer block has attention, then a feed-forward layer. An MoE keeps attention as it is and swaps the feed-forward layer for N experts. Each expert is an ordinary SwiGLU layer with its own weights.
Why there? A feed-forward layer is position-wise: each token's output depends only on that token's vector. So two tokens can go to two different experts with no coordination. Attention mixes tokens, so splitting it is harder. MoE attention exists (ModuleFormer, JetMoE), but the lecture calls it less common.
The router is one matrix, Wr, of size d by N. It turns the token's vector x into N scores. Call the k chosen experts TopK, expert i's output Ei(x), and its gate (its weight in the mix) gi. The layer's output is:
y equals the sum over i in TopK of g-i times E-i of x.
Score all N experts with W-r. Keep the k best. Run x through those k experts only. Scale each output by its gate g-i and add them up.
Mixtral: x has 4,096 numbers. W-r is 4,096 by 8, so 32,768 weights and 65,536 FLOPs per token. The two chosen experts cost 2 × 352 million = 705 million FLOPs. The router is 0.009% of the layer's work.
The full pass is drawn. Press Start over, then Step through it one stage at a time, with each tensor shape.
Shapes and FLOPs are Mixtral's (d = 4,096, expert width 14,336, 8 experts, top 2). The scores are illustrative random numbers; the device computes the gates from them.
Not every layer needs experts. Mixtral uses an MoE in all 32 layers. DeepSeek-V3 keeps its first 3 layers dense and uses experts in the other 58. Llama 4 Maverick alternates: 24 dense layers and 24 MoE layers.
Symptom: a naive MoE runs out of memory at a tiny batch.
Measure: look for code that gathers each token's expert weights, w1[expert_idx]. At Mixtral's size that copies 117 MB of one matrix for every token.
Fix: sort tokens by expert and run one matrix product per expert, or use a grouped kernel such as MegaBlocks.
Chapter 2
Turn scores into gate weights, and see why the order of softmax and top-k matters
The router multiplies x by Wr and gets one score per expert, a logit. The k largest logits choose the experts. Then the router turns the chosen logits into gates. The lecture calls this the "token chooses expert" pattern; almost every MoE uses it.
Models differ in one detail: the order. Call expert i's logit li. Mixtral and DBRX keep the top k logits and take a softmax over those k alone (Shazeer et al. did the same in 2017):
g-i equals e to the l-i, divided by the sum over j in TopK of e to the l-j.
Pick the k largest logits. Exponentiate each one. Divide each by their total. The losers get no gate and no say in the gates.
With made-up logits [2, 1, 0.5, −1] and k = 2: e2 = 7.389 and e1 = 2.718. g = 7.389 / 10.107 = 0.731 and 0.269. A softmax over all four first gives 0.610 and 0.224, which sum to only 0.834.
Left: the four logits. Right: the gates of the chosen experts. Drag expert 2's score, change the order and change k.
Illustrative logits [2, l2, 0.5, −1]. DeepSeek-V3 scores each expert with a sigmoid, 1 / (1 + e−l), then divides the chosen scores by their sum.
The choice of the top k has no gradient: a tiny change in a logit either flips the choice or does nothing. The router learns only through the gates of the experts it chose. If expert 1 helped, the loss pushes its gate up, so its logit rises.
Other routers exist. Hashing sends each token by a fixed rule. Reinforcement learning works (Clark et al. 2020) but is not a clear win, given its noisy gradients. Expert choice (Zhou et al. 2022) lets each expert pick its tokens, which balances load by construction. Shazeer et al. (2017) added Gaussian noise to the logits; the Switch Transformer used a random multiplicative jitter, which ST-MoE later removed.
Symptom: with k = 1, the router's weights never change.
Measure: log the gradient of Wr. With top-k then softmax and k = 1, the gate is always exactly 1, so the loss cannot reach the router.
Fix: for k = 1, take the softmax over all N first, as the Switch Transformer does. The gate pi then carries a gradient.
Chapter 3
Watch the router send everything to one expert, then add the penalty that spreads the load
Training has a loop. An expert that is a little better early gets more tokens, trains faster, and gets better still. Soon it takes almost every token. This is expert collapse: you pay memory for N experts and train one, and one GPU does all the work.
The Switch Transformer's fix is an extra loss. For each expert i, over a batch of T tokens, count two things. fi is the fraction of tokens whose top choice is expert i. Pi is the router's average probability for expert i. Add this to the training loss:
L-bal equals alpha times N times the sum over i of f-i times P-i.
Multiply each expert's token share f-i by its average probability P-i. Add the products, then multiply by N and alpha. The gradient on P-i is alpha N f-i, so the busiest expert gets the strongest push down.
With made-up numbers, N = 4, f = [0.5, 0.3, 0.1, 0.1], P = [0.4, 0.3, 0.2, 0.1], alpha = 0.01: the sum is 0.32, so L-bal = 0.0128. Perfect balance gives 0.01; full collapse gives 0.04. The push on expert 1 is 0.02; on experts 3 and 4 it is 0.004.
Why is balance the minimum? When f matches P, the sum is the sum of Pi squared. For N shares that add to 1, that is at least 1/N, with equality only at 1/N each.
Bars: each expert's share of the batch. Yellow: the fair share, 1/8. Bottom: N × Σ f P over training (1 is balanced, 8 is collapsed). Train once with the loss off, then on.
Illustrative toy, trained live in your browser: 2-D tokens from 4 clusters, a linear router, 8 experts, top 1. Each expert's loss falls as it trains: the rich-get-richer loop. alpha = 1 in toy units. A Python copy gives the same picture on every seed; exact shares vary a little by browser, because the run is chaotic.
DeepSeek V1 and V2 add a second loss that balances whole GPUs. V3 is mostly auxiliary-loss-free: each expert gets a bias that V3 adds to its score for the choice only, never to its gate. After each step, an overloaded expert's bias drops by γ and an underloaded one's rises by γ (γ = 0.001 for 14.3 trillion tokens). A tiny sequence-level loss stays, with alpha = 0.0001.
Symptom: the loss looks fine, but a few experts take most tokens and most GPUs idle.
Measure: log each layer's token shares f every few hundred steps, and N × Σ f P.
Fix: add the balance loss at about 0.01, or a per-expert routing bias. OLMoE without the loss sent most tokens to a few experts.
Chapter 4
Give each expert a buffer sized before routing, and decide what happens to the tokens that do not fit
Even a balanced router is uneven batch to batch. But accelerators want shapes fixed before the batch arrives. So each expert gets a fixed buffer of seats, its expert capacity. A capacity factor sets the headroom above a fair share.
Call the tokens in the batch T, the experts N, the experts per token k and the capacity factor C. Each expert gets:
Seats equals C times k times T, divided by N.
Count the seat requests, k times T. Split them evenly over N experts. Multiply by C for headroom. A full expert drops every token that arrives after its seats are gone.
T = 512, N = 8, k = 1, C = 1.25: seats = 1.25 × 512 / 8 = 80. If expert 1 receives 95 tokens, it drops 15. With C = 1.0, seats = 64 and our example batch drops 37 tokens, 7.2%.
Each column is one expert. Warm: tokens that got a seat. Red: dropped tokens. Blue outline: empty seats that still cost compute. Drag C.
The example batch is made up: loads [95, 70, 64, 58, 61, 52, 60, 52]. New batch draws 512 tokens from a random uneven router. k = 1, as in the Switch Transformer.
A dropped token is not lost. It skips the expert, and the residual connection carries its vector to the next layer unchanged (Switch Transformer, GShard). Raising C drops less but pays for empty seats: at C = 1.5 the example batch drops nothing, but 256 of 768 seats are padding.
Seats fill per batch, so other people's requests can drop your token. The lecture notes this as one guess for why GPT-4's outputs varied run to run. ST-MoE found that dropping up to 10 to 15% of tokens did not materially hurt fine-tuning. DeepSeek-V3 drops no tokens in training or inference, and OLMoE uses a dropless kernel.
Symptom: the same prompt gives different answers depending on what else is in the batch.
Measure: count dropped tokens per expert per batch at inference.
Fix: raise C for serving, or use a dropless kernel that sizes each expert's work to its real load.
Chapter 5
Put different experts on different GPUs, and count the bytes each token sends to reach them
DeepSeek-V3's weights take 1.3 TB in bf16, far more than one GPU holds. The lecture's answer is a new kind of parallelism. Expert parallelism places whole experts on different GPUs. Each GPU holds a few experts and a slice of the batch.
Every MoE layer then needs two exchanges between all GPUs, called all-to-all. Dispatch sends each token's vector to the GPUs of its k experts. Combine sends the k results back. Call the width d and the bytes per number b. One token, in one MoE layer, moves:
Bytes equals two times k times d times b.
Copy the token's vector once for each of its k experts. Send the copies out, and get k results of the same size back.
DeepSeek-V3 in bf16: 2 × 8 × 7,168 × 2 = 229,376 bytes, about 229 kB per token per layer. For one 4,096-token sequence through 58 MoE layers, that is 54.5 GB. Mixtral: 2 × 2 × 4,096 × 2 = 32.8 kB.
Eight nodes, four experts each. The token starts on node 0. Each blue line is one copy sent between nodes. Press Next token a few times, then switch on the node limit.
Illustrative: random router scores, 32 experts, top 8, width 7,168 in bf16. A token sends one copy to each remote node, which forwards it inside the node, as DeepSeek-V3 does. Over 20,000 random tokens a Python copy averages 5.6 nodes free and 4.0 with the limit.
Between nodes the network is slow. DeepSeek-V3's cluster has NVLink inside a node at 160 GB/s and InfiniBand between nodes at 50 GB/s, 3.2 times slower. Cross-node expert parallelism made its compute to communication ratio about 1 to 1. So V3 limits each token to at most 4 nodes, picked by the best expert scores on each node. It also overlaps the exchanges with computation (its DualPipe schedule).
Symptom: GPUs sit idle during every MoE layer.
Measure: time the all-to-all against the expert matrix products.
Fix: limit the nodes per token, overlap communication with compute, and keep experts that talk often on the same node.
Chapter 6
Cut each expert into smaller pieces, route to more of them, and keep one expert that every token visits
DeepSeekMoE (Dai et al. 2024) made two changes that many recent models copy. The first is fine-grained experts: cut each expert into m smaller experts of width de/m. Then route each token to m times as many. The weights and the FLOPs stay the same. What grows is the number of ways to mix experts.
Count the mixes. A token picks mk experts out of mN. The number of possible sets is:
Combos equals m-N choose m-k.
"Choose" counts the ways to pick mk items from mN when order does not matter. Multiply mN, mN − 1, and so on, for mk terms. Divide by 1 × 2 × … × mk.
DeepSeekMoE's own example: N = 16, k = 2 gives 120 sets. Cut each expert into m = 4: 64 choose 8 = 4,426,165,368 sets, for the same weights and FLOPs.
The block is one layer's expert weights. Lit pieces are what one token uses. Drag the cut; switch on a shared expert.
Illustrative layer: 16 experts, top 2, at OLMoE's width (d = 2,048, expert width 8,192 before the cut). As in DeepSeekMoE, a shared piece replaces one routed piece, so the compute stays the same.
The second change is shared experts: a few experts that every token visits, plus the routed ones. The idea is that common knowledge should not take a routed slot. DeepSeekMoE 16B uses 2 shared and 64 routed experts with 6 active: 16.4 billion weights, 2.8 billion active. DeepSeek-V3 uses 1 shared and 256 routed experts with 8 active, each only 2,048 wide (0.29 d).
The evidence is mixed. DeepSeek's ablations found that more experts and shared experts both help. OLMoE found gains from fine-grained experts and none from shared ones.
| Model | Routed | Active | Shared | Fine-grained ratio |
|---|---|---|---|---|
| Switch Transformer | 64 | 1 | 0 | 1 |
| Mixtral | 8 | 2 | 0 | 1 |
| DBRX | 16 | 4 | 0 | 1 |
| DeepSeek V1 | 64 | 6 | 2 | 1/4 |
| Qwen 1.5 | 60 | 4 | 4 | 1/8 |
| OLMoE | 64 | 8 | 0 | 1/8 |
| DeepSeek-V3 | 256 | 8 | 1 | 1/14 |
| Llama 4 Maverick | 128 | 1 | 1 | 1/2 |
From the lecture's table. The ratio is an expert's size against a standard feed-forward layer, as the lecture lists it; for DeepSeek-V3, 2,048 / (4 × 7,168) = 1/14.
Symptom: finer experts did not help, and each step got slower.
Measure: the size of each expert's matrix product and the all-to-all bytes. At m = 4 a token sends 8 copies instead of 2: 4 times the traffic of Chapter 5.
Fix: stop cutting when expert matrices get too small to keep the GPU busy, or when traffic dominates.
Chapter 7
Find why the router's softmax breaks in bf16, and pin its logits near zero
MoE runs are prone to loss spikes. The router is a softmax, and a softmax exponentiates. In bf16, a number keeps only 8 significant bits. Near 100, the gap between two numbers bf16 can store is 0.5. An error of 0.25 in one logit multiplies its exponential by e0.25 = 1.28.
The Switch Transformer's fix is selective precision: compute the router in float32 and keep everything else in bf16. In its test, bf16 training diverged. The float32 router matched full float32 quality at bf16 speed, 1,390 examples a second against 1,160.
ST-MoE (Zoph et al. 2022) added the router z-loss, which keeps the logits small. Call token t's logit for expert i lt,i and the tokens in the batch T:
L-z equals one over T times the sum over t of: the log of the sum over i of e to the l-t-i, squared.
For each token, compute log Z from its router logits. Square it. Average over the batch. The gradient on each logit is 2 × 0.001 × log Z × its probability, so the z-loss pulls every logit down, the largest most.
With made-up logits [2, 1, 0.5, −1]: log Z = 2.495, squared 6.23, times 0.001 = 0.0062. Add 20 to every logit: the probabilities do not change, but log Z = 22.5 and the z-loss is 0.506.
Outlines: the true probabilities. Filled bars: what a bf16 router computes. Drag the logits up, then switch on the float32 router.
Illustrative logits [0.3, 0.1, −0.3, −0.6] plus the shift, rounded to bf16 by round-to-nearest-even, as PyTorch does. The z-loss weight is 0.001.
This is the same z-loss Lecture 3 used on the output softmax, now on the router. The lecture shows OLMoE's runs with and without it, at weight 0.001: without it the loss spikes again and again. ST-MoE reports that the z-loss stabilized training with no quality loss, and a slight gain.
Symptom: loss spikes that get worse as the model grows.
Measure: log the router's largest logit and log Z per layer, and check the router's dtype.
Fix: cast the router to float32 and add the z-loss with weight 0.001.
Chapter 8
Keep a sparse model from overfitting, and build one from a dense checkpoint you already paid for
Sparse models overfit small fine-tuning sets. ST-MoE's fix is to fine-tune only part of the model. Updating only the non-MoE weights worked about as well as updating all of them. Updating only the expert weights, about 80% of the model, hurt quality badly. DeepSeek took the other route: more data, 1.4 million fine-tuning examples for DeepSeekMoE 16B.
Training a large MoE from scratch is expensive. Sparse upcycling (Komatsuzaki et al. 2022) starts from a trained dense model. Copy its feed-forward layer into every expert, add a new router, and keep training. What does the new layer compute at step 0? Every expert is the same function, call it E, so:
y equals the sum over i in TopK of g-i times E of x, which equals the sum of the gates, times E of x.
All chosen experts give the same answer E(x), so the weighted sum is E(x) scaled by the sum of the gates. If the gates sum to 1, the new layer starts as the dense layer exactly.
Our PyTorch check, 8 copies, top 2, five random tokens: with top-k then softmax, the largest gap from the dense output is 0.00003 (float rounding). With softmax first, the gates sum to 0.78 to 0.93, and each output shrinks by that factor.
Outlines: the dense layer's output for one token. Filled bars: the upcycled MoE's output at step 0. Change the gate order and k.
Illustrative: a SwiGLU layer of width 8 and hidden width 16 with random weights, copied into 8 experts; a random new router. Computed live in your browser.
Starting equal to the dense model is not automatically better. Komatsuzaki et al. tried normalizing the gates to sum to 1: it helped their vision models and hurt their language models. Their upcycled T5 and ViT models beat the dense originals with extra training worth about half of the original run. The lecture's examples are MiniCPM's MoE (8 experts, top 2, about 4 billion active) and Qwen1.5-MoE, built from Qwen 1.8B. OLMoE found upcycling helps only at small compute budgets.
Symptom: the loss jumps at the first step after upcycling.
Measure: run the dense model and the upcycled model on one batch and compare their outputs.
Fix: check the gate order and the sum of the gates; if they sum to less than 1, the layer's output has shrunk.
Chapter 9
Load a published config, then turn the expert count, k, shared experts and width, and watch every count move
Every formula of the lesson in one counter. Load a preset and check the totals against the published sizes. Then change one knob and predict which bar moves before you look.
Top: weights held and weights used per token, by part. Bottom: weights in GB against one 80 GB GPU, and the bytes one token sends per MoE layer. Load a preset, then drag.
Per layer: attention (from the config), the feed-forward weights (3 × d × width per expert), the router (N × d) and 2 norms. Then embeddings (2 × vocabulary × d) and a final norm. A preset's own shared-expert width holds until you drag the width. bf16 for weights and traffic.
Things to try. Load DeepSeek-V3 and set k from 8 to 1: active weights fall from 37.6 to 19.7 billion, and the total does not move. Load Mixtral and raise N to 64: 362 billion weights, still 12.9 billion active. Load Llama 4 Maverick: only 1 routed expert per token, so it uses 4.3% of what it holds.
Check yourself. Without the counter, estimate Mixtral's active weights: 32 layers × (42 million of attention + 2 × 176 million of experts) plus 0.26 billion of embeddings. That is 12.9 billion.
Chapter 10
Keep the design table, the layer in code, and the checks that catch a sick MoE
An MoE swaps the feed-forward layer for N experts and a router that picks k. Memory pays for N, compute for k.
The rest keeps that trade healthy. A balance loss or bias stops collapse. A capacity rule gives fixed shapes. Node limits cap the traffic. A float32 router and a z-loss stop spikes.
| Decision | Common choice | Why | Exceptions |
|---|---|---|---|
| Where the experts go | the feed-forward layer | it acts on each token alone | MoE attention (ModuleFormer, JetMoE); dense first layers (DeepSeek-V3: 3) |
| Routing | token choice, top k | simple; trains through the gates | hashing, RL, expert choice |
| k | 2 to 8 | k sets the compute per token | 1 (Switch, Llama 4 Maverick) |
| Gate order | top-k, then softmax | gates sum to 1 | softmax first (Switch, DeepSeek V1 and V2); sigmoid (V3) |
| Balance | αN Σ fiPi, α about 0.01 | stops collapse, keeps GPUs busy | DeepSeek-V3: bias update plus a tiny sequence loss |
| Capacity | C about 1.0 to 1.25, drops pass through | fixed shapes | dropless kernels (MegaBlocks, OLMoE); DeepSeek-V3 drops none |
| Granularity | many small experts | more mixes, same FLOPs | Mixtral, DBRX: full-size experts |
| Shared experts | 0 to 2 | common knowledge off the routed slots | OLMoE saw no gain |
| Stability | float32 router, z-loss 0.001 | the router softmax is fragile in bf16 | none in the lecture's examples |
The layer in code: a float32 router, top-k then softmax, the balance loss and the z-loss, and one matrix product per expert. We ran it: the output shape is (2, 16, 64), the balance loss is 0.0102 and the z-loss is 0.0053 for these random weights. It matches a slow loop over tokens to 7 × 10−7.
python import torch, torch.nn as nn, torch.nn.functional as F class MoE(nn.Module): def __init__(self, d, d_e, n_exp, k, alpha=0.01, c_z=1e-3): super().__init__() self.k, self.n, self.alpha, self.c_z = k, n_exp, alpha, c_z self.router = nn.Linear(d, n_exp, bias=False) self.w1 = nn.Parameter(torch.randn(n_exp, d, d_e) * d ** -0.5) # gate branch, through Swish self.v = nn.Parameter(torch.randn(n_exp, d, d_e) * d ** -0.5) # linear branch self.w2 = nn.Parameter(torch.randn(n_exp, d_e, d) * d_e ** -0.5) def forward(self, x): # x: (B, T, d) B, T, d = x.shape x = x.reshape(-1, d) # (B*T, d): experts act per token logits = self.router(x.float()) # router in float32: (B*T, N) top_l, top_i = logits.topk(self.k, dim=-1) # (B*T, k) gates = F.softmax(top_l, dim=-1).to(x.dtype) # top-k, then softmax: sum to 1 probs = F.softmax(logits, dim=-1) # for the balance loss f = F.one_hot(top_i[:, 0], self.n).float().mean(0) # share of tokens, top choice (no gradient) P = probs.mean(0) # mean probability (has a gradient) l_bal = self.alpha * self.n * (f * P).sum() l_z = self.c_z * torch.logsumexp(logits, -1).pow(2).mean() # router z-loss y = torch.zeros_like(x) for e in range(self.n): # one matrix product per expert tok, slot = (top_i == e).nonzero(as_tuple=True) # which tokens chose e, in which slot if tok.numel() == 0: continue h = x[tok] out = (F.silu(h @ self.w1[e]) * (h @ self.v[e])) @ self.w2[e] y.index_add_(0, tok, gates[tok, slot, None] * out) return y.reshape(B, T, d), l_bal + l_z torch.manual_seed(0) moe = MoE(d=64, d_e=128, n_exp=8, k=2) y, aux = moe(torch.randn(2, 16, 64)) print(y.shape, round(aux.item(), 5)) # torch.Size([2, 16, 64]) 0.01546
Now teach it: press Present or Teach. Explain why the weights and the compute come apart, how the balance loss pushes on the busiest expert, and what happens to a token that finds its expert full. Then go back to the router and predict the two bars before you pick a model.