llama2.c is a minimalist implementation of the Llama 2 language model architecture designed to run entirely in pure C. Created by Andrej Karpathy, this project offers an educational and lightweight framework for performing inference on small Llama 2 models without external dependencies. It provides a full training and inference pipeline: models can be trained in PyTorch and later executed using a concise 700-line C program (run.c). While it can technically load Meta’s official Llama 2 models, current support is limited to fp32 precision, meaning practical use is capped at models up to around 7B parameters. The goal of llama2.c is to demonstrate how a compact and transparent implementation can perform meaningful inference even with small models, emphasizing simplicity, clarity, and accessibility. The project builds upon lessons from nanoGPT and takes inspiration from llama.cpp, focusing instead on minimalism and educational value over large-scale performance.

Features

  • Implements the full Llama 2 architecture for both training and inference
  • Provides a compact, 700-line C-based inference engine (run.c)
  • Allows training in PyTorch and running models directly in C
  • Supports fp32 model precision for smaller, educational-scale LLMs
  • Offers a clean, dependency-free implementation for easy study and modification
  • Inspired by llama.cpp but designed for simplicity and minimalism

Project Samples

Project Activity

See All Activity >

License

MIT License

Follow llama2.c

llama2.c Web Site

Other Useful Business Software
Full-stack observability with actually useful AI | Grafana Cloud Icon
Full-stack observability with actually useful AI | Grafana Cloud

Our generous forever free tier includes the full platform, including the AI Assistant, for 3 users with 10k metrics, 50GB logs, and 50GB traces.

Built on open standards like Prometheus and OpenTelemetry, Grafana Cloud includes Kubernetes Monitoring, Application Observability, Incident Response, plus the AI-powered Grafana Assistant. Get started with our generous free tier today.
Create free account
Rate This Project
Login To Rate This Project

User Reviews

Be the first to post a review of llama2.c!

Additional Project Details

Operating Systems

Linux, Mac, Windows

Programming Language

C, Python

Related Categories

Python Large Language Models (LLM), C Large Language Models (LLM)

Registered

2025-10-07