This repository contains my implementations for all assignments from Stanford's CS336: Language Modeling from Scratch course (Spring 2025). The course covers the fundamentals of building, training, and deploying large language models.
CS336 provides a comprehensive, hands-on approach to understanding language models by implementing them from the ground up. Topics include model architecture, systems optimization, scaling laws, data processing, and alignment techniques.
Core Topics: Tokenization, Transformer Architecture, Language Model Training
Implementation of fundamental language modeling components:
Note: CPU parallel tokenizer training is not implemented in this assignment.
Core Topics: Performance Optimization, Distributed Training, Systems Engineering
Deep dive into efficient LM training systems:
Note: Distributed parallel training components are not implemented in this assignment.
Core Topics: Scaling Laws, Compute-Optimal Training, Model Scaling
Exploration of scaling behaviors in language models:
Note: Due to the lack of official API access, this assignment could not be fully tested. It is recommended to use custom synthetic datasets or publicly available datasets for verification.
Core Topics: Data Curation, Quality Filtering, Dataset Construction
Building high-quality training datasets:
Note: This assignment was completed using smaller datasets. Large-scale dataset training was not performed.
Core Topics: RLHF, Preference Learning, Model Safety
Aligning language models with human preferences:
Note: The supplemental assignment on safety RLHF has not been implemented yet. Stay tuned for future updates!
.
├── assignment1-basics/ # Fundamental LM implementation
├── assignment2-systems/ # Systems optimization
├── assignment3-scaling/ # Scaling law investigations
├── assignment4-data/ # Data processing pipeline
├── assignment5-alignment/ # Alignment techniques
└── README.md # This file
Each assignment directory contains:
torch - Deep learning frameworkflash-attn - Optimized attention implementationeinops - Tensor operationswandb - Experiment trackinguv for dependency management:# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# or via pip
pip install uv
# or via Homebrew
brew install uv
Each assignment is self-contained. Navigate to the assignment directory and use uv run:
cd assignment1-basics
uv run pytest # Run tests
uv run python scripts/train.py # Run training script
Dependencies are automatically installed based on each assignment's pyproject.toml.
Through these assignments, I gained practical experience in:
This code is provided for educational purposes. Please refer to individual assignment directories for specific licensing information.
本仓库包含我完成的斯坦福大学 CS336《从零开始的语言模型》课程(2025年春季)的所有作业实现。该课程涵盖了构建、训练和部署大型语言模型的基础知识。
CS336 提供了一种全面的实践方法来理解语言模型,通过从头实现来深入掌握。主题包括模型架构、系统优化、缩放定律、数据处理和对齐技术。
核心主题: 分词、Transformer架构、语言模型训练
实现语言建模的基础组件:
注意: 本作业未实现CPU并行分词器训练。
核心主题: 性能优化、分布式训练、系统工程
深入研究高效的语言模型训练系统:
注意: 本作业未实现分布式并行训练组件。
核心主题: 缩放定律、计算最优训练、模型扩展
探索语言模型中的缩放行为:
注意: 由于缺乏官方API访问权限,本作业无法完全测试。建议使用自定义合成数据集或公开可用的数据集进行验证。
核心主题: 数据管理、质量过滤、数据集构建
构建高质量的训练数据集:
注意: 本作业使用较小的数据集完成。未进行大规模数据集训练。
核心主题: RLHF、偏好学习、模型安全
使语言模型与人类偏好对齐:
注意: 安全RLHF补充作业尚未实现。敬请期待后续更新!
.
├── assignment1-basics/ # 基础语言模型实现
├── assignment2-systems/ # 系统优化
├── assignment3-scaling/ # 缩放定律研究
├── assignment4-data/ # 数据处理pipeline
├── assignment5-alignment/ # 对齐技术
└── README.md # 本文件
每个作业目录包含:
torch - 深度学习框架flash-attn - 优化的注意力实现einops - 张量操作wandb - 实验跟踪uv 进行依赖管理:# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# 或通过 pip
pip install uv
# 或通过 Homebrew
brew install uv
每个作业都是独立的。进入作业目录并使用 uv run:
cd assignment1-basics
uv run pytest # 运行测试
uv run python scripts/train.py # 运行训练脚本
依赖项会根据每个作业的 pyproject.toml 自动安装。
通过这些作业,我获得了以下实践经验:
本代码仅供教育目的使用。具体许可信息请参考各作业目录。
3 commits
Python
96.9%
PowerShell
1.7%
Shell
1.4%
This repository contains my implementations for all assignments from Stanford's CS336: Language Modeling from Scratch course (Spring 2025). The course covers the fundamentals of building, training, and deploying large language models.
CS336 provides a comprehensive, hands-on approach to understanding language models by implementing them from the ground up. Topics include model architecture, systems optimization, scaling laws, data processing, and alignment techniques.
Core Topics: Tokenization, Transformer Architecture, Language Model Training
Implementation of fundamental language modeling components:
Note: CPU parallel tokenizer training is not implemented in this assignment.
Core Topics: Performance Optimization, Distributed Training, Systems Engineering
Deep dive into efficient LM training systems:
Note: Distributed parallel training components are not implemented in this assignment.
Core Topics: Scaling Laws, Compute-Optimal Training, Model Scaling
Exploration of scaling behaviors in language models:
Note: Due to the lack of official API access, this assignment could not be fully tested. It is recommended to use custom synthetic datasets or publicly available datasets for verification.
Core Topics: Data Curation, Quality Filtering, Dataset Construction
Building high-quality training datasets:
Note: This assignment was completed using smaller datasets. Large-scale dataset training was not performed.
Core Topics: RLHF, Preference Learning, Model Safety
Aligning language models with human preferences:
Note: The supplemental assignment on safety RLHF has not been implemented yet. Stay tuned for future updates!
.
├── assignment1-basics/ # Fundamental LM implementation
├── assignment2-systems/ # Systems optimization
├── assignment3-scaling/ # Scaling law investigations
├── assignment4-data/ # Data processing pipeline
├── assignment5-alignment/ # Alignment techniques
└── README.md # This file
Each assignment directory contains:
torch - Deep learning frameworkflash-attn - Optimized attention implementationeinops - Tensor operationswandb - Experiment trackinguv for dependency management:# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# or via pip
pip install uv
# or via Homebrew
brew install uv
Each assignment is self-contained. Navigate to the assignment directory and use uv run:
cd assignment1-basics
uv run pytest # Run tests
uv run python scripts/train.py # Run training script
Dependencies are automatically installed based on each assignment's pyproject.toml.
Through these assignments, I gained practical experience in:
This code is provided for educational purposes. Please refer to individual assignment directories for specific licensing information.
本仓库包含我完成的斯坦福大学 CS336《从零开始的语言模型》课程(2025年春季)的所有作业实现。该课程涵盖了构建、训练和部署大型语言模型的基础知识。
CS336 提供了一种全面的实践方法来理解语言模型,通过从头实现来深入掌握。主题包括模型架构、系统优化、缩放定律、数据处理和对齐技术。
核心主题: 分词、Transformer架构、语言模型训练
实现语言建模的基础组件:
注意: 本作业未实现CPU并行分词器训练。
核心主题: 性能优化、分布式训练、系统工程
深入研究高效的语言模型训练系统:
注意: 本作业未实现分布式并行训练组件。
核心主题: 缩放定律、计算最优训练、模型扩展
探索语言模型中的缩放行为:
注意: 由于缺乏官方API访问权限,本作业无法完全测试。建议使用自定义合成数据集或公开可用的数据集进行验证。
核心主题: 数据管理、质量过滤、数据集构建
构建高质量的训练数据集:
注意: 本作业使用较小的数据集完成。未进行大规模数据集训练。
核心主题: RLHF、偏好学习、模型安全
使语言模型与人类偏好对齐:
注意: 安全RLHF补充作业尚未实现。敬请期待后续更新!
.
├── assignment1-basics/ # 基础语言模型实现
├── assignment2-systems/ # 系统优化
├── assignment3-scaling/ # 缩放定律研究
├── assignment4-data/ # 数据处理pipeline
├── assignment5-alignment/ # 对齐技术
└── README.md # 本文件
每个作业目录包含:
torch - 深度学习框架flash-attn - 优化的注意力实现einops - 张量操作wandb - 实验跟踪uv 进行依赖管理:# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# 或通过 pip
pip install uv
# 或通过 Homebrew
brew install uv
每个作业都是独立的。进入作业目录并使用 uv run:
cd assignment1-basics
uv run pytest # 运行测试
uv run python scripts/train.py # 运行训练脚本
依赖项会根据每个作业的 pyproject.toml 自动安装。
通过这些作业,我获得了以下实践经验:
本代码仅供教育目的使用。具体许可信息请参考各作业目录。
3 commits
Python
96.9%
PowerShell
1.7%
Shell
1.4%