MiniMind is an open-source project that trains an ultra-small language model from 0, with the goal of enabling ordinary personal GPUs to quickly complete LLM training and reproduction.
Purpose
The project aims to train the ultra-small language model MiniMind, with a scale of about 64M, completely from 0 using only 3 yuan in cost and 2 hours of training time. It hopes to lower the learning threshold for large language models, allowing everyone to start by understanding every line of code and personally train an extremely small language model, rather than merely staying at the level of inference or fine-tuning.
Main Capabilities
- Provides complete MiniMind-LLM architecture code (Dense + MoE); the current mainline architecture aligns with the Qwen3 / Qwen3-MoE ecosystem.
- Provides Tokenizer and tokenizer training code, supporting
<tool_call>、<tool_response>、<think>and other template markers. - Covers the complete training process including Pretrain, SFT, LoRA, RLHF-DPO, RLAIF (PPO / GRPO / CISPO), Tool Use, Agentic RL, adaptive thinking, and model distillation.
- Provides full-stage open-source data, covering high-quality datasets after collection, distillation, cleaning, and deduplication.
- Key training algorithms and core modules are all implemented from 0, without relying on third-party framework wrappers.
- Compatible with mainstream frameworks such as transformers, trl, and peft, as well as commonly used inference engines such as llama.cpp, vllm, and ollama, and training frameworks such as Llama-Factory.
- Supports single-machine single-GPU and single-machine multi-GPU (DDP, DeepSpeed) training, supports wandb / swanlab visualization, and dynamic start/stop of training.
- Supports evaluation on third-party benchmark sets such as C-Eval, C-MMLU, and OpenBookQA, and supports RoPE long-text extrapolation via YaRN.
- Provides a minimalist server compatible with the OpenAI API protocol, making it easy to integrate with third-party Chat UIs such as FastGPT and Open-WebUI, and supports reasoning_content, tool_calls, and open_thinking.
- Provides a minimalist Streamlit-based chat WebUI, supporting thinking display, tool selection, and multi-turn Tool Call.
- Includes experimental extensions: discrete diffusion language model (dLM) and linear attention model (Linear Attention), both of which can continue training based on the mainline AR model.
Usage
The current mainline of the project recommends using the staged training combination of pretrain_t2t + sft_t2t + rlaif/agent_rl. For quick reproduction, it is recommended to use the data combination of pretrain_t2t_mini.jsonl + sft_t2t_mini.jsonl. All training scripts are executed from the cd ./trainer directory.
Environment Preparation
The code was tested under Python 3.10.16 and a CUDA environment. If you plan to use CUDA for training, it is recommended to first confirm whether the current environment has correctly recognized the GPU. If CUDA is unavailable, you can still choose CPU or MPS operation according to your own device, but trainingspeed and compatibility will differ greatly.
Data Preparation
Download the required data files from the provided download link and place them into ./dataset directory. Currently, by default you only need to download pretrain_t2t_mini.jsonl and sft_t2t_mini.jsonl to quickly reproduce the MiniMind Zero chat model.
Training Pipeline
- Pretraining (Pretrain): Let the model learn basic knowledge and language patterns from a large amount of text. After training, the weights are saved as
pretrain_*.pth. - Supervised Fine-Tuning (SFT): Let the model adapt to interaction forms such as multi-turn dialogue, question answering, tool calling, and thinking tags. After training, the weights are saved as
full_sft_*.pth. - Knowledge Distillation (KD): Divided into black-box distillation and white-box distillation. The project provides
train_distillation.pyas a reference implementation for white-box distillation. - LoRA: Parameter-efficient fine-tuning, updating only a small number of newly added parameters. See the implementation in
model_lora.pyandtrain_lora.py. After training, the weights are saved aslora_xxx_*.pth. You can usescripts/convert_model.pyinconvert_merge_base_lorato merge the LoRA weights back into the base model. - Tool Calling & Adaptive Thinking: The current version no longer separately maintains
reason_*.pthweights, but instead uniformly controls them through chat_template, the<think>tag, and theopen_thinkingadaptive switch. - RLAIF / Agentic RL: Provides algorithms such as PPO, GRPO, and SPO, and adds the native Agentic RL training script
train_agent.py.
Inference and Deployment
The project provides a minimalist server compatible with the OpenAI API protocol, serve_openai_api.py , and a Streamlit-based chat WebUI, web_demo.py, supporting reasoning_content / tool_calls / open_thinking.
All training scripts support checkpoint saving. After adding the --from_resume 1 parameter, training progress can be automatically detected and resumed.
Use Cases
- Introductory learning and practice for large language models: Gain an in-depth understanding of the internal workings of LLMs by implementing core algorithms from scratch.
- Rapid reproduction by individual developers: Train a Zero chat model on a single 3090 in about 2 hours and at a cost of about 3 yuan.
- Algorithm teaching and research: Serve as a reproducible, understandable, and extensible open-source full-stage reproduction project for LLMs.
- Domain adaptation experiments: Transfer the model to private datasets through LoRA or full-parameter fine-tuning.
Limitations
- The model size is extremely small (about 64M for the main line and about 198M-A64M for MoE), and its factual knowledge and generalization performance are still relatively limited.
- “2 hours” refers to the measured time to complete 1 epoch of the SFT stage on a single NVIDIA 3090, and “3 yuan” refers to the GPU rental cost for the corresponding period.
- Retraining the tokenizer is not recommended, because changes to the vocabulary and segmentation rules will affect compatibility with model weights, data formats, inference interfaces, and the community ecosystem.
- For more details, update logs, dataset and weight download links, online experience links, etc., please refer to the project GitHub repository.