Developer releases a 190-line pure-JAX implementation of DeepSeek-V3
A developer released a pure-JAX implementation of key DeepSeek-V3 architecture components in 190 lines, along with tests, a checkpoint, training logs, diagrams, and reproduction instructions. The author reports pretraining a 36.2M-parameter model on public-domain detective fiction using a MacBook Air M5, while explicitly describing it as an architecture demonstration rather than a capable language model. The project omits sparse expert dispatch, MLA weight absorption, FP8 training, DualPipe, node-limited routing, YaRN, and post-training.
The release provides a compact, readable reference for studying MLA, DeepSeekMoE routing, balancing, and multi-token prediction, although its reported training results remain author-supplied and the implementation is not operationally equivalent to full DeepSeek-V3.
The architecture from the DeepSeek-V3 technical report in 190 lines of pure JAX, pretrained from scratch on a MacBook Air on public-domain detective fiction.
No Flax, no Equinox, no PyTorch. Params are plain dicts of arrays and every part of the model is a function you can read top to bottom in deepseek_v3.py.
Read the write-up:DeepSeek V3 in 190 lines of pure JAX, with diagrams, the code explained piece by piece, and the results.
What's in the 190 lines
| Idea from the paper | What it does | Where |
|---|---|---|
| Multi-head Latent Attention (MLA) | Caches one small latent per token instead of full keys and values: 480 → 144 numbers per token per layer here | mla, init_cache |
| Decoupled RoPE | One rotary key shared by all heads, kept outside the compressed latent | rope, apply_rope, mla |
| DeepSeekMoE | 1 shared expert that always runs + 16 routed experts, top-4 per token | route, moe |
| Auxiliary-loss-free balancing | A per-expert bias nudges routing toward idle experts; it changes which experts are picked, not their weights | update_bias, route |
| Sequence-wise balance loss | The small complementary loss from the paper (α = 1e-4) | seq_balance_loss |
| Multi-token prediction (MTP) | An extra module also predicts the token after next, weighted λ = 0.3 in the loss | forward, loss_fn |
| Training and generation | bf16 compute on f32 master weights; prefill + decode with the MLA cache | make_train_step, generate |
#DeepSeek-V3#deepseek-v3-jax#JAX#DeepSeekMoE#Multi-head Latent Attention#DeepSeek-AI