datawhalechina/diy-llm

▲ 312 stars today★ 2,440⑂ 230

Covers pre-training data, Tokenizer, Transformer, MoE,distributed training, Scaling Laws, inference & alignment .6 progressive code assignments for full-stack LLM learning |

About datawhalechina/diy-llm

datawhalechina/diy-llm is an open-source project on GitHub, mainly written in Jupyter Notebook. Covers pre-training data, Tokenizer, Transformer, MoE,distributed training, Scaling Laws It currently holds 2,440 stars and 230 forks with 11 open issues, and was last pushed on 2026-10-29 (repository created 2025-11-24).

Project Overview

Git Homed tracks it on the Today's Trending board, currently at rank #28 with 312 new stars today.

GitHub Repository Details

Repository datawhalechina/diy-llm · default branch main · size 205746 KB · watchers 3 · source: GitHub REST API and repository README

README

https://github.com/datawhalechina/diy-llm/blob/HEAD/alt text

Diy-LLM

https://github.com/datawhalechina/diy-llm/blob/HEAD/简体中文 https://github.com/datawhalechina/diy-llm/blob/HEAD/English

https://github.com/datawhalechina/diy-llm/blob/HEAD/GitHub stars https://github.com/datawhalechina/diy-llm/blob/HEAD/GitHub forks https://github.com/datawhalechina/diy-llm/blob/HEAD/Language https://github.com/datawhalechina/diy-llm/blob/HEAD/GitHub Project

📚 在线阅读地址

📚 带你系统性学习大语言模型

一座为中文学习者量身打造的"LLM炼丹工坊"

我们希望这门 CS336 中文课程,不只是斯坦福原版的"汉化版",而是一座为中文学习者量身打造的"LLM炼丹工坊"。在这里,你亲手锻造理解、打磨代码、调控火候,最终炼出属于自己的大模型真丹。

📋 前置要求

📚 课程愿景

🎯 项目意义

学完这门课,你能得到什么?

📖 课程目录

| 章节 | 关键内容 | 配套作业 | 状态 | |------|----------|----------|------| | 前言 | 项目背景、学习路线、前置知识 | - | ✅ | | 第1章 工具使用 | W&B 实验追踪、超参数搜索、可视化面板 | - | 📝 | | 第2章 分词器 | BPE 算法原理、Unicode 规范化、手写 tokenizer 训练代码 | 作业1 | ✅ | | 第3章 PyTorch 与资源核算 | 混合精度训练、梯度累积、FLOPs/显存估算 | - | ✅ | | 第4章 语言模型架构与训练细节 | RoPE、RMSNorm、SwiGLU、AdamW、Pre-Norm vs Post-Norm、学习率调度 | 作业1 | ✅ | | 第5章 混合专家模型 | Top-K 路由、负载均衡、辅助损失、Expert Parallelism、DeepSeekMoE | - | ✅ | | 第6章 GPU 与相关优化 | 显存带宽与计算强度、Flash Attention、Kernel Fusion、混合精度、BF16/TF32 | 作业2 | ✅ | | 第7章 GPU 高性能编程 | CUDA 编程模型、Tensor Cores、Shared Memory、Triton 入门 | 作业2 | ✅ | | 第8章 分布式训练 | 数据并行/模型并行/流水线并行、ZeRO-1/2/3、FSDP、梯度累积、All-Reduce | 作业2 | ✅ | | 第9章 Scaling Laws | Chinchilla 定律、计算最优配置、Scaling 实验设计、Extrapolation | 作业3 | ✅ | | 第10章 推理 | KV Cache、投机解码、量化 (GPTQ/AWQ)、PagedAttention、Continuous Batching | 作业6 | ✅ | | 第11章 数据工程 | 数据质量过滤、MinHash 去重、PII 脱敏、数据配比、Data Curriculum | 作业4 | ✅ | | 第12章 评估与基准测试 | MMLU、HumanEval、HELM、CEval、AlpacaEval、Arena 排名 | 作业6 | ✅ | | 第13章 大模型的基本训练流程 | Pre-training、SFT、DPO、RLHF PPO 流程、Alignment Tax | 作业5 | ✅ | | 第14章 可验证奖励的强化学习 | GRPO、Rule-based Verifier、Outcome/Process Reward、RLVR 与 R1 训练方案 | 作业5 | ✅ | | 第15章 多模态模型 | 从 CLIP 到 Omni Model:CLIP/SigLIP、LLaVA、Qwen-VL、Chameleon | - | ✅ | | 第16章 扩展内容 | 1. 什么是LLM推理?(黎又榛)
2. LLM 的未来 - Lecun(黎又榛、jiangyinhe、李盛康、徐虎)| - | 🔄 |

