llm.c: LLM pretraining in plain C and CUDA, without PyTorch
llm.c is a program that pretrains GPT-2 and GPT-3 style language models using plain C and CUDA code instead of PyTorch.
According to the README, llm.c is a project for LLM pretraining written in simple, pure C and CUDA, with a current focus on reproducing the GPT-2 and GPT-3 miniseries. The author says it avoids roughly 245MB of PyTorch and 107MB of cPython. The author also writes that the mainline CUDA code is a bit faster than PyTorch Nightly, by about 7%. A parallel PyTorch reference, train_gpt2.py, sits alongside it. A CPU fp32 version in about 1,000 lines of C, train_gpt2.c, is meant for reading.
Running it means downloading starter files with a script, then building with make and running the binary. The README's CPU example fine-tunes the GPT-2 124M weights for 40 steps on tinyshakespeare. The author says it will not get far on CPU unless the machine is beefy. Multi-GPU runs need MPI and NCCL. cuDNN flash attention is optional and off by default because it lengthens compilation. Multi-node training has three documented ways to set up NCCL, and the README notes that none is superior.
The author says the root code should stay simple and readable. The dev/cuda folder is meant as an educational library of hand-written kernels, measured against cuBLAS as an expert upper bound. Ports to other languages are kept in separate repos and listed in the README. The project is under the MIT licence.
In the author's words
LLMs in simple, pure C/CUDA with no need for 245MB of PyTorch or 107MB of cPython.
From the README or the author's post. We checked that the sentence is there, not that it is true.
When to reach for it
Reach for it when you want to read a complete GPT-2 training loop in C and CUDA, or to benchmark a hand-written kernel against cuBLAS and cuDNN, as the author suggests.
See it
AI wrote this entry from the project's own README or its author's post. What the project does, and that AI built it where the entry says so, are the author's statements, quoted here. Nobody at IKANGAI ran or tested it. How this list is made