# LLaMA: Open and Efficient Foundation Language Models

Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothée Lacroix and 8 more · arXiv · 2023-2-27

- **Problem** Scaling studies ask how to split a fixed training compute budget between data and model size, which leaves out the cost of serving a trained model many times.
- **Method** Trains 7B to 65B transformers on about 1.4T tokens of publicly available text, with pre-normalization, RMSNorm, SwiGLU and RoPE, and an AdamW optimizer with a cosine learning rate schedule.
- **Results** LLaMA-13B reached 78.1 on BoolQ against 60.5 for GPT-3, and LLaMA-65B reached 68.2 exact match on TriviaQA zero-shot.

![Figure 2: Evolution of performance on question answering and common sense reasoning during training](https://refivu.com/papers/e01f8551-7797-458a-9c65-5b2b892f2bd8/figures/figure-7cf990b4982ce174b2ae0aba66377579.png?thumb=512)

**Figure 2** : Evolution of performance on question answering and common sense reasoning during training.

[Original paper](https://arxiv.org/abs/2302.13971v1) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothée Lacroix, Baptiste Rozière, Naman Goyal, Eric Hambro, Faisal Azhar, Aurelien Rodriguez, Armand Joulin, Edouard Grave, Guillaume Lample · LLaMA: Open and Efficient Foundation Language Models · Original paper figure · Extracted the figure area from page 8 of the original PDF.

## Why smaller models trained longer

Scaling studies answer a narrow question: for a fixed training compute budget, how should dataset size and model size be balanced. Under that framing, the best result for a given budget comes from a smaller model trained on more data, not from the largest model. Serving a model at scale adds a second cost that this framing ignores, which is the inference budget.

If a model answers many queries, a smaller model that reaches the same quality is cheaper per query, even when it takes longer to train. The authors note that Hoffmann et al. recommend a 10B model on 200B tokens, yet they found a 7B model still improving after 1T tokens. The goal is a series of models that stay competitive across different inference budgets, reached by training on more tokens than is usual.

## Public training corpus and tokenizer

English CommonCrawl makes up 67% of the mixture, built from five dumps from 2017 to 2020 and processed with the CCNet pipeline. CCNet deduplicates at the line level, uses a fastText classifier to remove non-English pages, filters low-quality text with an n-gram language model, and keeps only pages that a linear model classifies as Wikipedia references.

C4 adds 15%, included because diverse preprocessed CommonCrawl data improved performance in exploratory experiments. GitHub (4.5%) keeps only Apache, BSD and MIT projects, filters low-quality files and boilerplate, and deduplicates at the file level. Wikipedia (4.5%) uses dumps from June-August 2022 for 20 languages written in Latin or Cyrillic scripts.

Books (4.5%) combines Gutenberg with Books3, deduplicated at the book level for overlaps above 90%; ArXiv (2.5%) keeps LaTeX sources from the first section on, without the bibliography, comments or user macros. Stack Exchange (2%) uses the 28 largest sites, with HTML removed and answers sorted by score.

Text is tokenized with byte-pair encoding through SentencePiece, numbers are split into single digits, and unknown UTF-8 characters fall back to bytes. Across the mixture, most tokens are seen once in training, while the Wikipedia and Books domains are seen about twice, for roughly 1.4T tokens in total.

## Architecture changes and model sizes

The network keeps the transformer layout of Vaswani et al. and changes three components. Each sub-layer receives normalized input rather than a normalized output, which the authors motivate by training stability; the normalization is RMSNorm. The ReLU non-linearity is replaced by SwiGLU, with a hidden dimension of \\\\(\\\\frac{2}{3}\\\\cdot 4d\\\\) instead of \\\\(4d\\\\) as in PaLM.

Absolute positional embeddings are removed, and rotary positional embeddings (RoPE) are added at every layer.

Table 2 lists four sizes with model dimension from 4096 to 8192, from 32 to 64 heads, and from 32 to 80 layers. The table labels the sizes 6.7B, 13.0B, 32.5B and 65.2B, while the figures and text of the paper call them 7B, 13B, 33B and 65B.

Training uses AdamW with β1 = 0.9 and β2 = 0.95. The learning rate and batch size vary with model size, as listed in Table 2.

## Efficient training at 65B scale

Causal multi-head attention uses an implementation from the xformers library that does not store attention weights and skips computing key and query scores that the causal mask removes. To reduce recomputation during the backward pass, the outputs of linear layers are saved, which required a hand-written backward function for the transformer layers instead of PyTorch autograd.

Model and sequence parallelism lower memory use further, and communication between GPUs overlaps with computation as far as possible.

For a 65B-parameter model, the code processes around 380 tokens/sec/GPU on 2048 A100 GPUs with 80GB of RAM. At that rate, training on 1.4T tokens takes roughly 21 days.

## Common sense and closed-book QA

Eight zero-shot common sense benchmarks are used: BoolQ, PIQA, SIQA, HellaSwag, WinoGrande, ARC easy and challenge, and OpenBookQA. For most of them, the completion with the highest likelihood is chosen, normalized by its character count; OpenBookQA and BoolQ instead divide by the likelihood given Answer: as context, \\\\( P(\\\\text{completion} \\\\mid \\\\text{context}) / P(\\\\text{completion} \\\\mid \\\\text{Answer:}) \\\\).

LLaMA-13B reached 78.1 on BoolQ against 60.5 for GPT-3, and it beats GPT-3 on most benchmarks despite being 10× smaller. The text names BoolQ as the one benchmark where Chinchilla-70B is ahead of LLaMA-65B, but Table 3 gives 85.3 for LLaMA-65B and 83.7 for Chinchilla-70B on BoolQ, so the numbers show LLaMA-65B ahead there.

Natural Questions and TriviaQA are scored by exact match, with no access to documents that contain the answer. On TriviaQA, LLaMA-65B reached 68.2 zero-shot and 73.0 at 64-shot; on Natural Questions it reached 23.8 zero-shot and 39.9 at 64-shot. The authors report the best zero-shot and few-shot results on both benchmarks for LLaMA-65B, and LLaMA-13B, which runs on a single V100 GPU at inference, is competitive with GPT-3 and Chinchilla despite being 5-10× smaller.

During training, performance on most tracked benchmarks rises steadily, and the 7B model keeps improving past 1T tokens. SIQA varies a lot between checkpoints, and WinoGrande does not track training perplexity closely, with LLaMA-33B and LLaMA-65B performing similarly during training.

## Reading, math and code results

On RACE, scored zero-shot, LLaMA-13B reached 61.6 on middle and 47.2 on high, against 58.4 and 45.5 for GPT-3. LLaMA-65B reached 67.9 on RACE-middle and 51.6 on RACE-high.

MATH and GSM8k are scored with and without maj1@k, which takes a majority vote over k sampled solutions per problem. Minerva is PaLM fine-tuned on 38.5B tokens from ArXiv and math web pages, while LLaMA is not fine-tuned on math data. Without voting, LLaMA-65B reaches 50.9 on GSM8k against 52.4 for Minerva 62B; with maj1@k it reaches 69.7 against 68.5.

The authors say LLaMA-65B outperforms Minerva-62B on GSM8k, which holds in the majority-voting column but not in the plain one.

HumanEval and MBPP are scored with pass@1, using samples drawn at temperature 0.1, and the comparisons are with general models not fine-tuned on code. LLaMA-65B reaches 23.7 pass@1 on HumanEval and 37.7 on MBPP, above PaLM 62B at 15.9 and 21.4. LLaMA-13B reaches 15.8 on HumanEval and 22.0 on MBPP, above LaMDA 137B at 14.0 and 14.8. PaLM 540B reaches 26.2 on HumanEval pass@1, above the 23.7 of LLaMA-65B.

## MMLU and instruction tuning

On 5-shot MMLU, LLaMA-65B averages 63.4, behind Chinchilla-70B at 67.5 and PaLM-540B at 69.3. The authors link the gap to the limited book and paper data in pre-training, 177GB across ArXiv, Gutenberg and Books3, against up to 2TB of books for the other models.

LLaMA-I is an instruction-tuned version of LLaMA-65B, trained with the protocol of Chung et al. in a single experiment, and it reaches 68.9 on 5-shot MMLU. Moderate-size instruction-tuned models score lower, with OPT-IML-Max 30B at 43.2, Flan-T5-XXL 11B at 55.1 and Flan-PaLM 62B at 59.6. The 77.4 reported for code-davinci-002 remains higher than LLaMA-I's 68.9.

## Bias, toxicity and truthfulness

RealToxicityPrompts has about 100k prompts, each completed greedily and scored from 0 to 1 by PerspectiveAPI. The basic prompt score rises from 0.106 at 7B to 0.128 at 65B, and the respectful prompt score from 0.081 to 0.141, with 33B at 0.087 below 13B at 0.095 on respectful prompts. The authors say the scores are only loosely comparable with published numbers, since sampling strategy, number of prompts and API timing differ.

CrowS-Pairs covers nine bias categories and compares perplexity of stereotypical and anti-stereotypical sentences, where higher scores mean more bias. LLaMA-65B averages 66.6, slightly below GPT-3 at 67.2 and OPT-175B at 69.5. The authors report that religion is the category where the model is particularly biased, about 10% above OPT-175B.

On WinoGender, LLaMA-65B reaches 81.7 for their/them/someone pronouns, 78.8 for her/her/she and 72.1 for his/him/he. The authors read the gap as the model relying on the majority gender of an occupation rather than on the sentence.

On TruthfulQA, LLaMA-65B scores 0.57 truthful and 0.53 truthful\*informative, against 0.28 and 0.25 for GPT-3 175B. The authors note that the rate of correct answers is still low, so the model is likely to hallucinate incorrect answers.

## Carbon footprint estimates

Energy is estimated as GPU-hours times GPU power consumption times PUE, \\\\( \\\\text{Wh} = \\\\text{GPU-h} \\\\times \\\\text{GPU power consumption} \\\\times \\\\text{PUE} \\\\), with PUE set at 1.1. Emissions use the US national average intensity of 0.385 kg CO2eq/KWh, so \\\\( t\\\\text{CO}\_2\\\\text{eq} = \\\\text{MWh} \\\\times 0.385 \\\\), which puts all models on the same grid.

Table 15 gives LLaMA-65B 1,022,362 GPU-hours, 449 MWh and 173 tCO2eq, while OPT-175B reaches 137 tCO2eq and BLOOM-175B reaches 183 tCO2eq. The table assumes 400W per A100-80GB, taken as the thermal design power for NVLink systems. Developing all the models, on 2048 A100-80GB for about 5 months, is estimated at 2,638 MWh and 1,015 tCO2eq under these assumptions.

## Limitations

The authors state that the standard bias and toxicity benchmarks are not enough to fully capture the risks of these models. Toxicity and bias scores are not directly comparable with other reports, because the pipeline of the third-party API and the sampling setup differ.

Pre-training used only 177GB of books and papers, which the authors offer as a likely reason for the MMLU gap to Chinchilla and PaLM. Code-specific finetuning is outside the scope of the paper. Instruction tuning is a single experiment that was not the focus of the work, and larger models on larger corpora are left to future work.

## Paper info

- **Authors**: Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothée Lacroix, Baptiste Rozière, Naman Goyal, Eric Hambro, Faisal Azhar, Aurelien Rodriguez, Armand Joulin, Edouard Grave, Guillaume Lample
- **Venue**: arXiv · Preprint
- **First published**: 2023-2-27
- **Added**: 2026-10-20
- **Updated**: 2023-2-27
- **Version**: v1
- **arXiv**: 2302.13971
- **Category**: cs.CL
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info, commentary and permitted figures from the original paper

[Original paper ↗](https://arxiv.org/abs/2302.13971v1) · [PDF ↗](https://arxiv.org/pdf/2302.13971v1)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Abstract

We introduce LLaMA, a collection of foundation language models ranging from 7B to 65B parameters. We train our models on trillions of tokens, and show that it is possible to train state-of-the-art models using publicly available datasets exclusively, without resorting to proprietary and inaccessible datasets. In particular, LLaMA-13B outperforms GPT-3 (175B) on most benchmarks, and LLaMA-65B is competitive with the best models, Chinchilla-70B and PaLM-540B. We release all our models to the research community.

## Quote from the paper

Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothée Lacroix, Baptiste Rozière, Naman Goyal, Eric Hambro, Faisal Azhar, Aurelien Rodriguez, Armand Joulin, Edouard Grave, Guillaume Lample (2023). LLaMA: Open and Efficient Foundation Language Models. arXiv:2302.13971v1. https://arxiv.org/abs/2302.13971v1

**BibTeX**

```
@misc{touvron2023llama,
  title = {{LLaMA: Open and Efficient Foundation Language Models}},
  author = {Hugo Touvron and Thibaut Lavril and Gautier Izacard and Xavier Martinet and Marie-Anne Lachaux and Timothée Lacroix and Baptiste Rozière and Naman Goyal and Eric Hambro and Faisal Azhar and Aurelien Rodriguez and Armand Joulin and Edouard Grave and Guillaume Lample},
  year = {2023},
  eprint = {2302.13971},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2302.13971v1}
}
```

## Other paper commentary

- [Training language models to follow instructions with human feedback](https://refivu.com/en/papers/9a0e4c9e-5f65-4b6a-b559-76f0a9c35e07-training-language-models-to-follow-instructions-with-human.md)
- [Chain-of-Thought Prompting Elicits Reasoning in Large Language Models](https://refivu.com/en/papers/453dc85c-e794-4846-bb89-b8b678635169-chain-of-thought-prompting-elicits-reasoning-in-large.md)
- [Llama 2: Open Foundation and Fine-Tuned Chat Models](https://refivu.com/en/papers/5c1523c3-cd1c-48ba-8289-86de02d688dd-llama-2-open-foundation-and-fine-tuned-chat.md)
- [PaLM: Scaling Language Modeling with Pathways](https://refivu.com/en/papers/31a94910-97f3-470b-a240-6c8b698de722-palm-scaling-language-modeling-with-pathways.md)
- [Mistral 7B](https://refivu.com/en/papers/9993f1cb-8618-4aeb-9dc5-d4a5aa598381-mistral-7b.md)
- [Scaling Laws for Neural Language Models](https://refivu.com/en/papers/0b00379f-9c4e-4d81-be48-4963190a673b-scaling-laws-for-neural-language-models.md)
- [Zero-Shot Text-to-Image Generation](https://refivu.com/en/papers/ec261d9b-e98a-4dcc-8961-c79073db25e2-zero-shot-text-to-image-generation.md)
- [Deep reinforcement learning from human preferences](https://refivu.com/en/papers/46d079bb-6a3c-401d-94a4-5ceb66ab32a1-deep-reinforcement-learning-from-human-preferences.md)
- [Score-Based Generative Modeling through Stochastic Differential Equations](https://refivu.com/en/papers/11d114a6-a425-47ea-9133-db43e9c355d2-score-based-generative-modeling-through-stochastic.md)
- [Denoising Diffusion Probabilistic Models](https://refivu.com/en/papers/3a1faf88-ed3a-4c3a-bf1e-1afc6e7184fa-denoising-diffusion-probabilistic-models.md)
- [Mastering Atari, Go, Chess and Shogi by Planning with a Learned Model](https://refivu.com/en/papers/b99bbef4-e405-4227-881f-01ef69bed080-mastering-atari-go-chess-and-shogi-by-planning.md)

## Terms in this paper

- [Transformer](https://refivu.com/en/terms/48e8be2570bc-transformer)
- [GSM8K](https://refivu.com/en/terms/e48f0e01064d-gsm8k)
- [MMLU](https://refivu.com/en/terms/3036c0ba5adb-mmlu)
- [HumanEval](https://refivu.com/en/terms/3c3dbcadfdda-humaneval)
- [RMSNorm](https://refivu.com/en/terms/9b1cafd281f0-rmsnorm)
- [exact match](https://refivu.com/en/terms/f6e0295e5c92-exact-match)
- [TriviaQA](https://refivu.com/en/terms/d04d9611868e-triviaqa)
- [MBPP](https://refivu.com/en/terms/717e657dd0b2-mbpp)
- [pass@1](https://refivu.com/en/terms/0b5f8fd75383-pass-1)
- [SwiGLU](https://refivu.com/en/terms/9b64288c190e-swiglu)
- [RoPE](https://refivu.com/en/terms/e4cc5cfc6ebf-rope)
- [Wikipedia](https://refivu.com/en/terms/2569175e3d90-wikipedia)
- [C4](https://refivu.com/en/terms/87725552ed79-c4)
- [Code generation](https://refivu.com/en/terms/8b457c4f8807-code-generation)
- [RACE](https://refivu.com/en/terms/0dc449cd7f20-race)
- [LLaMA](https://refivu.com/en/terms/1a23d312f4db-llama)
- [Natural Questions](https://refivu.com/en/terms/2053f89c9387-natural-questions)
- [BPE](https://refivu.com/en/terms/8f51fddd26a4-bpe)
- [Mathematical reasoning](https://refivu.com/en/terms/35baa42c49e4-mathematical-reasoning)
- [RealToxicityPrompts](https://refivu.com/en/terms/904f69ed9de9-realtoxicityprompts)
- [ArXiv](https://refivu.com/en/terms/fb0ca98d81ee-arxiv)
- [Books3](https://refivu.com/en/terms/35d4c917123c-books3)
- [Common Sense Reasoning](https://refivu.com/en/terms/5c7ebea09fb2-common-sense-reasoning)
- [cosine learning rate schedule](https://refivu.com/en/terms/d307b7cd29a7-cosine-learning-rate-schedule)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/e01f8551-7797-458a-9c65-5b2b892f2bd8-llama-open-and-efficient-foundation-language-models)