状态图例说明:✅ 已完成 🔄 更新中 📝 待完善 🚧 筹备中 ⏸️ 暂缓

📝 作业概览

| 作业 | 核心任务 |状态 | |------|----------|------| | 作业1:手搓大模型 | 实现 tokenizer、model architecture、optimizer,训练一个极简语言模型 | ✅ | | 作业2:系统优化 | 性能分析与基准测试;用 Triton 实现 FlashAttention-2;构建分布式训练代码 | ✅ | | 作业3:扩展定律 | 理解 Transformer 各组件功能;拟合 scaling law 预测模型扩展效果 | ✅ | | 作业4:数据处理 | 将 Common Crawl 原始数据转换为预训练数据集,执行过滤与去重 | ✅ | | 作业5:模型对齐 | 应用 SFT 与强化学习(如 GRPO)训练模型解决数学问题 | ✅ | | 作业6:模型评估 | 使用 lm-evaluation-harness 和 evalscope 进行多维度评测(语言理解、常识推理、代码、数学推理) | ✅ |

🚀 快速开始

# 克隆仓库
git clone https://github.com/datawhalechina/diy-llm.git
cd diy-llm

安装基础依赖(根据具体作业需求安装)

学习路径

1️⃣ 理论学习 → 按章节顺序阅读 docs/zh/ 目录下的中文文档(English version in docs/en/) 2️⃣ 实践练习 → 完成 coursework/ 目录下的 6 个作业 3️⃣ 深入理解 → 阅读代码实现,理解每个组件的设计

项目结构

diy-llm/
├── docs/                    # 在线文档
│   ├── zh/                 # 中文文档(默认)
│   │   ├── 前言.md
│   │   ├── chapter1/       # 工具使用
│   │   ├── chapter2/       # 分词器
│   │   ├── chapter3/       # PyTorch 与资源核算
│   │   ├── chapter4/       # 语言模型架构与训练细节
│   │   ├── chapter5/       # 混合专家模型
│   │   ├── chapter6/       # GPU 与相关优化
│   │   ├── chapter7/       # GPU 高性能编程
│   │   ├── chapter8/       # 分布式训练
│   │   ├── chapter9/       # Scaling Laws
│   │   ├── chapter10/      # 推理
│   │   ├── chapter11/      # 数据工程
│   │   ├── chapter12/      # 评估与基准测试
│   │   ├── chapter13/      # 大模型的基本训练流程
│   │   ├── chapter14/      # 可验证奖励的强化学习
│   │   ├── chapter15/      # 多模态模型
│   │   └── chapter16/      # 前沿扩展内容
│   ├── en/                 # English documentation
│   │   └── ...
│   └── .vitepress/         # VitePress 配置
├── coursework/              # 实践作业
│   ├── assignment1-basics/        # 作业1:手搓大模型
│   ├── assignment2-systems/       # 作业2:系统优化
│   ├── assignment3-scaling/       # 作业3:扩展定律
│   ├── assignment4-data/          # 作业4:预训练数据处理
│   ├── assignment5-alignment/     # 作业5:对齐
│   └── assignment6-evaluation/    # 作业6:评估
├── README.md               # 中文项目说明
├── README_EN.md            # English project overview
└── .gitignore              # Git忽略配置

PDF 版本下载

本教程提供 PDF 版本,方便离线阅读和打印学习。为防止各类营销号加水印后贩卖给 LLM 的读者,我们特地在 PDF 文件中添加了不影响阅读的 Datawhale 开源标志水印,敬请谅解~

📥 Diy-LLM 课程讲义 PDF: https://github.com/datawhalechina/diy-llm/releases/latest/

🔗 相关链接

❓ 常见问题

Q: 没有 GPU 可以学习吗?

