05 · Mixture of Experts
Fixed Buffers, Dropped Tokens
The hardware wants a rectangle, and the router does not produce one.
Everything so far has been about one token. One token has a router,
The difficulty is not the mathematics. It is that the router produces a different number of tokens for each expert, on every step, and the hardware underneath wants a rectangle whose size was fixed before the step began.
The shrinking batch
Start with a problem that appears before any hardware does. A dense layer trained on a batch of
and that is if the routing is perfectly even, which it is not. The original paper calls this the shrinking batch problem, and the arithmetic is unkind: every expert you add makes every expert worse informed.
The standard answer is to make the batch bigger, which is why sparse models are trained with data and model parallelism together: split the batch across
Capacity
An accelerator wants to do the same operation on a fixed-size block of data. The memory has to be allocated before the routing is known, so each expert is given a buffer with room for a fixed number of tokens, decided in advance. That number is the expert capacity:
is the number of tokens in the batch, or in the group, and the number of experts. is the capacity factor, the slack we allow. gives each expert exactly its even share. ST-MoE recommends during training and at evaluation.
The capacity factor is the price of imbalance, paid in advance and in full. At
GShard adds a wrinkle worth knowing about, because it changes what balance even means. Rather than one capacity for the whole batch, it partitions the tokens into
What happens to a dropped token
When more tokens choose an expert than its buffer can hold, the surplus is dropped. The word is exact. The computation is skipped, and the token's representation is passed straight to the next layer through the residual connection, unchanged.
It is worth being clear about what that means, because "dropped" sounds like a failure and it is really a silent no-op. Nothing errors. The loss does not spike. That token simply did not receive a feed-forward block at that layer, and if it happens at every layer the token passes through the whole model untouched by any expert.
That figure is the argument for the whole of the next page. Nothing was over capacity on average, and a quarter of the batch was still thrown away, because the tokens went where the router sent them and the router had no reason to spread them out.
The loss now depends on the batch
One consequence deserves stating on its own, because it breaks an assumption every other part of the model is built on.
In a dense network, a sample's forward pass does not depend on which other samples it was batched with. The batch is a convenience for the hardware. Once capacity exists, that is no longer true: whether a token is processed by its expert or dropped depends on how many other tokens in its group chose the same expert. Reshuffle the batch and the same token gets a different answer.
Three things follow, and all of them are the price of the same fact.
- Training is no longer deterministic in the usual way. Two runs that differ only in batch composition compute different functions of the same token.
- Evaluation is not the same operation as training. Serving one sequence at a time changes the group, so the field raises the capacity factor at evaluation rather than leave it alone.
- The cheapest fix is to make imbalance unlikely. If the routing is close to even, the buffers are close to full, few tokens are dropped, and
can stay near one.
The third is the one the field took. It is not a fix to the routing mechanism, which is untouched, and it is not a fix to the objective, which still does not care. It is an extra term in the loss whose only job is to make the histogram flat, and it is the next page.