TopGit
GitHub Repo Review

MiniMind: Train a 64M LLM from Scratch in 2 Hours

jingyaogong/minimind
MTopGit review image for jingyaogong/minimind
Review by Topgit.dev for jingyaogong/minimind, with GitHub repository stats and README context.
Quick verdict

MiniMind earns its place as the most thorough single-repo LLM training tutorial for developers who want to build understanding, not just use a library. The catch is that a 64M model has hard capability ceilings—it can't reason like DeepSeek-R1 or hold long documents—and the project skews Chinese. But if you need a low-cost entry point into pretraining, SFT, RLHF, and agentic RL all in one place, written in readable PyTorch, MiniMind delivers exactly that: a full training run you can finish in an afternoon.

Stars
★ 74.4k
Forks
⑂ 9.9k
Contributors
👥 13
Language
Python
License
Apache-2.0
Topic
AI Tools
Updated
Nov 2026
Homepage
GitHub

What is MiniMind?

MiniMind is an open-source LLM training project that lets you train a 64M-parameter language model from scratch on a single NVIDIA 3090 in about two hours for roughly three yuan. It covers the full training pipeline—pretraining, SFT, DPO, PPO/GRPO, tool-calling, and agentic RL—using pure PyTorch code written from scratch, with no reliance on high-level training abstractions. Models are Dense (64M params) or MoE (198M, 4-expert top-1), both compatible with transformers, llama.cpp, vllm, and ollama.

What the full training pipeline covers

  • ✓Pretraining with raw text-to-token-prediction on jsonl datasets, supporting DDP multi-GPU and DeepSpeed
  • ✓Supervised Fine-Tuning (SFT) using a chat template with role tags, tool_calls, and chain-of-thought thinking tags
  • ✓LoRA fine-tuning implemented in native PyTorch (no peft dependency), with a weight-merging export script
  • ✓RLHF via DPO on preference pairs, and RLAIF via PPO/GRPO/CISPO with a decoupled rollout engine
  • ✓Tool Use and Agentic RL (train_agent.py) supporting multi-turn tool calling with GRPO/CISPO
  • ✓Compatibility with transformers, llama.cpp, vllm, ollama, and Llama-Factory for inference and further fine-tuning
  • ✓Custom BPE tokenizer (6400 vocab), Pre-Norm + RMSNorm, SwiGLU, RoPE with YaRN for 32K context
  • ✓Dense (64M) and MoE (198M, 4-expert top-1) model variants with Qwen3-aligned architecture
How this repository's GitHub stars have grown over time. Source: star-history.com.View the star history ↗

What you can build and experiment with

  • •Training a small LLM from scratch as a learning exercise, from data loading to final weights
  • •Experimenting with MoE vs Dense architecture trade-offs on a single GPU
  • •Fine-tuning with LoRA or full SFT on domain-specific data (medical, code, etc.)
  • •Reinforcement learning experiments with DPO, GRPO, or PPO on a small model
  • •Building a tool-calling agent that calls functions in a multi-turn conversation
  • •Evaluating the model on C-Eval, C-MMLU, and OpenBookQA benchmarks

Getting started: installation and hardware requirements

Clone the repo, install Python dependencies from requirements.txt using pip, and download the mini training datasets (pretrain_t2t_mini.jsonl and sft_t2t_mini.jsonl) from ModelScope or HuggingFace into a ./dataset directory. The main hardware requirement is a CUDA-capable GPU—at least one NVIDIA 3090 (24GB) for the documented training times. If CUDA is unavailable you can fall back to CPU or MPS, but training will be significantly slower.

Training a 64M model from scratch

The training sequence runs: pretrain on raw text with `python train_pretrain.py`, then supervised fine-tune with `python train_full_sft.py`. Both scripts live under trainer/ and support `--from_resume 1` for checkpoint recovery. Multi-GPU training uses `torchrun --nproc_per_node N train_xxx.py`. To evaluate, point eval_llm.py at your checkpoint with `--weight full_sft`. For a pretrained Dense model, one epoch of pretrain plus one epoch of SFT on a single 3090 takes roughly 2.3 hours and costs about 3 yuan. You can also serve via the OpenAI-API-compatible script or run a Streamlit chat UI from scripts/web_demo.py.

Why MiniMind stands out

  • ✓Every core training algorithm is written in native PyTorch—no hidden abstractions from trl or peft, which makes the code readable and educational
  • ✓Full pipeline breadth: pretraining, SFT, LoRA, DPO, PPO/GRPO/CISPO, tool use, and agentic RL all in one repo
  • ✓Training cost is concrete and low: ~3 yuan on a single 3090 for a complete Dense model run
  • ✓Supports DDP, DeepSpeed, wandb, SwanLab, and checkpoint resume out of the box
  • ✓Outputs are compatible with transformers, llama.cpp, vllm, ollama, and Llama-Factory
  • ✓MoE variant (198M total, 64M active) available for experimenting with sparse architectures

