SuperAPI AI Directory

minimind

MiniMind is an open-source project for training an ultra-small language model from scratch. It aims to lower the barriers to learning and reproducing large language models (LLMs), enabling even ordinary personal GPUs to complete training quickly. The smallest version of the project's mainline has about 64M parameters, roughly 1/2700 the size of GPT-3, and can be reproduced on a single 3090 with only about 3 yuan in cost and 2 hours of training time. The project open-sources a minimalist model architecture and a complete training pipeline, covering the full process code for MoE, data cleaning, pretraining, supervised fine-tuning, LoRA, RLHF (DPO), RLAIF (PPO/GRPO/CISPO), Tool Use, Agentic RL, adaptive thinking, and model distillation. All core algorithms are implemented natively in PyTorch and do not rely on third-party high-level abstraction interfaces. This is not only an open-source full-stage reproduction project for large language models, but also a tutorial for LLM beginners and practitioners. It is open-sourced under the Apache 2.0 license and is completely free.

Open website

About this tool

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

  1. 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.
  2. 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.
  3. Knowledge Distillation (KD): Divided into black-box distillation and white-box distillation. The project provides train_distillation.py as a reference implementation for white-box distillation.
  4. LoRA: Parameter-efficient fine-tuning, updating only a small number of newly added parameters. See the implementation in model_lora.py and train_lora.py. After training, the weights are saved as lora_xxx_*.pth. You can use scripts/convert_model.py in convert_merge_base_lora to merge the LoRA weights back into the base model.
  5. Tool Calling & Adaptive Thinking: The current version no longer separately maintains reason_*.pth weights, but instead uniformly controls them through chat_template, the<think> tag, and theopen_thinking adaptive switch.
  6. 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.