nano_moe_gpt
A six-layer decoder-only language model whose feed-forward layers alternate with eight-expert MoE layers.
Language · 296 operations Checked
Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.
At a glance
- Task
- Language
- Parameters
- 55.1M
- Operations
- 296
- Framework
- PyTorch
- Recurrent
- No
- Published
- 2025, Deep (Learning) Focus newsletter
- Authors
- Cameron R. Wolfe
- Source
- GitHub: wolfecameron/nanoMoE
- License
- MIT
- Checked
- Passed: the trace was replayed operation by operation and matched the model's own output for this input.
Files
The file opened in a new tab. Use your browser's Save command there to keep it.
The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.
Details
- Stable ID
- m7562
- Graph hash
- eb240fa9a5d4fb4126b73814527dd005f459e70fcefd7afb456a944c3d628a96
- Skeleton hash
- 27ab90a3d28c0eceb6f2c8402c0aa878e56d0d05ddcd058f10e5f5f057f314f4
- Architecture hash
- cc21479a7aeb7fc78a95eaef253b726e3dbe8c071e9f451f1de06488984169ef
- Diagram SHA-256
- 53517163ca37d10eacd13efad9555086608a349700123131de097a3672fb2a22
- TorchLens version
- 2.36.0
- Renderer
- graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
- Check
- Forward pass replayed in PyTorch
What it is
nanoMoE is a mid-sized Mixture-of-Experts (MoE) language model that a blog post builds and pretrains from scratch in PyTorch. Its code is a fork of the nanoGPT library, expanded to support MoE pretraining.
An MoE model starts from a decoder-only transformer and converts some of its feed-forward layers into expert layers, each holding several independent copies of the original feed-forward network. A router, a linear layer followed by a softmax, selects the top-K experts for each token, so only a small portion of the parameters is active for any given token. This model has six layers with six attention heads each and eight experts, two of them active per token, with an MoE block in every other layer.
Much of the post is about training stability, because MoEs are more complex than dense models and prone to instability during training. The final setup adds a load balancing auxiliary loss and a router z-loss, keeps the router in full float32 precision under mixed-precision training, and uses a weight initialization scheme chosen for MoE stability. With all of these enabled, the post reports that pretraining completes without diverging, on about 25 billion tokens of OpenWebText in roughly 5 days on two 3090 GPUs.
Key idea. nanoMoE extends the nanoGPT codebase into a small Mixture-of-Experts language model and shows which stability measures let it pretrain without diverging.
- nanomoe
- nano moe
- nano_moe_gpt
- mixture of experts
- moe
- moe llm
- sparse experts
- text generation
- language model
AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.
Cite the paper
@article{nanomoe2025,
title = {nanoMoE: Mixture-of-Experts (MoE) LLMs from Scratch in PyTorch},
author = {Cameron R. Wolfe},
year = {2025},
journal = {Deep (Learning) Focus newsletter}
}