Mixture of Experts

Machine Learning
Introduced by
Shazeer, N. et al.
Year
2017
Type
Sparse neural network architecture (conditional computation)

What does it do?

Mixture of Experts (MoE) is a sparse neural-network architecture in which a router activates only a subset of expert sub-networks for each input.

The gating-network architecture on which it builds was described by Jordan and Jacobs (1994). The sparsely-gated, top-K form used in large models was introduced by Shazeer and colleagues in 2017. Because the output sums only over the top-K selected experts, per-input computation depends on K rather than on the total number of experts.

The intuition behind the method

Instead of running every input through one huge network, MoE keeps a panel of specialised expert networks and a router that decides which few experts each input should consult. Because only a handful of experts fire per input, the model can carry an enormous number of parameters while doing roughly the same amount of work per example — much like consulting only the two specialists relevant to a question rather than the whole hospital.

History

Shazeer and colleagues introduced the sparsely-gated Mixture-of-Experts layer in 2017 in 'Outrageously Large Neural Networks', using sparse top-K gating as a form of conditional computation. The mixture-of-experts architecture itself is older. Jordan and Jacobs (1994) described a gating network that softly partitions the input space and combines expert predictions (as discussed in Webb, Statistical Pattern Recognition, p. 292). The originator attribution for the sparse layer therefore refers to the 2017 form. Later, Mixtral (Jiang et al., 2024) applied sparse mixture-of-experts layers in a large language model.

When to use it

Choose MoE when you need a very high-capacity model, your training data is large (for example, large-scale text corpora of the kind used for language modelling), and you have large-scale training infrastructure with GPU clusters. It also requires a training pipeline that can apply a router balancing loss and handle sparse gating. For small or moderate datasets, MoE may be a poor fit: the router may then have too little signal to learn balanced expert selection, and each expert receives few examples. In that situation a single dense model is often the more practical option. It is also the better choice when you lack the hardware to store all experts in memory.

Limitations and considerations

  • Requires large-scale training infrastructure and a GPU cluster.
  • Needs a router balancing loss; without it, routing tends to collapse onto a few experts and the rest stay under-trained.
  • With small datasets the router may learn unbalanced routing, and training may be less stable than for a dense model.
  • With limited data the model may overfit, so a single dense model is often the more practical choice.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Total parameter count can grow while per-input computation stays roughly fixed, because the output is a sum over only the top-K experts.
  • Individual experts can specialise, so one layer can serve inputs of different kinds by routing them to different sub-networks.
  • Per-input compute is lower than that of a dense model with the same total number of parameters, since most experts are skipped for each input.
  • Sparse expert layers have been applied in large language models such as Mixtral.

Applications

  • Large language models that increase parameter count without a proportional increase in inference cost (e.g. Mixtral).
  • Large-scale language modelling and text prediction, where very high capacity is needed.
  • Conditional-computation architectures that route different inputs to specialised sub-networks.

How it works

How it works

1

The layer holds many parallel expert sub-networks, each a small feed-forward network. In the basic formulation, expert i produces a nonlinear function of a linear projection of the input, E_i(x) = f(w_i^T x), where f is a fixed continuous nonlinearity. The experts are trained to specialise, so different inputs end up routed to different experts. Only the selected experts process a given input, which is why total capacity can grow without growing the per-input compute.

Formula
E_i(x) = f(\mathbf{w}_i^{\top} x)
2

A gating network (router) scores the experts for each input and keeps only the top-K. A softmax over those top-K scores produces the routing weights, so the weights of all non-selected experts are zero. In the original mixture-of-experts formulation the gating network is trained simultaneously with the experts rather than fitted afterwards. It acts as a soft partition of the input space, with each expert giving a local prediction (Jordan and Jacobs, 1994). During large-scale training a router balancing loss is commonly added, so that load is spread across experts rather than collapsing onto a few favourites.

Formula
G(x) = \text{Softmax}(\text{TopK}(x \cdot W_g))
3

The outputs of the selected experts are combined as a weighted sum, using the gating weights as coefficients. This sparse combination is what keeps computation constant while the parameter count, and thus model capacity, scales up.

Formula
y = \sum_{i \in \text{TopK}} G(x)_i \, E_i(x)

Common pitfalls

  • Omitting the router balancing loss, so a few experts receive most inputs and the rest stay idle.
  • Applying MoE to a small dataset, where a single dense model may be easier to train reliably.
  • Treating the number of experts as free capacity: all expert parameters must still be stored in memory even though only the top-K run for each input.
  • Underestimating the GPU and infrastructure footprint required for sparse, distributed training.

Frequently asked questions

Why does MoE add parameters without adding compute?

Only the top-K experts selected by the router run for each input, so even though the layer stores many experts, each example touches only a few. Total capacity scales with the number of experts while per-input computation stays roughly fixed.

What is the router balancing loss for?

Left alone, the router tends to send most inputs to a small number of experts, leaving the others untrained. A balancing loss penalises uneven load so that traffic is spread across experts and the full capacity is actually used.

How much data does MoE need?

It is intended for large-scale settings. On small datasets the router may learn unbalanced expert selection and training may be less stable. With limited data a single dense model is less prone to overfitting and is often the more practical choice. The appropriate data scale depends on the task and model size, and no general sample-size threshold can be stated.

Do I need special hardware?

Yes. MoE assumes large-scale training infrastructure and a GPU cluster, since the many experts and sparse routing are designed for distributed, high-throughput training.

How do I check whether the experts are being used evenly?

Look at the share of inputs routed to each expert. If a few experts receive most inputs while others are almost idle, routing has collapsed onto a small subset, and the balancing loss or the top-K setting should be revisited. Comparing training and validation loss also shows whether the added capacity is generalising or overfitting.

Related methods

Sources

  1. Shazeer, N. et al. (2017). Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer. ICLR. arXiv:1701.06538

    Open publication reference
  2. Jiang, A.Q. et al. (2024). Mixtral of Experts. arXiv.

    Open publication reference
  3. Webb, Statistical pattern recognition, p. 292