charent/Phi2-mini-Chinese
Phi2-Chinese-0.2B 从0开始训练自己的Phi2中文小模型,支持接入langchain加载本地知识库做检索增强生成RAG。Training your own Phi2 small chat model from scratch.
What it solves
该项目解决的是从零训练一个小规模(0.2B参数)中文因果语言模型的问题。它提供了一套完整的数据清洗、分词器训练、预训练、指令微调和偏好优化的代码与流程,让研究者或开发者能够在这个规模上复现类似 Phi-2 的中文模型训练实验。
How it works
项目基于 Phi-2 架构,使用因果语言建模(CLM)进行无监督预训练。训练流程分为几个阶段:
- 数据清洗:去除重复文本、繁体转简体、标准化标点和 Unicode 字符。
- 分词器训练:提供 char level 和 byte level 两种 BPE 分词器训练代码,训练后需检查特殊符号是否完整。
- 预训练:用大量中文文本(如 BELLE 数据集)进行自回归预训练,每个文档末尾添加 [EOS] 标记。
- 指令微调(SFT):使用固定格式(##提问: ... ##回答: ...)构造数据,并忽略回答标记之前的部分损失。
- DPO 优化:使用 prompt、chosen、rejected 三列数据,参考模型不更新参数,进行偏好对齐。
代码统一通过 uv 管理依赖,提供训练脚本(bash/bat),并支持 flash attention 2 加速。模型权重在 Hugging Face 上开源,可直接用于对话或 RAG 演示。
Who it’s for
适合对中文小模型训练感兴趣的机器学习工程师、研究者和爱好者,尤其希望从零开始了解预训练、SFT、DPO 全流程的人。它也是一个实验项目,不保证生产级效果。
Highlights
- 完整训练流水线:数据清洗 → 分词器训练 → 预训练 → SFT → DPO
- 支持两种 tokenizer 训练方式(char/byte level)
- 提供对话 demo 和 RAG(Retrieval-Augmented Generation)演示
- 代码模块化,使用 uv 统一依赖管理,易复现
- 模型权重开源(0.2B 参数,中文)
Related
- Project
YuChuang1205/PALPAL is a framework for detecting small infrared targets using only single-point labels. It uses progressive active learning (easy-to-hard training) and integrates many networks and datasets. The code allows easy switching between models, datasets, and label types. It provides pre-processed datasets, training/testing scripts, and evaluation tools. The project was accepted at ICCV 2025 and welcomes community contributions.
- Project
TBC-TJU/MetaBCIMetaBCI is an open-source platform that makes brain-computer interface research easier by providing unified data loading, preprocessing tools, modern decoding algorithms, and real-time experiment support — all in Python.
- Project
qlabs-eng/slowrunNanoGPT Slowrun is a benchmark that evaluates language‑model training when the data is fixed (100 M tokens) but compute is effectively unlimited. Four tracks (15 min, 1 h, 2 h, unlimited) let participants experiment with heavy regularisation, large models, and exotic optimisers. The repo provides data‑prep scripts, training code for each track, and a world‑record table that logs every improvement (e.g., swiglu, U‑Net, meta‑gradients, ensembles). To try it, clone the repo, install the Python requirements, run `prepare_data.py`, then launch training with `torchrun` on an 8‑GPU H100 node. Submit a PR with a lower validation loss to claim a spot on the leaderboard.
- Project
google-deepmind/simplyA minimal and scalable JAX-based codebase for frontier LLM research designed for rapid iteration by both human researchers and AI agents.