理论部分可以正常学习,作业中的部分内容可以在 CPU 上调试,但完整训练需要 GPU。建议使用云服务平台。

Q: 与原版 CS336 有什么区别?

我们在保留原版技术深度的基础上,针对中文学习者进行了本土化改造,包括中文讲解、作业实现、更详细的参考内容来源、国产模型案例等。

💬 读者交流群

欢迎加入 Diy-LLM 读者交流群,与大家一起交流学习、答疑解惑:

https://github.com/datawhalechina/diy-llm/blob/HEAD/读者交流群1二维码
读者交流群1
https://github.com/datawhalechina/diy-llm/blob/HEAD/读者交流群2二维码
读者交流群2

群1满员后可加入群2。如果两个群二维码都过期或已满,可以添加以下任一负责人的微信(备注「diy-llm」),由我们拉你入群:

| 负责人 | 微信号 | |--------|--------| | 徐虎 | xuhu96736 | | 黎又榛 | zydsx111 | | 李盛康 | muzichengminguangli |

👥 贡献者

贡献者名单

https://github.com/datawhalechina/diy-llm/blob/HEAD/pic
徐虎

项目负责人
Datawhale 成员
上海交通大学
负责内容:第1、3、9、12、14、15章;作业5、6;全文内容审核

https://github.com/datawhalechina/diy-llm/blob/HEAD/pic
李盛康

项目负责人
Datawhale 成员
西安邮电大学
负责内容:第4、6、7、8、13章;作业2、4

https://github.com/datawhalechina/diy-llm/blob/HEAD/pic
黎又榛

项目负责人
Datawhale 成员
负责内容:第2、5、10、11、13章;作业1、3;

社区贡献

注:我们感谢每一位为项目做出贡献的开发者,也欢迎社区的小伙伴积极参与贡献!

我们欢迎所有形式的贡献!无论是文档改进、代码优化、bug修复还是新内容添加,都是对项目的宝贵支持。

如何贡献

1. 报告问题:如果发现文档错误、代码bug或改进建议,欢迎提交 Issue 2. 提交代码:Fork 本仓库,创建你的特性分支,提交更改后发起 Pull Request 3. 完善文档:帮助改进文档、翻译内容或添加示例 4. 分享经验:在讨论区分享学习心得和实践经验

贡献指南

📝 更新日志

项目持续更新中,最新进展请查看 GitHub Releases 或提交记录。

📄 许可证

https://github.com/datawhalechina/diy-llm/blob/HEAD/知识共享许可协议

本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。

🙏 致谢

⭐ Star History

如果这个项目对你有帮助,欢迎给个 Star ⭐️!

https://github.com/datawhalechina/diy-llm/blob/HEAD/Star History Chart ---

让更多人能够系统性地学习大语言模型构建技术

Made with ❤️ by the Datawhale

GitHub Stars & Activity

2,440Stars
230Forks
11Open issues
Jupyter NotebookLanguage

GitHub Popularity

GitHub stars2,440
Forks230
Open issues11
Primary languageJupyter Notebook
License-
Stars gained today312
Created2025-11-24
Last pushed2026-10-29

Trending History

Daily boardrank #28 · ▲ 312 stars
Weekly boardrank #72 · ▲ 721 stars

Related GitHub Projects

1

anthropics / claude-cookbooks

Jupyter Notebook★ 53,951⑂ 6,510▲ 53 stars
→
2

DataExpert-io / data-engineer-handbook

Jupyter Notebook★ 44,809⑂ 9,380▲ 115 stars
→
3

microsoft / Data-Science-For-Beginners

Jupyter Notebook★ 37,839⑂ 7,616▲ 41 stars
→
4

NirDiamant / RAG_Techniques

Jupyter Notebook★ 30,136⑂ 3,690▲ 73 stars
→
5

xiaolai / the-craft-of-selfteaching

Jupyter Notebook★ 18,870⑂ 17,942▲ 365 stars
→
6

AI4Finance-Foundation / FinRL

Jupyter Notebook★ 16,887⑂ 3,606▲ 37 stars
→
7

FinanceFlash / unvibecode

Jupyter Notebook★ 701⑂ 119▲ 78 stars
→
8

openclaw / openclaw

TypeScript★ 393,424⑂ 82,694▲ 149 stars
→

More Trending Repositories