TL;DR
LLaMA is a family of causal transformer language models, from 7B to 65B parameters, trained on 1 to 1.4 trillion tokens drawn only from publicly available data. The bet is that a smaller model trained on far more tokens than the training-compute recipe recommends is cheaper to run for every user and still competitive. LLaMA-13B beats GPT-3 (175B) on most of the paper's benchmarks, and LLaMA-65B lands close to Chinchilla-70B and PaLM-540B.
Where you'll see it: the first strong open-weight base model. Most open LLMs released after it, and the many fine-tuned chat models built on its weights, follow its architecture and training recipe.
The problem
By 2023 the scaling literature gave a clear answer to a narrow question. Scaling laws and the Chinchilla results (Hoffmann et al., 2022) say that for a fixed training compute budget, the best loss comes from balancing parameters against tokens. Their rule of thumb was about 20 training tokens per parameter. A 70B model trained on 1.4T tokens followed that rule, and it became the reference point for the field.
That answer ignores the other cost of a model, which is inference. A model that will answer millions of queries is paid for every time it runs. If you spend extra training compute to make a smaller model as good as a larger one, the larger model's inference bill is saved on every request afterwards. The paper's question is therefore not "what is the best loss for a training budget" but "what is the best model for a given inference budget, however many tokens it takes to get there."
The paper also had a second problem. The strongest models of the time, GPT-3, Gopher, Chinchilla and PaLM, were closed. Their weights and, in most cases, their training data were not available. The authors wanted to show that state-of-the-art results could come from public data alone.
Key idea
Train a family of models of different sizes, each on many more tokens than the scaling recipe calls for, using only data that could be released. Then measure them on standard benchmarks.
The pipeline is ordinary; the choices are the point.
flowchart LR A[Public data mixture, about 1.4T tokens] --> B[BPE tokenizer, digits split] B --> C[Decoder-only transformer, 7B to 65B] C --> D[AdamW with cosine schedule] D --> E[Zero-shot and few-shot evaluation] E --> F[Release weights to researchers]
The model is trained past the point where a compute-optimal recipe would stop. The 7B model (6.7B parameters in the paper's Table 2) sees 1.0T tokens, which is about 149 tokens per parameter. The 65B model sees 1.4T tokens, about 21.5 per parameter. Those extra tokens cost training time, but they are paid once. The result is a model that is small enough to serve on modest hardware.
The method
Training data
The corpus is a mixture of public sources. Sampling proportions, as reported in the paper's Table 1, are:
| Source | Share of training mix | Notes |
|---|---|---|
| English CommonCrawl | 67.0% | Five dumps from 2017 to 2020, processed with the CCNet pipeline, filtered to pages resembling Wikipedia references |
| C4 | 15.0% | Public cleaned crawl, with heuristic quality filters |
| GitHub | 4.5% | Only Apache, BSD and MIT licensed projects, deduplicated at file level |
| Wikipedia | 4.5% | June to August 2022 dumps, 20 languages in Latin or Cyrillic script |
| Books | 4.5% | Project Gutenberg and the Books3 section of The Pile, deduplicated at book level |
| arXiv | 2.5% | LaTeX sources, with the preamble and bibliography removed |
| StackExchange | 2.0% | 28 largest sites, HTML stripped, answers sorted by score |
Most of the mixture is web text, and the paper leans on the fact that each source is license-compatible for open release. Wikipedia and Books are repeated for about two epochs. Most other data is seen about once.
The tokenizer is byte-pair encoding from SentencePiece. Two details matter for later results. Every digit is its own token, so arithmetic is tokenized one digit at a time. Unknown UTF-8 characters fall back to raw bytes, so no input is out of vocabulary. The whole corpus is about 1.4T tokens after tokenization. See Subword Tokenization for the general idea.
Architecture
The network is a standard decoder-only Transformer. The paper changes three parts of the block, each taken from a published model.
Pre-normalization with RMSNorm. Normalization happens on the input of each sub-layer, not on its output, following GPT-3. The normalizer is RMSNorm instead of Layer Normalization. For a vector of length , with a learned gain ,
RMSNorm drops the mean subtraction of layer norm. It is cheaper, and in practice it trains as stably.
SwiGLU in the feed-forward block. The ReLU non-linearity is replaced by SwiGLU, following PaLM. With input and two weight matrices and , the gated unit is
where is the logistic sigmoid and is element-wise multiplication. Because the gate adds a third matrix, the hidden width is set to two thirds of the usual , which keeps the parameter count comparable. See Activation Function.
Rotary embeddings instead of absolute positions. The learned absolute position embeddings are removed. Instead, each attention layer rotates its query and key vectors by an angle that depends on token position. That is RoPE, borrowed from GPTNeo and the RoFormer line of work. The attention score between positions and then depends only on the offset .
The four sizes are given below, as listed in the paper's Table 2.
| Model | Dimension | Heads | Layers | Peak learning rate | Batch size | Training tokens |
|---|---|---|---|---|---|---|
| 7B | 4096 | 32 | 32 | 3.0e-4 | 4M | 1.0T |
| 13B | 5120 | 40 | 40 | 3.0e-4 | 4M | 1.0T |
| 33B | 6656 | 52 | 60 | 1.5e-4 | 4M | 1.4T |
| 65B | 8192 | 64 | 80 | 1.5e-4 | 4M | 1.4T |
Table 2 itself lists the exact sizes 6.7B, 13.0B, 32.5B and 65.2B, and the rest of the paper rounds them to 7B, 13B, 33B and 65B. Each size is a single architecture scaled in width and depth, with no mixture of experts.
Optimization
Training uses AdamW with and . AdamW is the Adam Optimizer with weight decay applied directly to the weights rather than mixed into the gradient. The update for step with learning rate and decay is
where and are bias-corrected running averages of the gradient and its square. The paper uses weight decay , gradient norm clipping at 1.0 (see Gradient Norm Clipping), and 2,000 linear warm-up steps. The learning rate follows a cosine decay that ends at 10% of its peak. Peak rates and batch sizes are set per model size, as in the table above.
Efficient implementation
The paper spends a full subsection on speed, since the cost of training 65B on 1.4T tokens is the main constraint.
- Causal attention without wasted work. The attention kernel from the xformers library does not store the attention weight matrix and does not compute the masked-out query-key scores. It uses the FlashAttention-style backward pass (see FlashAttention: Fast and Memory-Efficient Exact Attention).
- Selective activation checkpointing. Rather than recomputing everything in the backward pass, the code saves activations that are expensive to recompute, such as linear-layer outputs. The backward pass for transformer layers is written by hand rather than left to autograd.
- Parallelism and overlap. Model and sequence parallelism reduce memory per GPU. Communication, mostly all-reduce, is overlapped with computation as far as possible.
The reported throughput for 65B is about 380 tokens per second per GPU on 2,048 A100 GPUs with 80 GB of memory. Training on the full 1.4T tokens therefore takes about 21 days.
Results
The paper evaluates 20 benchmarks in zero-shot and few-shot settings. Baselines are closed models taken from their own papers (GPT-3, Gopher, Chinchilla, PaLM) and open models (OPT, GPT-J, GPT-Neo). Multiple-choice tasks score each option by its likelihood, normalized by length.
Common sense reasoning (zero-shot, Table 3). The paper's text says LLaMA-65B beats Chinchilla-70B on all reported benchmarks but BoolQ, and beats PaLM-540B everywhere but BoolQ and WinoGrande. The table agrees on PaLM, but not on Chinchilla: its BoolQ entries are 85.3 for LLaMA-65B and 83.7 for Chinchilla, so by the table LLaMA-65B is ahead on every Chinchilla benchmark, BoolQ included. The text is the one that is wrong. LLaMA-13B beats GPT-3 on most tasks while being more than 10 times smaller (the paper says 10 times; 175B over 13B is about 13). On BoolQ, LLaMA-65B scores 85.3 and PaLM-540B scores 88.0. On HellaSwag, LLaMA-65B scores 84.2.
Closed-book question answering. On NaturalQuestions (exact match, Table 4), LLaMA-65B reaches 39.9 at 64-shot, against 35.5 for Chinchilla, 29.9 for GPT-3 and 39.6 for PaLM-540B, so the lead over PaLM is only 0.3. At zero shot the paper's text calls LLaMA-65B state of the art, but within LLaMA the 33B model is best at 24.9 against 23.8 for 65B. On TriviaQA (Table 5), LLaMA-65B reaches 68.2 zero-shot and 73.0 at 64-shot, state of the art among the compared models. The paper highlights that LLaMA-13B, which runs on a single V100 at inference time, is competitive with GPT-3 and Chinchilla here.
Reading comprehension. On RACE-high, LLaMA-65B scores 51.6 zero-shot, the best in Table 6. On RACE-middle it scores 67.9, close to PaLM-540B at 68.1.
Mathematics. Neither PaLM nor LLaMA is fine-tuned on math, while Minerva is. On GSM8k, LLaMA-65B scores 50.9 greedy and 69.7 with majority voting over 100 samples, Minerva-62B scores 52.4 greedy and 68.5 voted. The paper's text says LLaMA-65B outperforms Minerva-62B on GSM8k, but the table supports that only for the voted number (69.7 against 68.5); greedy, Minerva is ahead (52.4 against 50.9). The voted runs also differ in sample count: for LLaMA and Minerva-62B on GSM8k, against for Minerva-540B. On the harder MATH benchmark LLaMA is far behind: 10.6 for 65B against 33.6 for Minerva-540B.
Code. On HumanEval pass@1, LLaMA-65B scores 23.7, ahead of PaLM-62B at 15.9 and close to PaLM-540B at 26.2. On MBPP pass@1 it scores 37.7, slightly above PaLM-540B at 36.8. Even the 13B model beats LaMDA-137B on both benchmarks. The paper notes that code-specialized fine-tuning would widen the gap; it does not do that.
MMLU (5-shot, Table 9). This is the weak spot. LLaMA-65B averages 63.4, behind Chinchilla at 67.5 and PaLM-540B at 69.3. The authors suspect the books share. Their book and paper corpora total about 177 GB, while the comparison models were trained on up to about 2 TB of books.
Training dynamics (Figure 2). On most benchmarks, accuracy rises steadily during training and tracks the training perplexity. The exceptions are SIQA, which is noisy enough that the authors question it as a benchmark, and WinoGrande, where 33B and 65B perform similarly despite different perplexities.
Instruction tuning (Section 4). A short instruction fine-tune of 65B, called LLaMA-I, reaches 68.9 on MMLU. The authors call this a single experiment. It beats other instruction-tuned models of moderate size (Flan-PaLM-cont 62B at 66.1), but the paper notes it is still far from the 77.4 reported for GPT code-davinci-002.
The table below collects the headline numbers the paper itself emphasizes, to make the scale comparison concrete.
| Benchmark | LLaMA-13B | LLaMA-65B | Closed comparison |
|---|---|---|---|
| BoolQ, zero-shot | 78.1 | 85.3 | GPT-3 175B: 60.5 |
| NaturalQuestions, 64-shot | 31.9 | 39.9 | Chinchilla 70B: 35.5 |
| TriviaQA, 64-shot | 64.0 | 73.0 | Chinchilla 70B: 64.6 |
| MMLU, 5-shot average | 46.9 | 63.4 | Chinchilla 70B: 67.5 |
Why it mattered
The paper's central claim was that public data is enough to reach frontier-adjacent quality. For many researchers who could not use closed APIs, LLaMA was the first base model they could download, run locally, fine-tune and study. The weights were released under a research-only license, and within weeks of release variants of LLaMA appeared that were tuned for instruction following and chat on small budgets.
The architecture choices also spread. RMSNorm, SwiGLU, rotary embeddings and pre-normalization became a common default in later open models. The inference-first framing shaped how many groups size their models: a smaller model trained for longer can be the better product even when it is not the better research result at a fixed training budget.
The paper's limits set the agenda that followed. Its MMLU gap was blamed on data, its toxicity and bias evaluations were acknowledged as incomplete, and its carbon table (about 173 tCO2eq for the 65B run, against 137 for OPT-175B and 183 for BLOOM-175B) put training cost beside energy use. Later releases made larger and more deliberately curated models, and some of the "trained longer than the scaling recipe" logic was revisited in later compute-optimal work.
Reading guide
Read the paper in this order, pausing at the prerequisites that each section relies on.
- Section 1, Introduction. Needs Neural Scaling Laws and Compute-Optimal Training for the training versus inference argument. Read it for the claim, not for the numbers yet.
- Section 2.1, Pre-training data. Needs Language Model for what the training objective is, and Subword Tokenization for the digit-splitting and byte-fallback details in the tokenizer paragraph.
- Section 2.2, Architecture. Needs Transformer (the block being modified), Layer Normalization (the thing RMSNorm replaces), Activation Function (ReLU versus SwiGLU), and Rotary Position Embedding together with Positional Encoding for the change from absolute positions.
- Section 2.3, Optimizer. Needs Adam Optimizer and Gradient Norm Clipping. The weight decay term is the part of AdamW that differs from plain Adam.
- Section 2.4, Efficient implementation. Needs FlashAttention: Fast and Memory-Efficient Exact Attention for the attention kernel. The rest is systems engineering and needs no further prerequisites.
- Section 3, Main results. Needs Cross-Entropy Loss for the likelihood-based multiple-choice scoring, and In-Context Learning for the few-shot prompting setup. Language Models are Few-Shot Learners (GPT-3) and Training Compute-Optimal Large Language Models (Chinchilla) are the baselines and are worth reading first.
- Sections 4 to 6. Instruction tuning and the bias and carbon sections can be read independently of the method.
Check yourself
QuestionRecall: what is the main change LLaMA makes to the position information in each attention layer, compared with the original transformer?Show answer
The original transformer adds learned or sinusoidal absolute position embeddings to the input. LLaMA removes absolute position embeddings and instead rotates the query and key vectors in every attention layer by a position-dependent angle (rotary embeddings). The attention score between two tokens then depends on their relative offset.
QuestionComputation: the 65B model is trained on 1.4 trillion tokens. How many tokens per parameter is that, and how does it compare with the 7B model trained on 1.0 trillion tokens?Show answer
For 65B: 1.4e12 divided by 65e9 is about 21.5 tokens per parameter. For the 7B model (6.7B parameters exactly): 1.0e12 divided by 6.7e9 is about 149 tokens per parameter. The 7B model is trained on roughly seven times more tokens per parameter than the 65B model. That is the inference-first choice: extra tokens are spent to make the small model as good as possible, because it is the one that is cheap to serve.
QuestionWhy? The paper chose RMSNorm over standard layer normalization. What does RMSNorm skip, and why might that be acceptable?Show answer
Layer normalization subtracts the mean of the activations and divides by their standard deviation. RMSNorm divides only by the root mean square, without subtracting the mean. The rescaling keeps the activations at a stable magnitude, which is what helps training stability, while removing the mean subtraction saves computation. The paper's choice relies on the claim that the re-centering step was not needed for stable training at these scales.
QuestionApplied: a team wants to replicate the 65B training run on 2,048 A100 GPUs at 380 tokens per second per GPU, using 1.4 trillion tokens. Roughly how long does it take, and how many GPU-days are used?Show answer
Throughput across the cluster is 380 times 2,048, which is about 778,000 tokens per second. Dividing 1.4e12 tokens by 778,000 tokens per second gives about 1.8 million seconds, which is about 20.8 days. That matches the paper's "approximately 21 days". GPU-days are 2,048 times 21, about 43,000. Real runs lose time to restarts and failures, so the planned number is a lower bound.
QuestionScenario: a company wants an open model for a product that will answer very many queries a day, but its training budget is fixed. Using the LLaMA argument, when would a smaller model trained on more tokens be the better choice, and what is the cost of that choice?Show answer
The argument applies when the number of queries is large, so inference cost dominates total cost over the model's life. A smaller model trained longer costs more training compute than the compute-optimal recipe would spend on that size, but each query is cheaper to serve. The cost is that, at the same training compute, a larger model trained on fewer tokens would have a lower loss. The smaller model wins on total cost of ownership, not on the loss achieved for the training budget.
Sources
- Touvron et al., "LLaMA: Open and Efficient Foundation Language Models", arXiv:2302.13971 (2023). https://arxiv.org/abs/2302.13971
- Hoffmann et al., "Training Compute-Optimal Large Language Models" (Chinchilla), arXiv:2203.15556 (2022). https://arxiv.org/abs/2203.15556