Skip to content

zhang588/llm.c

 
 

Repository files navigation

llm.c

📖 中文学习指南: README.zh-CN.md

LLMs in simple, pure C/CUDA with no need for 245MB of PyTorch or 107MB of cPython. Current focus is on pretraining, in particular reproducing the GPT-2 and GPT-3 miniseries, along with a parallel PyTorch reference implementation in train_gpt2.py.

quick start

# 下载初始包
chmod u+x ./dev/download_starter_pack.sh
./dev/download_starter_pack.sh

# CPU 版本(Mac/Linux)
make train_gpt2
OMP_NUM_THREADS=8 ./train_gpt2

# GPU 版本(需要 NVIDIA CUDA)
make train_gpt2cu
./train_gpt2cu

项目结构

llm.c/
├── train_gpt2.c        # ~1000行 CPU fp32 实现(学习用)
├── train_gpt2.cu      # CUDA 主线训练代码
├── train_gpt2.py      # PyTorch 参考实现
├── dev/
│   ├── cuda/          # 手写 CUDA 内核库
│   └── data/          # 数据处理脚本
├── doc/
│   └── layernorm/     # LayerNorm 教程
├── scripts/            # 多GPU/多节点脚本
└── README.zh-CN.md     # 中文学习指南

主要文件说明

文件 说明 适合人群
train_gpt2.c ~1000行,单文件,CPU实现 初学者学习
train_gpt2.py PyTorch 参考实现 对照理解
train_gpt2.cu CUDA 主线代码 GPU训练
dev/cuda/*.cu 手写kernel 深度优化

Links

license

MIT

About

LLM training in simple, raw C/CUDA

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Cuda 66.2%
  • Python 13.5%
  • C 12.0%
  • C++ 3.9%
  • Shell 2.2%
  • Makefile 1.7%
  • Jupyter Notebook 0.5%