开发者发布190行纯JAX版DeepSeek-V3
开发者以190行纯JAX代码实现了DeepSeek-V3架构的多个关键组件,并同时提供测试、检查点、训练日志、图解和复现说明。作者称其在一台MacBook Air M5上使用公版侦探小说从头预训练了一个3620万参数模型,但明确表示这只是架构演示,并非能力强大的语言模型。该项目未实现稀疏专家调度、MLA权重吸收、FP8训练、DualPipe、节点限制路由、YaRN及后训练。
该项目为理解MLA、DeepSeekMoE路由、负载均衡和多词元预测提供了紧凑且易读的参考,但训练结果均来自作者自述,实现也与完整的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