Train a 64M LLM from scratch with MiniMind
MiniMind trains a roughly 64M-parameter language model from scratch in plain PyTorch; you run pretraining, then SFT, then chat with the result.
TL;DR
MiniMind is an open-source (Apache-2.0) project for training a small language model, about 64M parameters, from scratch with native PyTorch code. You download two mini jsonl datasets (about 2.8GB in total per the README), run train_pretrain.py, then train_full_sft.py, and chat with the result using eval_llm.py.
Why this repo matters
Per the README, libraries such as transformers, trl and peft wrap training in a few abstract lines, which hides how an LLM actually works. MiniMind implements the model, the training loops and the post-training methods (SFT, LoRA, distillation, DPO, PPO, GRPO and an agent trainer, each with its own script under trainer/) in readable PyTorch. The README says the "2 hours" figure is one SFT epoch on a single NVIDIA 3090 and "RMB 3" is the matching GPU rental cost.
Best practices
- Start with the mini datasets. The README says you only need
pretrain_t2t_mini.jsonlandsft_t2t_mini.jsonlto reproduce theMiniMind Zerodialogue model. - Run scripts from
trainer/. The README states all training scripts are executed from the./trainerdirectory. - Use
--from_resume 1for long runs. Checkpoints (model, optimizer, progress) go in./checkpoints/and the run resumes automatically. - Scale out with
torchrun. For N GPUs the README usestorchrun --nproc_per_node N train_xxx.py. - Use LoRA for a private domain. The README positions it for adapting the model to a vertical scenario while keeping general ability.
- Match
--weightto what you trained.eval_llm.py --weighttakes the weight-name prefix such aspretrainorfull_sft.
How-to
Where do I start?
1. Install and fetch the data
What do I need first? Clone the repo and install the pinned requirements (the README gives this, with a mirror flag you can drop):
git clone --depth 1 https://github.com/jingyaogong/minimind
cd minimind && pip install -r requirements.txt
Then download pretrain_t2t_mini.jsonl and sft_t2t_mini.jsonl from the ModelScope or Hugging Face dataset page into ./dataset.
Next: Pretrain
Try it
Run pretrain then SFT on the mini datasets, then ask the same question with --weight pretrain and --weight full_sft. Write down how the answers differ.
Pitfalls
- Weight names must line up. The README warns the
--weightfor LoRA evaluation must match the base model used intrain_lora. - The WebUI needs a copied model folder. The README says to copy the transformers-format model into
./scripts/first, or the demo errors out. - Timing claims are narrow. "2 hours" is one SFT epoch on one 3090 according to the README, not the whole pipeline on any hardware.
- Pin your environment.
requirements.txtpins versions (for exampletransformers==4.57.6), so use a fresh virtualenv.
Next steps
- MiniMind README for the full training-stage guide and data combinations
trainer/for the DPO, GRPO, PPO, distillation and agent scriptsmodel/model_minimind.pyto read the whole model