What a 64M model cannot do

  • △A 64M model has hard capability limits—it cannot match larger models on reasoning, factual accuracy, or long-context tasks
  • △The project and its default data skew heavily Chinese; English support exists but is secondary
  • △The 6400-token vocabulary trades embedding efficiency for vocabulary coverage, which can hurt non-Chinese tokenization quality
  • △MoE training at the default 4-expert top-1 config is roughly 50% slower than Dense with pure PyTorch kernels, and expert utilization varies by workload
  • △Full training (non-mini datasets) requires 10GB for pretrain and 14GB for SFT data on top of GPU memory
  • △Checkpoint resume across different GPU counts works, but configuration mismatches between runs can require manual cleanup
View on GitHub ↗Homepage ↗

Other small LLM training projects

llm.c — a minimal C/CUDA repository from Andrej Karpathy focused on teaching GPT-2 training from scratch without Python or PyTorch overheadnanoGPT — a minimal PyTorch reimplementation of GPT-2 for training/finetuning, widely used as a learning reference but narrower scope than MiniMind ↗GPT-2 from Scratch (HuggingFace notebook) — a notebook-based tutorial covering transformer architecture and training from scratch using the transformers libraryLLM-Zero — an emerging open-source project aiming to replicate LLM training mechanics with minimal dependencies

Who is MiniMind for?

MiniMind is for developers who want to understand how an LLM actually trains end-to-end—data preprocessing, pretraining, RLHF, tool use—not just how to call a model's API. It's designed for someone with Python and basic ML knowledge who has read transformer papers but wants to see the math run as actual code. Hobbyist researchers on a budget who can't rent H100 clusters will get the most out of it. If you just need a capable model for production, a larger open-weight model will outperform it significantly; this is a learning and experimentation tool, not a production model source.

Frequently asked questions

How much does it cost to train MiniMind?

The README documents that training minimind-3 (64M Dense) using pretrain_t2t_mini plus sft_t2t_mini on a single NVIDIA 3090 takes about 2.3 hours at roughly 1.3 yuan per hour, totaling around 3 yuan (about $0.40 USD). The MoE variant (198M) costs about 4.2 yuan for the same dataset combination.

What is MiniMind's architecture (Dense vs MoE)?

MiniMind uses a Transformer Decoder-only structure aligning with the Qwen3 ecosystem: Pre-Norm + RMSNorm, SwiGLU activation, and RoPE with YaRN support. The Dense variant (minimind-3) has 8 layers, 768 dimensions, 8 query heads, and 4 KV heads for 64M total parameters.

Can MiniMind models run with transformers, llama.cpp, or vllm?

Yes. The README explicitly lists compatibility with transformers, llama.cpp, vllm, ollama, and Llama-Factory. You can load a trained MiniMind model via `transformers.AutoModelForCausalLM`, serve it with `vllm serve`, run it locally with `ollama run`, or export weights for llama.cpp inference.

What hardware is needed to train MiniMind from scratch?

The documented training runs use a single NVIDIA GeForce RTX 3090 with 24GB VRAM. The project supports DDP multi-GPU training via torchrun and DeepSpeed, so additional GPUs accelerate training proportionally. A CUDA-capable GPU is required; CPU or MPS backends work but are not recommended for training.

Does MiniMind support multi-GPU and DeepSpeed training?

Yes. Single-node multi-GPU training uses torchrun with the `--nproc_per_node N` flag for DDP. DeepSpeed is supported for distributed training, and checkpoint resume works across different GPU counts by automatically adjusting the step count.

What training stages does MiniMind cover (Pretrain, SFT, RLHF, etc.)?

MiniMind covers the complete LLM training lifecycle: pretraining on raw text, supervised fine-tuning (SFT), LoRA fine-tuning (native PyTorch implementation), DPO for preference learning, RLAIF using PPO/GRPO/CISPO, tool-calling capability, and Agentic RL with multi-turn tool use via train_agent.py.

The problem it solves

Most LLM learning paths start and end with LoRA fine-tuning a model you downloaded from HuggingFace. You never touch the part where the model learns to predict the next token in the first place. Third-party frameworks like trl and peft abstract away the training mechanics entirely, which is great for production but terrible for understanding. Meanwhile, paid courses sell shallow explanations of things you could read in the code yourself. There's no accessible, self-contained path from raw PyTorch to a working language model that covers pretraining, RLHF, and tool use end-to-end.

Related repositories

Source & attribution

Source: https://github.com/jingyaogong/minimind

GitHub data · last synced Sep 1, 2026Reviewed by Henry
← Back to TopGit

Curious whether minimind is right for you?

Let ChatGPT, Claude, or Perplexity look into it — click below and see what AI actually says about minimind.

GitHub