Skip to content

llama2.c vs llama3 from scratch

Which should you use? A side-by-side look at what each one does, who it suits, what it costs, how hard it is to set up, and where each falls short.

llama2.c

Open source · MIT

A small C program that runs small Llama 2 language models, with training done in PyTorch.

llama3 from scratch

Open source · MIT

A from-scratch walkthrough of Llama 3 inference in a Jupyter notebook, one tensor operation at a time.

The short answer

Choose llama2.c if you need…

  • Developers who want to see how LLM inference works in plain C
  • Students learning the Llama 2 architecture end to end
  • People experimenting with tiny models trained on narrow datasets like TinyStories
  • Anyone who wants a minimal inference engine with no external dependencies

Choose llama3 from scratch if you need…

  • Learners who understand basic Python and want to see how a transformer works internally
  • Engineers who read model code and want a concrete, tensor-shape-level explanation
  • Students studying attention and positional encoding

Side-by-side

llama2.cllama3 from scratch
TypeOtherLearning resource
PriceFree and open sourceFree and open source
LicenceMITMIT
GitHub stars20.2k15.2k
Setup difficultyIntermediateIntermediate
How you get itClone and build from sourceClone and build from source
Main languageCJupyter Notebook
Last code update2 years ago2 years ago

What each one is

llama2.c

This project runs Llama 2 style language models using a single short C file with no dependencies. The README says you train a model in PyTorch and then run it with that C program. It is mainly built for minimalism and learning how inference works, not for running large models quickly.

llama3 from scratch

This is a Jupyter notebook that rebuilds parts of Meta's Llama 3 language model step by step, loading the official weight file and applying each operation (tokenizing, embedding, normalization, attention) by hand. It is meant to show how a transformer language model turns a text prompt into numbers and then computes with them. The README is truncated, so it covers only the early stages of the walkthrough.

Best for

llama2.c

  • Developers who want to see how LLM inference works in plain C
  • Students learning the Llama 2 architecture end to end
  • People experimenting with tiny models trained on narrow datasets like TinyStories
  • Anyone who wants a minimal inference engine with no external dependencies

llama3 from scratch

  • Learners who understand basic Python and want to see how a transformer works internally
  • Engineers who read model code and want a concrete, tensor-shape-level explanation
  • Students studying attention and positional encoding

Strengths

llama2.c

  • Inference is a single short C file with no dependencies, which makes it easy to read
  • The README includes a full train-plus-inference workflow in one repo
  • Small models trained on narrow data can produce surprisingly coherent output, as shown in the examples

llama3 from scratch

  • Clear, shape-by-shape explanations with diagrams that make the math easier to follow
  • Uses the official Meta weights and config, so the numbers correspond to the real model
  • Short, readable code that is easy to modify and experiment with

Not ideal for

llama2.c

  • People who need to run 7B or larger models, since the README says the code only does float32 inference and 13B+ does not currently work
  • People who need fast production inference, since the README describes it as educational and float32-only
  • People who want a polished, supported product, since the README says the project is young and moving quickly

llama3 from scratch

  • People who want to run Llama 3 for chat or apps; this is an educational walkthrough, not a production inference server, and the README does not cover serving
  • Readers without basic Python or linear algebra, since the explanations assume familiarity with tensors and matrix shapes
  • Anyone looking for a complete implementation; the README says the BPE tokenizer is intentionally skipped and the truncated text covers only the first layer's early steps

Trade-offs

llama2.c

  • The README says only fp32 inference is supported, so large models need a lot of memory and run slowly
  • 13B and larger models do not currently work according to the README
  • Code Llama support is incomplete and the README calls it buggy

llama3 from scratch

  • You must obtain the Meta weights separately, which requires accepting Meta's download terms
  • The README is truncated and says the tokenizer is not implemented from scratch, so it is not a full standalone system
  • Relies on torch and tiktoken, and the weights file is large, so it needs substantial local resources

Getting started

llama2.c

Clone the repository

git clone https://github.com/karpathy/llama2.c.git

Open the repository folder

cd llama2.c
Step-by-step guide: how to use llama2.c

llama3 from scratch

Clone the repository

git clone https://github.com/naklecha/llama3-from-scratch
Step-by-step guide: how to use llama3 from scratch

Frequently asked questions

What is the difference between llama2.c and llama3 from scratch?

llama2.c: A small C program that runs small Llama 2 language models, with training done in PyTorch. llama3 from scratch: A from-scratch walkthrough of Llama 3 inference in a Jupyter notebook, one tensor operation at a time. llama2.c suits developers who want to see how llm inference works in plain c, while llama3 from scratch suits learners who understand basic python and want to see how a transformer works internally.

Are llama2.c and llama3 from scratch free?

llama2.c: Free and open source. llama3 from scratch: Free and open source.

Is llama2.c or llama3 from scratch more popular?

llama2.c has more GitHub stars (20.2k) than llama3 from scratch (15.2k). Popularity isn't the same as fit — check which one matches your use case above.

What are other alternatives to llama2.c and llama3 from scratch?

Other options people compare them with include llama.cpp, minbpe.

Keep comparing

Built from our catalogue entries for both products: open-source details come from each project's README (AI-assisted, refreshed weekly) and GitHub data; AI-tool details are editorial. Spotted something wrong? Let us know from either product's page.