---
title: "Mixture of Experts Explained"
description: "Mixture of Experts (MoE) transformers replace dense feed-forward layers with sparse expert layers and a learned router that sends each token to only a few experts."
url: "https://swe.quest/articles/mixture-of-experts-explained-5efff8fe17f2e9ca"
canonical: "https://huggingface.co/blog/moe"
source: "Hugging Face"
published: "2023-12-11"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 21
tags: ["llms","model-training","inference","machine-learning"]
---

# Mixture of Experts Explained

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2023-12-11, 21 min read, Deep dive. Original: [https://huggingface.co/blog/moe](https://huggingface.co/blog/moe)

## Summary

Mixture of Experts (MoE) transformers replace dense feed-forward layers with sparse expert layers and a learned router that sends each token to only a few experts. Pretraining is much faster than for dense models, and inference is faster than a dense model with the same parameter count, but all experts must sit in memory: Mixtral 8x7B needs VRAM for about 47B parameters while computing like a 12B model. The history runs from the 1991 origins through Shazeer's noisy top-k gating, GShard's expert capacity and random routing, and Switch Transformers' single-expert routing and selective bfloat16 precision. It also covers load-balancing auxiliary losses, router z-loss, fine-tuning difficulties, expert parallelism and serving tradeoffs.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)

## Prerequisites

- transformer architecture ([easy posts on System design](https://swe.quest/tags/system-design.md?difficulty=easy))
- neural network training basics ([easy posts on Model training](https://swe.quest/tags/model-training.md?difficulty=easy))
- softmax and loss functions

## Keywords

Mixture of Experts, Mixtral 8x7B, Switch Transformers, GShard, Noisy Top-k Gating, router z-loss, Hugging Face Transformers

## Related posts

- [Mixture of Experts (MoEs) in Transformers](https://swe.quest/articles/mixture-of-experts-moes-in-transformers-670e279baa41a80a.md): Hugging Face · 2026-02-26 · Hard · 10 min read · Inference & serving, LLMs, Model training, Performance engineering, Python
  Hugging Face transformers v5 reworks its internals to treat Mixture of Experts models as first-class: a WeightConverter pipeline packs per-expert checkpoint tensors into contiguous runtime tensors with async, lazy materialization, cutting Qwen1.5-110B load time from ~66s to ~21s (10s with tensor parallelism) on an A100.
- [Welcome Mixtral - a SOTA Mixture of Experts on Hugging Face](https://swe.quest/articles/welcome-mixtral-a-sota-mixture-of-experts-on-hugging-face-8678082efd21a0bd.md): Hugging Face · 2023-12-11 · Medium · 11 min read · LLMs, Inference & serving, Model training, Machine learning
  Mixtral 8x7B is Mistral's sparse Mixture-of-Experts LLM. It replaces feed-forward layers with MoE layers that route each token to 2 of 8 experts, so it has about 45B total parameters but decodes at roughly the speed of a 12B dense model.
- [180B Parameters, 32GB of RAM: Pushing MoE Inference to the Limit with Transformers](https://swe.quest/articles/180b-parameters-32gb-of-ram-pushing-moe-inference-to-the-limit-with-transformers-63cd3cf21432f7c3.md): Hugging Face · 2026-11-18 · Hard · 11 min read · Inference & serving, LLMs, Performance engineering, Caching, Hardware
  Streaming MoE experts from SSD through a bounded device-side slot pool lets Transformers run Qwen3.8-Flash-Next (121 GB of experts) on a 32 GB MacBook M5 at ~13.9 tok/s, within 6% of the specialized Strata engine on decode and slightly faster on prefill.
- [SegMoE: Segmind Mixture of Diffusion Experts](https://swe.quest/articles/segmoe-segmind-mixture-of-diffusion-experts-11821c390645523e.md): Hugging Face · 2024-02-03 · Medium · 5 min read · Computer vision, Machine learning, Inference & serving, Python
  SegMoE is a framework for building Mixture-of-Experts diffusion models by merging pretrained Stable Diffusion or SDXL checkpoints.
- [Accelerating Transformers Fine-Tuning with NVIDIA NeMo AutoModel](https://swe.quest/articles/accelerating-transformers-fine-tuning-with-nvidia-nemo-automodel-c196d721b8de0a9a.md): Hugging Face · 2026-06-24 · Hard · 10 min read · Model training, Performance engineering, LLMs, Python
  NeMo AutoModel subclasses Transformers v5's AutoModelForCausalLM and adds Expert Parallelism as a dedicated mesh orthogonal to data parallelism, DeepEP fused all-to-all dispatch, and TransformerEngine kernels.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
