Skip to content
r.

llama2.c

karpathy/llama2.c · Public GitHub repository

Inference Llama 2 in one file of pure C

Open project in RepoShelf

Open the project to try its demo, view the repository, or save it to your collection. Repository and demo actions use RepoShelf’s sign-in flow.

llama2.c live demo screenshot
Captured from the live demo · 2026-11-01

About this project

Author-written excerpt from the project README.

Have you ever wanted to inference a baby Llama 2 model in pure C? No? Well, now you can!

Train the Llama 2 LLM architecture in PyTorch then inference it with one simple 700-line C file (run.c). You might think that you need many billion parameter LLMs to do anything useful, but in fact very small LLMs can have surprisingly strong performance if you make the domain narrow enough (ref: TinyStories paper). This repo is a "fullstack" train + inference solution for Llama 2 LLM, with focus on minimalism and simplicity.

As the architecture is identical, you can also load and inference Meta's Llama 2 models. However, the current code only inferences models in fp32, so you will most likely not be able to productively load models larger than 7B. Work on model quantization is currently ongoing.

Requirements and intended audience

Have you ever wanted to inference a baby Llama 2 model in pure C? No? Well, now you can!

Not recorded: account, external api key, paid service, self-hosting. Missing information does not mean there are no requirements.

Statements extracted from the author’s documentation · Checked 2026-11-01. Source: https://github.com/karpathy/llama2.c/blob/master/README.md

Recorded maintenance information

Last recorded source update: 2024-08-06. A published release has not been recorded. These dates do not guarantee ongoing maintenance.

Technologies
C
Licence
MIT. Generally permits modification and commercial use, subject to the licence’s notices and conditions.
Demo check
A public page loaded on 2026-11-20. This does not test every feature.

Browse related categories