What it is used for

Mixture of experts is used to enlarge the capacity of language models and translation models. Its founding paper applied it to language modeling and machine translation, two tasks that in its authors' account badly need large capacity to absorb knowledge from very large training text collections. The result stated by that paper was quality significantly better than the state of the art of its time, at lower computational cost.

Its best known present day form is the sparsely activated language model: most of the model's parameters sit idle for every word processed, and only a small slice of them works. That way one model can store knowledge equal to a much larger model, while the speed of processing each word stays close to that of a small model. Named models that use this approach are proven in the Real examples chapter below.

How to use it

End users do not install mixture of experts as a separate product; the approach lives inside the models they use, for example an openly released language model. What users can recognize from the outside is its consequence: a model with a very large total parameter count can answer at the speed of a much smaller model, because for each word only some of its experts work.

For model builders, using it means replacing an ordinary feed forward layer in the network with a mixture of experts layer. Another small network, the gating network, also called the router, inspects the input and chooses which experts switch on for that input. The chosen experts process the input, and their outputs are combined according to the weights the gating network assigns. Training trains the experts and their gating network together, so the experts slowly divide the territory among themselves.

Real examples

The following examples are not invented for this article. All three are recorded in primary papers written by their own researchers.

The first example is the experiment in the founding paper itself, from 2017. On a language modeling task with a text collection of about 100 billion words, its authors raised the number of experts layer by layer up to 131,072 experts, equal to 137 billion parameters in that layer. Model quality improved up to 65,536 experts, or 68 billion parameters, with word prediction error, called perplexity, dropping 39 percent lower than a computationally matched comparison model; at 131,072 experts the quality fell again. On the WMT 2014 translation task, their model reached BLEU scores of 40.56 for English to French and 26.03 for English to German, respectively 1.34 and 1.12 points above the strong comparison models of the time. The same paper also records that on another language modeling benchmark, its fastest model beat the best previously published result while using only 6 percent of its computation.

The second example is the Switch Transformer, reported by William Fedus, Barret Zoph, and Noam Shazeer in 2021. They simplified mixture of experts routing so that each input only needs to be sent to a single top expert, and with that simplification they trained models as large as one trillion parameters. Their paper's abstract states that their models achieved up to 7x increases in pre training speed with the same computational resources, and that its largest model ran 4x faster than the T5-XXL model.

The third example is Mixtral 8x7B, a mixture of experts language model reported by Albert Q. Jiang and colleagues in 2024. Each of its layers is composed of 8 feedforward blocks, that is 8 experts, and for every token, the unit of text the model processes, a router network selects two experts to process it. Its paper's abstract states that each token has access to 47 billion parameters, but only uses 13 billion active parameters during inference. The model was trained with a context size of 32 thousand tokens, and according to its abstract it outperforms or matches Llama 2 70B and GPT-3.5 across all evaluated benchmarks, and was released under the Apache 2.0 license.

Practitioner level

The working unit of mixture of experts is token by token, not sentence by sentence. In a mixture of experts language model, the router works at every layer and for every token separately, so two neighboring words can be processed by different combinations of experts. This is what makes the number of active parameters far smaller than the total number of parameters: in the Mixtral example above, per token only two of the eight experts in each layer switch on.

The router in the founding paper works through what is called noisy top-k gating. Before the choice values are computed, controlled random noise is added, then only the top k values are kept and the rest are made zero, so only the top experts switch on. The noise is not decoration: it helps with load balancing, that is, keeping tokens from piling onto the same few experts. The founding paper also adds special loss terms that push the router to divide importance and load evenly across all experts. Without such guarding, an expert that gets good early would keep being chosen and keep getting better, while the other experts never learn.

The Switch Transformer simplification shows another direction: a single top expert for each input is enough. That simpler route cuts communication and computation costs, and makes very large sparsely activated models trainable in the lower precision number format called bfloat16, which according to its paper's abstract was achieved for the first time for sparse models of that size.

Expert level

Mixture of experts gating network diagram

*Mixture of experts gating network diagram: one gating network routes the input to the experts that switch on. Work by Sinafe, CC BY-SA 4.0, via Wikimedia Commons.*

Mixture of experts is the most successful realization of the idea of conditional computation, the idea that which parts of a network are active may depend on its input. The founding paper's abstract frames it as a way of dramatically increasing model capacity without a proportional increase in computation, and reports greater than 1,000x improvements in model capacity with only minor losses in computational efficiency on modern GPU clusters. The mixture of experts layer in that paper was applied convolutionally between stacked LSTM layers, with the layer's parameter count reaching 137 billion.

In form, each expert is a standalone feed forward network with its own parameters, and the layer's output is a weighted combination of the outputs of the experts that switch on, with the weights coming from the gating network. Because the gate switches on only a sparse combination, the computation cost per example is set by the size of the experts that switch on, not by the total number of experts. The Switch paper puts it in a sentence that reads exactly: "In deep learning, models typically reuse the same parameters for all inputs. Mixture of Experts (MoE) defies this and instead selects different parameters for each incoming example."

The technical limits named plainly by its primary literature are three. First, load balancing: the router must constantly be kept dividing the load, and the founding paper solves this with noise in the gate plus importance and load loss terms. Second, saturation at extreme sparsity: in the founding experiment, raising the experts to 131,072 actually lowered quality, which its authors suspected was a result of too much sparsity. Third, the barriers to adoption recorded word for word in the Switch paper's abstract as complexity, communication costs, and training instability; these are the reasons the approach long failed to spread widely before routing simplifications and new training techniques arrived.

Limits and risks

Mixture of experts enlarges a model without enlarging the computation cost per word, but its total parameter count still has to be stored and maintained: a model with access to 47 billion parameters per token is still a model of that size, even though only 13 billion are active. The storage and machine memory it needs do not shrink along with the active parameters.

There is also a risk inherent in the routing itself. If the router fails to divide the load, some experts are overloaded and others sit idle, and model quality falls; its primary literature itself records training instability as a real barrier. And like every model that learns from examples, a mixture of experts model imitates the patterns of its training data, including its gaps and its biases; the output of such a model remains raw material that needs checking, especially for important decisions.