Skip to content

By PromptFission2 min read

DeepSeek V3's architecture in 190 lines of JAX, trained on a MacBook Air

A 36M-parameter miniature with latent attention, routed experts, and loss-free load balancing, trained on detective novels in 2.6 hours. It includes an ablation.


deepseek-v3-jax rebuilds the DeepSeek V3 architecture in what the README counts as 190 non-blank, non-comment lines of plain JAX, with no Flax, Equinox, or PyTorch. Vaibhaav Tiwari then trained the result on a MacBook Air and published the numbers, including a small experiment on the one piece of the design that is hardest to take on faith.

How it works

The file implements the parts that make V3 different from a textbook transformer, at toy scale: 6 layers instead of 61, a 256-token context, and 36.2M parameters of which 13.6M are active for any one token.

Multi-head latent attention is a way to shrink the cache a model keeps while generating. Instead of storing full keys and values for every past token, it stores one small compressed vector and expands it when needed. Here that is 144 numbers per token per layer, down from 480, according to the README.

The feed-forward part is a mixture of experts: one shared expert runs on every token, and a router picks 4 of 16 others. The usual problem is that the router falls in love with a few experts and starves the rest. V3’s answer, reproduced here, is a per-expert bias that nudges routing toward underused experts. It changes who gets picked, not the experts’ weights.

There is also multi-token prediction, an extra module that guesses the token after the next one.

The ablation

The training data is 207 public-domain crime and detective books, about 21.7M tokens. On an M5 MacBook Air with 24 GB, 12,000 steps took about 2.6 hours, and validation loss fell from 5.02 to 3.51.

At step 2000 with the bias on, each expert handled between 5.7 and 6.9 percent of tokens, against a perfectly even 6.25. With it off, the spread was 0.09 to 18.6 percent. Validation loss was 3.921 with balancing and 3.923 without. So in this run the bias evened out the load and cost nothing measurable. These are the author’s figures from single runs.

What broke

jax-metal 0.1.1 only works with jax==0.4.34, so JAX must not be upgraded. A gradient through one kind of two-axis contraction fails on jax-metal, and the model is written to avoid it. Project Gutenberg has re-issued 28 of the books with small edits, so a fresh data build will likely not match the published hashes.

It is also not efficient. Every expert runs on every token and the unselected outputs are zeroed, so the routing is exact but nothing is saved. The author calls it “an architecture demo, not a strong language model.”

Try it yourself

The repo is MIT licensed and links a longer write-up with diagrams. The published run needs an Apple Silicon Mac, Python 3.12, and uv:

uv venv -p 3.12 .venv
uv pip install --python .venv/bin/python -r requirements.txt
.venv/bin/python prepare_data.py
.venv/bin/python train.py

There is a smaller CPU config that the README says has only been checked for a couple of steps. The v1.0 release includes a 138 MB checkpoint; the README warns that it is a Python pickle, which can run code when loaded.

We have not trained or sampled from it; this is based on the README.