DeepSeek V3 in 190 Lines of JAX: A 36M-Parameter Clone Trained on a MacBook Air in 2.6 Hours
A solo developer has published a 190-line pure-JAX implementation of the DeepSeek V3 architecture, trained from scratch on a MacBook Air M5 (24 GB) in about 2.6 hours. The repository, created on 13 November and MIT-licensed, reached 16 GitHub stars within a day and landed on the Hacker News front page on 14 November.
It is an architecture demo, not a usable language model. The author says so. What makes it worth reading is the ablation: it reproduces, at toy scale, the claim DeepSeek made for its auxiliary-loss-free expert balancing.
What is in the 190 lines
No Flax, no Equinox, no PyTorch. Parameters are plain dicts of arrays and each component is a function. The code covers:
- Multi-head Latent Attention (MLA): caches one small latent per token instead of full keys and values. Here that is 144 numbers per token per layer against 480 for standard attention, a 3.3x reduction.
- Decoupled RoPE: one rotary key shared by all heads, kept outside the compressed latent.
- DeepSeekMoE: one always-on shared expert plus 16 routed experts, top-4 per token.
- Auxiliary-loss-free balancing: a per-expert bias is nudged down for overloaded experts and up for idle ones. It changes which experts get picked, not the weights applied to their outputs.
- Multi-token prediction: an extra module predicts the token after next, weighted at 0.3 in the loss.
- Training and generation: bf16 compute on float32 master weights, plus prefill and decode with the MLA cache.
The scale gap
| DeepSeek V3 | This implementation | |
|---|---|---|
| Parameters (total / active) | 671B / 37B | 36.2M / 13.6M |
| Layers (dense + MoE) | 61 (3 + 58) | 6 (1 + 5) |
| d_model | 7,168 | 384 |
| Attention heads | 128 | 6 |
| Experts | 1 shared + 256 routed, top-8 | 1 shared + 16 routed, top-4 |
| Vocabulary | ~129K | 8,192 |
| Context | 4K, extended to 128K | 256 |
The author puts it at roughly 1/18,500th of V3.
The training run
The data is 207 books, 21.7M training tokens, mostly Project Gutenberg crime fiction with Dashiell Hammett’s novels repeated three times. Validation is held-out crime fiction. Training ran 12,000 steps over about 98M tokens (roughly 4.5 epochs) at a median 10.7K tokens per second, around 0.7 seconds per 8,192-token step.
Validation loss fell from 5.02 at step 250 to 3.51. Train loss ended at 2.81, and the author notes the model is starting to memorise, concluding it needs more data rather than more steps. Sample output for the prompt “The fog came in off the” reads as plausible detective prose that does not hold together as a story.
The Metal backend is the awkward part. Apple’s jax-metal plugin only works with jax 0.4.34, so the repository pins every dependency. One operation, a gradient through a 2-axis contraction, fails on jax-metal 0.1.1, and the model is written to avoid it. The author measured bf16 matmuls at 11.10 TFLOP/s against 2.76 for float32, about 4x, which is why the run uses mixed precision.
The result that matters
Two 2,000-step runs, one with the balancing bias and one without:
| Run | Per-expert load at step 2,000 | Validation loss |
|---|---|---|
| Bias on | 5.7-6.9% (even split is 6.25%) | 3.921 |
| Bias off | 0.09-18.6% | 3.923 |
Without the bias, one expert handles nearly 19% of tokens while another gets under a tenth of a percent. With it, every expert sits within about 0.6 points of an even split, and loss is indistinguishable (3.921 vs 3.923). That matches the argument in the V3 technical report: balancing experts through a bias term avoids the quality tax of a conventional auxiliary loss. A single seed on a 16-expert toy model is thin evidence, but it is a clean, reproducible demonstration of the mechanism.
Reproducing it
The repository ships a 39-test suite, a pinned requirements file, and a v1.0 release with the exact checkpoint (138 MB), tokenizer and tokenised data so the run can be replayed byte for byte. The author warns that Project Gutenberg has since reissued 28 of the 203 public-domain books with small edits, so rebuilding the dataset from source will give different file hashes, though token counts match. The checkpoint is a Python pickle and should only be loaded if you trust the source.
The author says the next step is inference or mechanistic interpretability work.