6.1.5 · D1Scaling & Efficient Architectures

Foundations — Sparse routing and gating networks

2,295 words10 min readBack to topic

This page builds every symbol, word, and picture that the parent topic leans on. If the parent wrote , , , , or "load", and never stopped to explain it — we stop here. Read top to bottom; each block only uses symbols already earned above it.


0. The picture the whole topic lives inside

Figure — Sparse routing and gating networks

Look at the figure. On the left an input arrow enters a small box (the gating network). That box shines a spotlight on just 2 of the 8 tall boxes (the experts). Only the lit experts do work; the dark ones stay asleep. Their two outputs are blended and leave on the right.

Everything below is just: what is that arrow, what is that box, and how does the spotlight get decided.


1. A vector — the input

  • Plain words: a row of dials, each set to some value.
  • Picture: an arrow in space, OR simpler — a vertical stack of little number-boxes (see figure s02, leftmost column).
  • Why the topic needs it: every "token" flowing through a Transformer arrives as such a list of numbers. The gating network must read this list to make its decision.

The symbol means "all the real numbers" (any decimal, positive or negative). means " of them stacked". So reads: " lives in -dimensional real space."


2. A linear layer —

The parent writes . Let us earn every piece.

What "dotted" means — the dot product:

  • Plain words: multiply matching entries and add them all up — one number.
  • Why THIS tool? We need to turn a length- input into scores (one score per expert). A dot product is the simplest way to ask "how much does this input agree with this direction?" — big when input and row point the same way, negative when opposite. Each row of is a "taste profile" for one expert; the dot product measures how well the input matches that taste.
Figure — Sparse routing and gating networks

The figure shows the length- input becoming scores. The coral row of combines with the input to make score #2; a different row makes each other score.

Recall Why is a plain dot-product-plus-bias called "linear"?

Because doubling the input doubles the score (before the bias), and adding two inputs adds their scores. No curves, no thresholds — a straight-line relationship. ::: A straight-line relationship: scaling or adding inputs scales or adds outputs; the graph has no bends.

The word logits just means "raw scores, not yet turned into probabilities." They can be any size, positive or negative.


3. Turning scores into a choice — the softmax

The parent writes . Two new symbols: and .

  • Why THIS tool (why not just use the scores directly)? We want probabilities: numbers that are all positive and add to 1, so we can read them as "chance of picking this expert." Raw logits can be negative — you can't have a negative chance. fixes both problems: it makes every score positive, and it magnifies gaps (a slightly bigger logit becomes a much bigger weight), giving a confident-but-soft choice.
Figure — Sparse routing and gating networks

The figure shows the same 4 logits before and after softmax. Notice: the biggest logit (coral) grabs the biggest share, the negative logit still gets a small positive share, and the four output bars stack to height 1.

Recall Why must softmax outputs sum to 1?

Because the denominator is the sum of every numerator, so adding all the fractions puts the same total on top and bottom. ::: The denominator equals the sum of all numerators, so the fractions add to (total)/(total) = 1.

Because is smooth and the division is smooth, softmax is differentiable — that word is the next stop.


4. Differentiable, gradients, and backprop

The parent says softmax is chosen because it is "differentiable (enables backprop)." Let's ground that.

  • Picture: stand on a hillside (the loss surface). The gradient is the arrow pointing straight uphill; training walks the opposite way, downhill, to reduce error. See figure s04.
Figure — Sparse routing and gating networks
  • Why the topic cares: neural networks learn by backpropagation — sending "which way to nudge" signals backward through every operation. An operation with a jump or corner (like a hard "pick the top one") has no well-defined nudge there, so no signal passes. This is exactly why the parent's top- step is troublesome and why the auxiliary loss routes gradients through the smooth instead of the jumpy . Hold that thought for §7.

5. Picking the best few — and TopK

  • Picture: sort the bars from §3 tallest-first, keep the front , throw the rest to zero. This is a staircase decision — nudging a logit a hair usually changes nothing, until it crosses a neighbour and the choice snaps. That snap is the non-differentiable corner from §4.
Recall Why is TopK not differentiable?

Because its output stays flat as you nudge inputs, then jumps abruptly when the ranking flips — flat-then-jump has no smooth slope. ::: The selected set is constant under tiny nudges and jumps discontinuously when two scores swap order; no smooth gradient exists.


6. The indicator and counting load

The parent defines .

  • Why the topic needs it: to count how many tokens landed on expert , we tally a 1 each time that expert was chosen. Summing over the whole batch is literally "count the visits."
  • Note the trap: is a hard yes/no — it inherits the staircase problem. That is why load counting is a monitoring tool, not something you can backprop through directly.

7. Fractions , mean-probability , and why they differ

Now every symbol in the parent's balance loss is buildable:

Symbol Plain words Smooth? Built from
fraction of tokens that actually got sent to expert ❌ staircase §5 TopK + §6 indicator
average softmax probability the gate gave expert ✅ smooth §3 softmax
small dial (a chosen constant) scaling the penalty just a number
number of experts a count
  • Why two versions of "how busy is expert "? Because we need one to measure reality (, the true count) and one to push the gate (, the smooth thing gradients can travel through, from §4). The product multiplies "how overloaded it is" by "the knob we can turn," so training turns down the knob on the crowded experts.
Recall Why can gradients flow through

but not ? is an average of smooth softmax outputs (§3–4); counts TopK hits, a staircase with no slope (§5). ::: averages differentiable softmax values so it has a slope; counts discrete TopK selections which jump, so it has no usable gradient.


8. Big-O — reading the cost claims

The parent writes costs like .

  • Why it matters here: the headline of the whole topic is that active compute is — it depends on (a tiny constant like 1 or 2), not on , the total expert count. So you can pile on experts (grow total parameters) while per-token cost barely moves. That is conditional computation in one line. Here is just the hidden width of each expert's feed-forward network — another size number.

Prerequisite map

Vector x in R^d

Linear layer Wx plus b

Dot product

Logits raw scores

Exponential exp

Softmax

Sum symbol

Gate weights G of x

TopK selection

Differentiable and gradients

Auxiliary balance loss

Indicator 1 of condition

Load and fraction f

Mean probability P

Big O cost

Sublinear scaling

MoE layer


Equipment checklist

Cover each answer and see if you can state it before revealing.

means
an ordered list of real numbers — the input token, one number per feature.
is
a grid of numbers with rows and columns; each row is one expert's "taste profile."
The dot product computes
multiply matching entries and sum them — a single number measuring agreement between the row and the input.
always returns
a positive number; it grows fast and turns any logit into a positive weight.
Softmax guarantees its outputs
are each between 0 and 1 and sum to exactly 1 — a valid probability distribution.
"Differentiable" means
smooth, no jumps or corners, so you can always ask which way and how much to nudge (the gradient exists).
returns
the index (position) of the largest entry, not its value.
TopK is not differentiable because
its selection stays flat then snaps when the ranking flips — a staircase with no slope.
equals
1 if the condition is true, 0 if false — used to count expert visits.
versus
is the true fraction of tokens routed to expert (staircase, no gradient); is the mean softmax probability (smooth, carries gradients).
tells us
active compute scales with (tiny constant), not with — so total parameters can grow almost for free.