A mixture of experts (MoE) avoids running every part of a model for every input. In a transformer, an MoE layer can replace a parameter-dense feed-forward layer with multiple expert networks. A gate or router directs an input to the experts selected for it, so only some experts typically run. section 3.3.1
Figure 3.3 Example mixture of an expert's model with both a gate and router to control flow. The MoE model is used to replace the FFN layers in a transformer; here, we show it replacing the FFN in a decoder.
The diagram locates the MoE layer in a transformer decoder and shows how a gate and router control the path through its experts. section 3.3.1
Think of the experts as students who begin together and develop different specialties during training. Their specialties need not have recognizable names: they emerge from patterns in the training data. At inference time, selecting experts relevant to an input can retain that specialization without consulting every expert. Unlike an ensemble that combines every model’s result, an MoE typically runs only one or a few experts; a complex input may call for more. section 5.3.4 section 3.3.1
The practical trade-offs are:
- Sparse activation shortens the computation path, but the full layer can still contain many parameters. Do not equate fewer active experts with fewer stored parameters. section 3.3.1
- Changing a feed-forward layer into an MoE changes the model’s structure and requires finetuning afterward. Finetuning must account for both experts and gating. section 3.3.1 section 5.5
- Quantization can complement MoE: a cited study reached 2-bit quantization with minimal reported accuracy impact. That result is not a guarantee for every model. section 3.3.1
Finetune an existing MoE
Rather than converting a feed-forward layer yourself, load a pretrained Google Switch Transformer through Hugging Face Transformers, tokenize a text dataset, and finetune it. The example uses `google/switch-base-8` and a local text file; it illustrates using an existing MoE rather than building its routing mechanism from scratch. section 5.3.4



