$ show jingyaogong/minimind
MiniMind is an educational open-source toolkit for training small language models entirely from scratch using native PyTorch. It provides a complete pipeline including custom BPE tokenizer training, pretraining, supervised fine-tuning (SFT), LoRA, RLHF (DPO), RLAIF (PPO/GRPO/CISPO), agentic reinforcement learning, and knowledge distillation. The system is designed to be accessible (low compute cost, ~3 RMB and 2 hours on a single GPU) and includes inference interfaces such as a CLI, Streamlit web UI, and an OpenAI-compatible API server. While primarily a software application for training and deploying LLMs, it also contains dataset preparation, evaluation benchmarks, and research experiments, giving it a hybrid character that leans toward application due to its focus on providing reusable training scripts and deployment tools.
The LLM identified 3 files worth highlighting for reuse:
A self-contained LoRA implementation using forward hooks that can be applied to any nn.Linear layer. It provides functions to apply, load, save, and merge LoRA weights without modifying the original model architecture. The module is isolated (imports only PyTorch) and reusable across different PyTorch models for parameter-efficient fine-tuning.
An abstract base class for rollout generation in reinforcement learning training, with two concrete implementations: TorchRolloutEngine (local generation using model.forward) and SGLangRolloutEngine (distributed generation via HTTP). This design decouples the training loop from the rollout mechanism, enabling easy switching between backends without changing the training code. The pattern is reusable for any RL training pipeline that requires sampling from a policy.
Contains a self-contained safe_math_eval function that evaluates arithmetic expressions using Python's ast module to prevent arbitrary code execution. It only allows numeric operations and a whitelist of functions (e.g., sqrt, sin, log). This utility is isolated, has no internal dependencies, and can be extracted into any project that requires safe evaluation of user-provided mathematical expressions.