ModelsFine-TuningMLAgentic

MiniMind: Train a 64M-Parameter LLM From Scratch

by Jingyao Gong (open source, GitHub)

IntermediateTutorialFree~2.3 GPU-hours for pretrain + SFT (one epoch each) on a single RTX 3090, plus self-paced time to read the code and run LoRA, DPO, RL and agent stages

Every stage of an LLM, from pretraining to agentic RL, in plain PyTorch scripts you can run on one consumer GPU.

Start LearningAdded Dec 2, 2026 · Updated Dec 2, 2026

Overview

MiniMind is an Apache-2.0 GitHub project by Jingyao Gong that implements the full lifecycle of a decoder-only language model as a set of standalone PyTorch scripts launched with torchrun. The current release, minimind-3 (April 1, 2026), aligns its architecture with the Qwen3 and Qwen3-MoE layouts: a 64M dense model with 8 layers, d_model 768, 8 query heads and 4 key-value heads, a 6,400-token vocabulary and a 32,768 maximum position, plus a 198M-A64M mixture-of-experts variant with 4 experts and top-1 routing. The pipeline runs train_pretrain.py, then train_full_sft.py (tool calling and adaptive thinking are folded into the SFT data and chat template), train_lora.py, DPO preference tuning, RLAIF with PPO, GRPO and a CISPO loss option, white-box knowledge distillation (cross-entropy plus KL), and train_agent.py for multi-turn tool-use RL. Mini datasets are 1.2 GB for pretraining and 1.6 GB for SFT, with 10 GB and 14 GB full versions. The README's cost table puts pretrain plus SFT at about 2.31 hours and roughly 3 CNY of rented RTX 3090 time; the headline "2 hours" refers to one SFT epoch alone. Trained models export in Transformers format and can be served through an included OpenAI-compatible server, vLLM, SGLang, llama.cpp (GGUF) or Ollama. Earlier minimind2 and minimind-v1 series date back to August 2024, and the changelog shows PPO, GRPO and SPO added in October 2025.

At a Glance

Topic
Models
Level
Intermediate
Format
Tutorial
Cost
Free
Duration
~2.3 GPU-hours for pretrain + SFT (one epoch each) on a single RTX 3090, plus self-paced time to read the code and run LoRA, DPO, RL and agent stages
Provider
Jingyao Gong (open source, GitHub)
Hands-on
Yes — code/exercises
Certificate
None

What You’ll Learn

  • ✓Pretrain a 64M dense decoder with grouped-query attention from random weights using train_pretrain.py
  • ✓Run full supervised fine-tuning where tool calling and adaptive thinking live in the SFT data and chat template
  • ✓Train LoRA adapters with train_lora.py and merge them for export with scripts/convert_model.py
  • ✓Apply DPO preference tuning and RLAIF with PPO, GRPO and the CISPO loss option
  • ✓Train a multi-turn tool-use agent with GRPO or CISPO through train_agent.py, added in minimind-3
  • ✓Distill a larger teacher into the small model with white-box distillation combining cross-entropy and KL loss
  • ✓Build the 198M-A64M mixture-of-experts variant with 4 experts and top-1 routing in the Qwen3-MoE layout
  • ✓Serve your trained model through an OpenAI-compatible API, vLLM, SGLang, llama.cpp GGUF or Ollama

Highlights

  • •Each training stage is a separate plain PyTorch script, so the loss and training loop for pretraining, SFT, DPO and RL are readable in one file each
  • •One of the most-starred educational LLM repos: 74.4k stars and 9.9k forks on GitHub when checked on December 2, 2026
  • •An independent write-up on wavect.io (November 16, 2026) found that the scripts default to two epochs, so you must pass --epochs 1 to match the README's 2.31-hour estimate
  • •The same review found that SFT examples whose user message pushes the reply past the 768-token truncation point contribute zero loss tokens, a data check worth running on your own SFT sets
  • •Covers the current post-training stack, including CISPO and agentic tool-use RL, which most from-scratch tutorials stop short of
  • •The README's per-stage cost table (single RTX 3090 at about 1.3 CNY per hour) tells you the GPU budget before you start

Who It’s For

Best For

  • ✓Application engineers who call LLM APIs and want to understand pretraining, SFT and RL by running them end to end
  • ✓ML engineers preparing to fine-tune or RL-train open models who want a small sandbox to test recipes cheaply
  • ✓Instructors and study groups looking for a complete LLM training codebase small enough to read in a week
  • ✓Hobbyists with one 24 GB consumer GPU, or a few dollars of rented GPU time

Prerequisites

  • •Comfortable Python and working knowledge of PyTorch training loops
  • •Basic understanding of the transformer architecture (attention, tokenization, next-token loss)
  • •Access to an NVIDIA GPU with about 24 GB of memory (RTX 3090 class) or a rented cloud GPU; vLLM and SGLang serving need CUDA
  • •Familiarity with SFT, DPO and GRPO concepts helps for the post-training stages

FAQ

What is MiniMind: Train a 64M-Parameter LLM From Scratch?

MiniMind is an open-source PyTorch project that trains a small language model (about 64M parameters) from random weights and then takes it through SFT, LoRA, DPO, RL and tool-use agent training. It is for engineers who use LLMs daily and want to see every training stage in code they can read and run on one 24 GB GPU.

Is MiniMind: Train a 64M-Parameter LLM From Scratch free?

MiniMind: Train a 64M-Parameter LLM From Scratch is free to access.

What level is MiniMind: Train a 64M-Parameter LLM From Scratch for?

MiniMind: Train a 64M-Parameter LLM From Scratch is aimed at a intermediate audience. Recommended background: Comfortable Python and working knowledge of PyTorch training loops, Basic understanding of the transformer architecture (attention, tokenization, next-token loss), Access to an NVIDIA GPU with about 24 GB of memory (RTX 3090 class) or a rented cloud GPU; vLLM and SGLang serving need CUDA, Familiarity with SFT, DPO and GRPO concepts helps for the post-training stages.

How long does MiniMind: Train a 64M-Parameter LLM From Scratch take?

Expect roughly ~2.3 GPU-hours for pretrain + SFT (one epoch each) on a single RTX 3090, plus self-paced time to read the code and run LoRA, DPO, RL and agent stages. Most learners work through it at their own pace.

What will I learn from MiniMind: Train a 64M-Parameter LLM From Scratch?

You'll learn: Pretrain a 64M dense decoder with grouped-query attention from random weights using train_pretrain.py; Run full supervised fine-tuning where tool calling and adaptive thinking live in the SFT data and chat template; Train LoRA adapters with train_lora.py and merge them for export with scripts/convert_model.py; Apply DPO preference tuning and RLAIF with PPO, GRPO and the CISPO loss option; Train a multi-turn tool-use agent with GRPO or CISPO through train_agent.py, added in minimind-3; Distill a larger teacher into the small model with white-box distillation combining cross-entropy and KL loss; Build the 198M-A64M mixture-of-experts variant with 4 experts and top-1 routing in the Qwen3-MoE layout; Serve your trained model through an OpenAI-compatible API, vLLM, SGLang, llama.cpp GGUF or Ollama.

Topics

llm-from-scratchpytorchpretraininggrpoloramixture-of-experts

Sources

This page was written from 4 sources, 3 on domains other than github.com.

  1. 1.github.com — minimindvendor
  2. 2.raw.githubusercontent.com — README en.md
  3. 3.wavect.io — minimind training from scratch.md
  4. 4.hn.algolia.com — search