■ Change #52 · wiki.edited
Mixture-of-experts routing: Normalize Markdown to canonical form
explainer.student
− **What it is for.** In a transformer language model most of the arithmetic sits in the feed-forward sub-layer of each block: two large matrix multiplications applied to every token (a token is a word piece, represented as a vector). Making the model "know more" usually means making these matrices bigger, and the cost per token grows with them. A mixture-of-experts (MoE) layer breaks that link: it keeps many smaller feed-forward networks, called *experts*, and sends each token through only a few of them.+ **What it is for.** In a transformer language model most of the arithmetic sits in the feed-forward sub-layer of each block: two large matrix multiplications applied to every token (a token is a word piece, represented as a vector). Making the model "know more" usually means making these matrices bigger, and the cost per token grows with them. A mixture-of-experts (MoE) layer breaks that link: it keeps many smaller feed-forward networks, called _experts_, and sends each token through only a few of them.**An analogy.** Think of a hospital with 64 specialists and a triage nurse. Each patient sees only the two most relevant specialists, so the hospital's total expertise grows with the number of specialists while each visit costs the same. The analogy breaks in one important way: the nurse (the router) and the specialists are trained together from scratch, so nobody decides in advance what each expert is for.**The mechanism.** The router is a small matrix $W_r$. For a token vector $x$ it computes one score per expert, $s = W_r x$, turns the scores into positive weights that add to one with the softmax function ($p_i = e^{s_i} / \sum_j e^{s_j}$, which exaggerates the largest scores), keeps the top $k$ experts, and outputs− $$y = \sum_{i \in \text{top-}k} p_i \, E_i(x),$$+ $y = \sum_{i \in \text{top-}k} p_i \, E_i(x),$the weighted sum of the chosen experts' outputs $E_i(x)$. With 64 experts and $k = 2$, the layer holds 64 experts' worth of parameters but each token pays for only 2.**The hard part: load balance.** Training nudges the router toward experts that already help, so a few experts can end up taking almost every token while the rest stay untrained. When experts live on different GPUs, the busiest one also makes every other GPU wait. Three families of fixes exist:− - an *auxiliary loss*, an extra penalty added to the training error that grows when the load is uneven; it works but pulls the model away from its real objective;− - *expert-choice routing*, where each expert picks its tokens, so loads are equal by construction;− - *auxiliary-loss-free balancing*, used in DeepSeek-V3: add a per-expert bias to the scores and nudge it up for under-used experts and down for over-used ones, like a thermostat.+ - an _auxiliary loss_, an extra penalty added to the training error that grows when the load is uneven; it works but pulls the model away from its real objective;+ - _expert-choice routing_, where each expert picks its tokens, so loads are equal by construction;+ - _auxiliary-loss-free balancing_, used in DeepSeek-V3: add a per-expert bias to the scores and nudge it up for under-used experts and down for over-used ones, like a thermostat.**Costs and open questions.** Moving tokens to experts on other GPUs needs all-to-all communication, and each expert gets a different number of tokens, which needs special matrix-multiply kernels. Which balancing method is best for the largest models is not settled in public: the controlled comparisons were run on models of a few billion parameters, and large technical reports describe one choice without a side-by-side test. How to scale the number and size of experts with the compute budget is studied by MoE scaling laws.
hash 66e650ffd7092eebb85fb599481e2f64e409f67084152aa9a4fdaa8e9ac5fd61
previous e727f898541788eb296ddc63e399bacc9e2d7625cd77645f398a8e8f21501ac5