llama2.c is an open-source project by Andrej Karpathy that runs inference for Meta’s Llama 2 language models in a single file of pure C โ roughly a thousand lines with no dependencies. With more than 20,100 stars on GitHub, it has become a beloved reference for anyone who wants to understand exactly how a transformer model loads weights and generates text, stripped of framework magic. The repository was last updated in 2024 and remains a stable, finished piece of work.
The project pairs a compact C inference engine (llama2.c, plus an OpenMP variant for multi-core speed) with a PyTorch training codebase that trains small Llama 2 architectures from scratch on datasets such as TinyStories. Pre-trained checkpoints from 15M to 110M parameters can be downloaded and run immediately, while the original Meta Llama 2 weights (7B and up) can be exported into the same simple binary format. The result is an end-to-end, hackable pipeline that covers tokenization, training, and fast CPU inference in code a single person can read in an afternoon.
llama2.c is completely free and open source under the MIT license.
llama2.c is perfect for students, educators, and engineers who want to learn how LLM inference really works, and for hobbyists who enjoy running language models in the most minimal environment possible. Its clarity has also made it a popular starting point for ports, experiments, and tiny on-device language model projects of every kind.