Can You Train a 64M LLM in 2 Hours for ¥3? Inside 75.4K-Star MiniMind's 4,753 Lines of Pure PyTorch
DEV Community

Can You Train a 64M LLM in 2 Hours for ¥3? Inside 75.4K-Star MiniMind's 4,753 Lines of Pure PyTorch

jingyaogong/minimind just surged past 75,382 stars (9,985 forks, Apache-2.0) on GitHub Trending. Its headline hook - "Train your own 64M LLM from scratch in 2 hours for ¥3" - travels fast, and often gets misread as a shortcut to building a cheap production assistant on a laptop.

I inspected all 22 Python files (4,753 total lines) and read through README.md down to its benchmark tables at line 1,628. Here is what makes the codebase genuinely special - and the four fine-print realities hidden behind the tagline.

Why Engineers Love It: 4,753 Lines of Zero-Wrapper Pure PyTorch

High-level libraries (transformers, trl, peft) let you fine-tune in twenty lines, but they hide how RoPE scaling, GQA, MoE routing loss, or GRPO advantages actually execute tensor by tensor.

MiniMind strips away training-framework abstractions and aligns its 2026 minimind-3 mainline with Qwen3 / Qwen3-MoE across clean, standalone PyTorch scripts:

File Lines Scope
model/model_minimind.py 293 Complete Dense (64M) + MoE (198M-A64M, 4 experts / top-1) Transformer with GQA (8Q/4KV), YaRN (32,768 ctx), Flash Attention
trainer/train_tokenizer.py 190 Custom 6,400-vocab BPE tokenizer with <think> and <tool_call> tokens
trainer/train_pretrain.py 166 Raw PyTorch AMP + grad accumulation + DDP pretraining loop
trainer/train_full_sft.py 167 Full supervised fine-tuning (now mixing tool-calling traces directly)
trainer/train_lora.py + model_lora.py 181 + 71 From-scratch LoRA injection without peft
trainer/train_dpo.py / train_ppo.py / train_grpo.py 221 / 443 / 322 Native PyTorch RLHF & RLAIF implementations
trainer/train_agent.py + rollout_engine.py 485 + 225 New multi-turn Agentic RL trainer (GRPO / CISPO) with decoupled rollout engine

Reading model_minimind.py (293 lines) alongside train_pretrain.py (166 lines) and train_grpo.py (322 lines) over a weekend teaches more real mechanics than most paid courses.

4 Realities Hidden Behind the "2 Hours / ¥3" Headline

Credit to the author: none of these caveats are hidden - they are documented right inside README.md, just skipped by viral reposts.

  1. "2 hours / ¥3" Is One SFT Epoch on an RTX 3090 - Not Full From-Scratch Training

    Line 42 of README.md explicitly clarifies: "2 hours" refers to 1 epoch of SFT on a single NVIDIA RTX 3090 (24 GB), and "¥3" is the corresponding cloud GPU rental cost. Line 252 shows the author's actual workstation: 8 × RTX 3090 (24 GB) + 128 GB RAM.

    Quick demos use pretrain_t2t_mini.jsonl (1.2 GB) + sft_t2t_mini.jsonl (1.6 GB), whereas the full minimind-3 mainline corpus requires 10 GB pretrain + 14 GB SFT JSONL plus rlaif.jsonl (24 MB) and agent_rl.jsonl (86 MB).

  2. Pure-PyTorch MoE Trains ~50% Slower Than Dense

    Because MiniMind avoids custom fused Triton or DeepSpeed-MoE kernels to stay readable, routing tokens into per-expert buckets multiplies kernel-launch overhead. Line 599 openly notes that 4 experts / top-1 MoE trains roughly 50% slower than the matching dense model.

  3. The 6,400-Token Vocabulary Trades Sequence Efficiency for Tiny Embeddings

    Keeping vocab_size = 6400 stops the embedding and LM-head layers from dominating a 64M parameter budget, but splits Chinese and English text into significantly more tokens per sentence than modern 100K+ tokenizers.

  4. Objective Benchmarks Confirm It Is a Textbook, Not a Production Model

    Line 1,628 publishes transparent zero-shot benchmarks (where random 4-choice guessing sits at 25%):

Model Params C-Eval C-MMLU ARC-Easy PIQA
minimind-3 64M 24.89 25.38 28.49 50.65
minimind-3-moe 198M 25.48 24.32 27.74 50.71
minimind-3-exam (format LoRA) 64M 30.98 26.12 35.61 56.26
Similarly, the bundled tool-calling data comes from ~100k qwen3-4b traces across ~10 mock tools (weather, math, time) - great for learning multi-turn `<tool_call>` formatting, not generalizable agent production.

Practical Verdict

  • Clone it immediately if you want to step-debug an entire modern LLM stack - Tokenizer, Pretrain, SFT, LoRA, DPO, GRPO, and Agentic RL - in under 5,000 lines of clean PyTorch.
  • Skip training from scratch if your goal is shipping a cheap private model for users: LoRA fine-tuning a strong pre-trained 1.5B-7B base beats a from-scratch 64M model by orders of magnitude.

When reading LLM training repos from scratch, which piece tripped you up first - GQA/RoPE tensor shapes or writing DPO/GRPO losses cleanly?

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.