Show HN: DeepSeek V3 in ~200 lines of pure Jax github.com · 252 points · 23 comm...

@best30

Show HN: DeepSeek V3 in ~200 lines of pure Jax github.com · 252 points · 23 comments · HN thread

TL;DR A developer reimplemented the architecture of DeepSeek-V3 (Multi-head Latent Attention, routed mixture-of-experts with bias-based balancing, multi-token prediction) in about 190 lines of pure JAX, with no Flax, Equinox or PyTorch. They pretrained a 36.2M-parameter model from scratch on about 21.7M tokens of public-domain detective fiction in roughly 2.6 hours on a MacBook Air M5, and the README stresses it is an architecture demo rather than a strong language model.

  • The model is a 36.2M-parameter (13.6M active per token) version of DeepSeek-V3 with 1 shared plus 16 routed experts, top-4 routing, and 6 layers.
  • MLA caches 144 numbers per token per layer instead of 480 for full keys and values.
  • Balancing via a per-expert bias brings expert load to 5.7–6.9% each (even is 6.25%), versus 0.09–18.6% without, while validation loss at step 2000 is essentially unchanged (3.921 vs 3.923).
  • Training used 207 public-domain US crime novels (Hammett repeated 3x), 12,000 steps, about 4.5 epochs, validation loss falling from 5.02 to 3.51.
  • Known limitations: dense MoE compute with no sparse dispatch, no weight absorption in MLA, no FP8, DualPipe, YaRN or post-training.
  • A v1.0 release includes the checkpoint and exact data; a ROCm container setup on an RX 7600 XT was also tested and merged.

Discussion The thread is warm and appreciative, mostly praising the project as a clear learning resource for understanding DeepSeek-V3 internals. Much of the discussion turns practical: an AMD RX 7600 XT owner shares the environment variables and container setup needed to run it on ROCm, which the author merged. Others ask for learning roadmaps, mention Karpathy, Raschka and the Stanford CS336 course, and wonder about CPU-only hardware, a C++ port, or a V4 version. Mood is positive with some frustration aimed at AMD's consumer GPU software support.

  • Excellent learning resource for understanding DeepSeek's architecture (most): Many commenters say rebuilding the model from first principles in a short codebase is an effective way to learn, and thank the author for sharing it.
  • AMD ROCm support for consumer GPUs is still poor (some): One commenter argues AMD's software support for non-datacenter cards remains weak and costs sales, though a ROCm user reports the project ran end-to-end with two environment variable workarounds.
  • Want standard datasets for comparability (a few): A commenter notes that using common datasets would make results comparable to others; the author agrees for comparison-focused work but says the detective corpus was for fun.
  • Asking for learning roadmaps and resources (some): Several readers, including those from Java/Python backgrounds, ask how to build intuition, and are pointed to 3Blue1Brown, Welch Labs, Karpathy's Zero to Hero, nanochat, and CS336.
  • Requests for ports and extensions (a few): Commenters ask whether it runs on CPU-only hardware, whether a C++ version exists, and whether the author would build a V4.1 version.

Links from the comments

#JAX #DeepSeek #mixtureOfExperts #machineLearning #AppleSilicon #education