Learning resources#Model training
MiniMind: train a 64M LLM from scratch in 2 hours for 3 yuan
MiniMind is an Apache-2.0 PyTorch teaching repo: pretrain plus SFT of its 64M model takes 2.31 hours on one 3090, with DPO, PPO and GRPO scripts included.
Project facts
GitHub Ecosystem- License
- Apache-2.0
- Language
- Python
- Stars
- 70,169
- Data checked
- 2026-11-25
Snapshot figures reflect the check date and may change over time.

Most people who want to understand LLM training read papers, run a transformers wrapper, and nod at the loss curve when an epoch ends. MiniMind takes the other road: tokenizer, pretraining, SFT, LoRA, DPO, PPO, GRPO, tool use and distillation, all rewritten in plain PyTorch, around a 64M-parameter main model. Pretraining plus instruction tuning takes about 2.31 hours on a single 3090, which at the README’s 1.3 yuan per hour rental rate works out to roughly 3 yuan. The repo jingyaogong/minimind was created on 2024-07-27 and had 70,169 stars and 9,131 forks on 2026-11-25, under Apache-2.0, with the last push on 2026-11-23.

Key points
- The cost claim is defined precisely: “2 hours” is one SFT epoch on a single 3090, “3 yuan” is the GPU rental for that window. Pretraining is 1.21 hours and about 1.57 yuan; SFT is 1.10 hours and about 1.43 yuan.
- The mainline
minimind-3is a 64M dense model withd_model=768, 8 layers, 8 query heads and 4 KV heads, a 6,400-token vocabulary and a 32,768 context, configured to line up with the Qwen3 ecosystem so weights convert cleanly totransformers, llama.cpp, ollama and vLLM. - The family goes past text: MiniMind-V for vision, MiniMind-O for omni-modal, MiniMind-dLM for diffusion language modelling and MiniMind-Linear for linear attention, so the exercises do not stop at one architecture.
Core features
- One script per stage.
trainer/holdstrain_pretrain.py,train_full_sft.py,train_lora.py,train_dpo.py,train_ppo.py,train_grpo.pyand friends, each mapping to a step in the papers. You can read them end to end instead of hopping through framework internals. - No high-level wrappers. Attention, positional encoding, losses and RL sampling are written with native PyTorch rather than
trlorpeft, which is the whole point of the repo. - Dense and MoE side by side.
minimind-3is 64M dense;minimind-3-moeis 198M total with 64M active, 4 experts and top-1 routing. The README admits the MoE variant trains about 50% slower than a dense model of the same size in native PyTorch, because tokens are bucketed per expert and forwarded separately. That counter-intuitive detail is worth more than the summary line. - Three RL recipes. DPO, PPO and GRPO each get their own script, plus experiments for CISPO and adaptive thinking, with the data and scoring logic kept next to the trainers.
- Multi-GPU and resume. Launch with
torchrun --nproc_per_node N;--from_resume 1restores from./checkpoints/, including across a different GPU count. SwanLab is the default tracker. - Conversion and serving.
scripts/convert_model.pymoves between torch and transformers formats, and the README documents five serving paths: SGLang, vLLM, llama.cpp, ollama and MNN.
Typical use cases
- Anyone who wants to run a pretraining loop once. One 24GB card, or a rented 3090 for an afternoon, is enough to watch loss fall from random init to something that answers questions.
- Teachers and TAs explaining how LLMs work. A 64M model fits inside a lecture, and students can reproduce it in a dorm room. The
minimind-3-examLoRA run is a neat demonstration that a low benchmark score is not always a knowledge problem. - Teams prototyping agent and RL ideas. A cheap sandbox for reward design, sampling strategies, or the difference between PPO and GRPO, where one step is fast enough that a reward rewrite does not cost a night.
- People learning the deployment path. The same weights run in one line under ollama or as an OpenAI-compatible vLLM service, so the train-to-serve chain stays continuous.
Quick start
# clone and install
git clone --depth 1 https://github.com/jingyaogong/minimind
cd minimind && pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple
# inference only: download weights and chat
modelscope download --model gongjy/minimind-3 --local_dir ./minimind-3
python eval_llm.py --load_from ./minimind-3
# train from scratch: put pretrain_t2t_mini.jsonl and sft_t2t_mini.jsonl in ./dataset first
cd trainer && python train_pretrain.py
python train_full_sft.py
train_full_sft.py writes full_sft_768.pth into out/, and python eval_llm.py --weight full_sft talks to it. The README keeps an early “Zero” sample transcript: the model names Hangzhou snacks and then drifts into nonsense on an English history question. That transcript is the most honest description of what two hours buys.
Benchmarks
The README runs lm-evaluation-harness over C-Eval, CMMLU, ARC-Easy, PIQA, OpenBookQA, HellaSwag and Social-IQa (results in the current table correspond to minimind-3, released 2026-04-01; last repo push 2026-11-23; training on a single 3090, eval examples use --device cpu):
| Model | Params | ceval / cmmlu | arc / piqa / obqa / hellaswag / siqa |
|---|---|---|---|
| minimind-3 | 64M | 24.89 / 25.38 | 28.49 / 50.65 / 23.60 / 28.28 / 34.19 |
| minimind-3-exam | 64M | 30.98 / 26.12 | 35.61 / 56.26 / 24.20 / 28.40 / 34.19 |
| gpt2-medium | 360M | 23.18 / 25.00 | 43.60 / 66.38 / 30.20 / 39.38 / 39.10 |
| SmolLM2-135M | 135M | 24.44 / 24.71 | 58.50 / 68.17 / 32.80 / 43.15 / 39.46 |
| TinyLlama-1.1B | 1.1B | 25.71 / 25.03 | 54.80 / 74.43 / 35.60 / 60.38 / 43.09 |
Read these numbers loosely. The author prints the standard errors himself: about ±1.9 on OpenBookQA, ±1.2 on C-Eval and PIQA, so gaps under roughly 3 points do not separate two models. The 64M model sits near chance on Chinese multiple choice and trails SmolLM2-135M by a wide margin in English, consistent with a smaller, Chinese-heavy training mix. The informative row is minimind-3-exam: one LoRA pass that only aligns answer formatting lifts the average across seven tasks by about 2.9 points, which says the bottleneck for tiny models is sometimes input format rather than knowledge.
Summary
Use it as a teaching base and an experiment sandbox, where readable, editable and finishable matter more than leaderboard position. Do not use it to build a product. At 64M the factual knowledge and generalization are thin, as the Zero transcript shows; the minimind-3-exam and tool-call variants are better for Chinese tasks, but they remain toys.
Three costs to know. The “3 yuan” is GPU rental, excluding your time and the hours spent getting the environment right. The MoE variant is about 50% slower than dense in native PyTorch, so real speedups wait on fused kernels. And the project is maintained by one person in his spare time, with 70k stars worth of issues arriving; documentation and features move at the author’s pace. For the opposite trade-off, compare airllm, which loads models layer by layer to fit large weights in small VRAM: one compresses inference cost, the other training cost. For where small models sit in real procurement, see Menlo Ventures’ read on a batch of Chinese open models.