GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
arXiv preprint

Llama 2: Open Foundation and Fine-Tuned Chat Models

Meta's 7B-70B models on 2T tokens, with the full chat recipe: 27,540 SFT examples, 1.4M preference pairs, two reward models, rejection sampling, PPO and Ghost Attention. Licensed for commercial use.

Breakdown by FDE Interviews · 14 min read · Updated

About the original · 2023
AUTHORS
Touvron, Martin, Stone, Albert, et al.
FROM
GenAI, Meta
PUBLISHED
Jul 2023 · arXiv preprint
CITED BY
19,002Semantic Scholar · Nov 2026
IN THIS BREAKDOWN · 10 SECTIONS

You can read 17% of this breakdown.

01

The paper in one minute

LLaMA showed open base models could match closed ones on benchmarks. What it did not provide was a usable assistant. The step that turns a base model into ChatGPT is alignment: supervised fine-tuning on instructions, then reinforcement learning from human feedback, and labs had not published how they did it. Llama 2 is Meta's attempt to document that step in full and release the result.

The base models change modestly from LLaMA: 40% more data (2 trillion tokens), a context doubled to 4,096 tokens, and grouped-query attention (GQA) in the 34B and 70B models so the KV cache is smaller at serving time. The chat models are the main contribution. Meta found that a few tens of thousands of carefully written instruction examples beat millions of third-party ones, stopping at 27,540. It then collected over 1.4 million binary human comparisons in weekly batches, each time on the newest model's outputs, and trained two reward models, one for helpfulness and one for safety, because the two goals pull against each other.

Five rounds of RLHF followed, first by rejection sampling (generate many answers, fine-tune on the best) and then PPO. A data trick called Ghost Attention keeps a system instruction such as "act as Napoleon" in force for 20 or more turns. Separate safety tuning, context distillation and red teaming targeted harmful outputs.

The 70B chat model won 36% and tied 31.5% of comparisons against ChatGPT, and its toxic generations dropped to effectively zero. Meta released 7B, 13B and 70B models for research and commercial use, holding back the 34B for lack of red-teaming time.

THE IDEA, VISUALLY
FROM BASE MODEL TO CHAT MODEL (FIGURE 4) Pretrain 2T tokens, 4k context SFT 27,540 examples, 2 epochs Collect preferences weekly, on latest model Two reward models helpfulness | safety Rejection sampling best of K from 70B PPO + KL penalty safety gate at 0.15 RLHF-V1 to V5 Ghost Attention system prompt, 20+ turns 1,418,091 Meta comparisons; SFT outputs rivaled human answers, so effort moved there GQA SHRINKS THE KV CACHE (APPENDIX A.2.1) MiB per token, illustrative 80-layer, 128-dim-head shape MHA, 64 KV heads 2.5 GQA, 8 KV heads 0.312 MQA, 1 KV head 0.039 4k-token chat: 10 GiB vs 1.25 GiB of cache 70B CHAT VS CHATGPT, HUMAN RATERS win 36% tie 31.5% loss 32.5% about 4,000 prompts, none on coding or reasoning SAFETY BENCHMARKS, 70B (TABLES 11, 14) base chat ToxiGen, % toxic 24.60 0.01 TruthfulQA, % true+info 50.18 64.14 but safety data raised false refusals on a 210-prompt borderline set arXiv 2307.09288, GenAI at Meta, July 2023
Llama 2-Chat is built in stages: pretraining on 2 trillion public tokens, a small supervised set of 27,540 high-quality examples, then five rounds of RLHF in which fresh human preferences retrain separate helpfulness and safety reward models that steer rejection sampling and PPO. Ghost Attention keeps a system instruction alive across turns.
Research notes: the problem, approach and results
2T tokens

pretraining data for every size, 40% more than LLaMA, with a 4,096-token context (Table 1)

1,418,091

Meta binary preference comparisons collected for reward modeling (Table 6)

36% / 31.5%

win and tie rates of Llama 2-Chat 70B against ChatGPT in human evaluation (Section 3.4.2)

THE PROBLEM

Open models such as LLaMA matched closed base models, but none could stand in for ChatGPT or Claude, because the expensive, opaque step is alignment: instruction tuning and RLHF with large amounts of human preference data. No open release documented that step.

THE IDEA

Pretrain 7B to 70B models on 2 trillion tokens with a 4k context and grouped-query attention for the large sizes. Fine-tune on a small, carefully written instruction set, then run iterative RLHF: collect weekly human comparisons on the latest model, train separate helpfulness and safety reward models, and optimize with rejection sampling followed by PPO. Add Ghost Attention for multi-turn instructions and safety-specific tuning.

THE RESULT

Llama 2 70B improved on LLaMA-65B by about 5 points on MMLU (68.9) and 8 on BBH. In human evaluation over about 4,000 prompts, Llama 2-Chat 70B won 36% and tied 31.5% against ChatGPT. Toxic generations fell to effectively 0% on ToxiGen. The models were released for research and commercial use.

02

Why it matters to an FDE

Llama 2 is the paper to read before fine-tuning an open model for a customer, because it states plainly what each alignment stage costs and buys.

Quality beats quantity in instruction data. A few thousand to tens of thousands of carefully checked examples outperformed millions of scraped ones, and different annotation vendors produced markedly different models. When a customer asks how much labeled data a fine-tune needs, this is the reference point, along with the warning to audit the vendor's work.

GQA is a serving decision. Sharing key and value heads across groups of query heads cuts KV-cache memory several times over with little quality loss, which means more concurrent conversations per GPU. It is why most large open models since use it.

Safety tuning has side effects you will see. The paper reports that the model sometimes refuses harmless prompts that contain alarming words, and says outright that its tuning "goes too far" at times. Before deploying a chat model in a customer workflow, test it on the borderline cases your users will actually send.

Commercial use changed the market. Unlike the first LLaMA, these weights came with a license allowing commercial use under Meta's terms and acceptable-use policy, which is why so many enterprise pilots started on Llama 2.

THE FULL BREAKDOWN

Understand the mechanism. Try it on a real problem.

Unlock this breakdown and 290 more papers.

Premium opens every paper in full, plus every answer, concept, course and guide on the site. One payment for six months of access.

6 months · One payment · No auto-renewal

Get Premium · ₹2,000 / $25
  • ◇1 architecture diagram
  • </>1 runnable code experiment
  • ▦2 results tables
  • ?5 interview questions with answers
  1. 03Key takeaways

    The pipeline stages, the reward-model design, the evaluation caveats and two misreadings

    Free account
  2. 04How it works

    The base-model changes, SFT details, preference collection, both reward models, RLHF and GAtt

    Premium
  3. 05The numbers that matter

    Base-model benchmarks, reward-model accuracy, human evaluation, safety tables and the training bill

    Premium
  4. 06Try it yourself

    GQA memory arithmetic, two table audits, best-of-N headroom and how close "competitive" is

    Premium
  5. 07Where it breaks

    Narrow evaluation, model-judged progress, over-refusal, English focus, and slips

    Premium
  6. 08Using it on a deployment

    Choosing a size, budgeting KV cache, fine-tuning on top of the chat model, and safety testing

    Premium
  7. 09Interview angles

    Five questions this paper prepares you for, with answer hints

    Premium
Back to the paper library →