Profile

Settings

Loading…

← Papers

Help

FAQ

Which features require signing in?

You can read the commentary, paper info, Model Structure and related papers of public papers without signing in. Sign in to manage your account or contact us about your inquiries.

Can I upload a PDF file?

Upload papers with an arXiv or DOI link; the commentary is public to everyone. Papers whose source and terms of use can't be verified, so the commentary can't be made public, can't be uploaded. Uploading PDF files and keeping papers private are for subscribers only, and a paper uploaded as a file is saved as private only. Searching for official info by title runs only when you press the button.

Are the figures and AI commentary accurate?

Figures come only from the original paper, and only those whose terms of use are verified are shown. The commentary is written by AI and may be wrong. Check important claims, numbers and figure context against the evidence in the original paper.

I want to report a copyright issue.

Terms of use and the source of the original paper are on the Paper info tab. If there's a problem, choose "Paper content, figures and copyright" under Contact us and send the paper link, the part in question, and evidence that you hold the rights. Receiving your report doesn't confirm any rights or remove anything right away. You can see the result of the review under My inquiries.

I forgot my password.

If you signed up with email, use Forgot password in the sign-in window to reset it with your verified email. If you signed up with Google, Naver or Kakao, change your password with that service.

What should I include in an inquiry?

Tell us which screen you were on and what you were doing when the problem happened, along with the paper link. Don't include personal information such as passwords, API keys, verification codes or phone numbers. Inquiries and replies are stored in Refivu and you can see them under My inquiries.

How do I delete my account?

In Settings, under My account, press Delete account. Review what will be deleted and complete identity verification to delete your account. For other requests, choose "Account" under Contact us.

Paper commentary

Llama 2: Open Foundation and Fine-Tuned Chat Models

  • Problem Open pretrained LLMs lack the heavy alignment that makes closed chat products usable and safe, and that alignment is costly and rarely reproducible.
  • Method Updates the Llama 1 pretraining recipe on 2T tokens, then fine-tunes Llama 2-Chat with supervised data and iterative rejection sampling and PPO, guided by separate helpfulness and safety reward models.
  • Results Helpfulness RM reached 63.2 on Meta Helpful and Safety RM reached 64.5 on Meta Safety. Llama 2-Chat 70B rose from 50.18 to 64.14 on TruthfulQA after fine-tuning relative to pretrained Llama 2.

Why open chat models lag behind product systems

Public releases such as BLOOM, LLaMa-1 and Falcon are reported to match closed pretrained models like GPT-3 and Chinchilla, yet none of them can replace product chat systems such as ChatGPT, BARD and Claude. Those product systems depend on heavy fine-tuning toward human preferences, which raises usability and safety. That step is expensive in compute and annotation and is rarely documented well enough to reproduce.

The study asks whether an openly released family can approach closed chat systems on helpfulness and safety. It releases pretrained Llama 2 models and fine-tuned Llama 2-Chat models at up to 70B parameters.

The comparisons with closed models rest mainly on human ratings, where Llama 2-Chat is on par with some closed models, and those ratings come from about 4k prompts. Such ratings depend on the prompt set, the review guidelines and individual raters, so the closed-model comparisons should be read with that in mind.

Pretraining changes relative to Llama 1

The base recipe is an optimized auto-regressive transformer following the Llama 1 approach, with several changes aimed at better performance. Data cleaning is more robust, the data mix is updated, and total training tokens rose by 40%. The context length is doubled, and grouped-query attention is used in the larger models to improve inference scalability.

The corpus comes from public sources and excludes data from Meta products and services. Sites known for large amounts of personal information about private individuals were removed where possible. Training uses 2 trillion tokens, which the authors judge to be a good balance of performance and cost. The most factual sources are up-sampled to aim for better knowledge and fewer hallucinations.

The architecture remains a standard transformer with pre-normalization by RMSNorm, the SwiGLU activation and rotary positional embeddings. Beyond Llama 1, the architectural differences are the longer context and grouped-query attention, which the appendix examines with ablations. Table 1 shows that the 7B and 13B models use a 4k context without grouped-query attention, while the 34B and 70B models use it.

Training uses AdamW with β1 = 0.9, β2 = 0.95 and eps = 10−5, a cosine learning rate schedule with 2000 warmup steps, and decay to 10% of the peak rate.

The tokenizer is the same byte pair encoding as Llama 1, implemented with SentencePiece. Numbers are split into individual digits, and unknown UTF-8 characters are decomposed into bytes, giving a vocabulary of 32k tokens. Training loss had not saturated after 2T tokens, which the authors read as room for further training.

Pretraining ran on Meta's Research SuperCluster and on internal production clusters, both with NVIDIA A100 GPUs. The two differ in interconnect and in the per-GPU power cap of 400W versus 350W. Summed over the four models, pretraining used 3311616 GPU hours and emitted 539.00 tCO2eq, and Meta's sustainability program offset the emissions.

Separate helpfulness and safety reward models

A single reward model struggles to serve both helpfulness and safety, because answering helpfully and refusing unsafe prompts pull in different directions. The authors therefore train a Helpfulness RM and a Safety RM. Both reward models start from pretrained chat checkpoints, so each shares the chat model's knowledge. This avoids an information mismatch that could favor hallucinated answers.

Preference pairs are converted into chosen and rejected labels. The reward model is trained so that the chosen response scores higher, using the loss below, where r_θ(x,y) is the scalar score for prompt x and completion y. \[ L_{ranking} = -\log(\sigma(r_\theta(x,y_c) - r_\theta(x,y_r))) \] Here y_c is the preferred response and y_r the rejected one.

Annotators rate preferences on a four-point scale, and the helpfulness model uses that scale through a margin m(r). Pairs with clearly different responses get a large margin and similar pairs a smaller one. \[ L_{ranking} = -\log(\sigma(r_\theta(x,y_c) - r_\theta(x,y_r) - m(r))) \] The authors report that the margin improves helpfulness accuracy, mostly on pairs whose responses are easier to separate.

Open-source preference datasets bootstrapped the reward models while human annotation was still running, and they stayed in the mixture. The authors observed no negative transfer from them. They expect the open-source data to help generalization and to limit reward hacking, where the policy exploits weaknesses of the reward. The combined training set has 2,919,326 comparisons, of which 1,418,091 are Meta Safety and Helpfulness comparisons.

The Helpfulness RM trains on all Meta Helpfulness data, plus equal parts of the remaining data sampled from Meta Safety and from the open-source sets.

Each reward model trains for one epoch with the same optimizer settings as the base model. The maximum learning rate is 5× 10−6 for the 70B model and 1× 10−5 for the rest, with cosine decay to 10% of the maximum. Warmup covers 3% of the steps with a minimum of 5, and each batch holds 512 pairs, or 1024 rows.

How RLHF iterations update the chat model

The chat model starts from supervised fine-tuning and is then refined through versions named RLHF-V1 to RLHF-V5, each trained on newer reward data. As more preference batches arrived, the reward models were retrained and more prompts were collected.

PPO is the standard RLHF algorithm. Rejection sampling draws K outputs for each prompt, keeps the candidate the reward model ranks highest, and fine-tunes on that candidate. Both methods are applied in the sequence of RLHF versions.

The authors link this selection step to earlier re-ranking for LLMs, where the reward acts as an energy function. They go a step further by using the selected outputs for a gradient update. Re-ranking alone only chooses among existing samples, whereas the gradient update changes the model itself.

Across the SFT models and successive RLHF versions, reward scores move toward the high end, with the worst answers progressively removed. The score distribution shift is shown in Figure 20.

The authors note that SFT learns the variation of its annotators, including poorly written tail examples, and its quality is capped by the most skilled writers. Comparing two candidate answers is easier for annotators than writing a strong answer, so preference labels carry signal beyond what annotators can write themselves. The authors argue that this is part of why RLHF works well.

Diversity on factual prompts falls over RLHF versions, while creative prompts keep diversity close to the SFT model, which the authors describe as the model learning context-dependent temperature behavior.

Reward model accuracy and scaling

Each annotation batch holds out 1000 examples as a test set, and the union of prompts forms the Meta Helpfulness and Meta Safety test sets. Baselines are SteamSHP-XL, the Open Assistant reward model and GPT-4 prompted zero-shot to choose between two answers.

Helpfulness RM scores 63.2 on Meta Helpful and Safety RM scores 64.5 on Meta Safety. GPT4 reaches 58.6 on Meta Helpful and 58.1 on Meta Safety. Each model is strongest on its own test set, and the authors report that their reward models outperform all baselines, including GPT-4.

Accuracy falls as the preference rating gets closer to a tie. Helpfulness RM reaches 80.7 on significantly better pairs and 54.7 on negligibly better or unsure pairs. Safety RM goes from 94.3 on significantly better pairs to 55.3 on negligibly better or unsure pairs on Meta Safety. The authors stress that accuracy on distinct responses matters most for improving Llama 2-Chat.

Larger models and more reward data both raise accuracy, and the curves had not flattened on the existing volume of annotation. The authors treat reward accuracy as one of the strongest proxies for the final performance of Llama 2-Chat, because the ranking task itself is unambiguous.

What the pretraining data contains

The authors did not add filtering beyond privacy and legal review, and they did not use Meta user data. Their reasons are that unfiltered data keeps the model useful for tasks such as hate speech classification and avoids the demographic erasure that over-scrubbing can cause. They also expect that leaving the data unfiltered lets Llama 2-Chat generalize more effectively in later safety tuning with fewer examples.

In the English corpus, 75.23% of documents contain gendered pronouns, and He pronouns appear in 50.73% of documents against 28.45% for She pronouns. The authors read this skew as a possible reason the model may learn less about She-referenced context and produce He pronouns more often.

Using HolisticBias descriptors, the authors find that 'american' appears in 69.4% of documents that mention a nationality term, and 'female' in 50.0% of documents that mention a gender or sex term. Across nationality, race and ethnicity, and religion, the authors observe a Western skew, with 'european' more prevalent than other race and ethnicity terms.

A HateBERT classifier fine-tuned on ToxiGen scores each line of a document and averages the scores per document. About 0.2% of documents receive a likelihood of 0.5 or higher. Toxic data was deliberately not scrubbed from pretraining, to support downstream generalization.

English makes up 89.70% of the pretraining data, and 8.38% is labeled unknown, which is partly programming code. The authors expect Llama 2 to perform best on English-language use cases, and the training corpus is not suited to other languages without further work.

Context distillation and red teaming

Context distillation bakes a safety preprompt into the model. A generic preprompt raises safety reward scores, and a preprompt with a tailored answer template raises them further. Context distillation increases the reward score most for samples that initially scored low, but can lower it for samples that initially scored high.

Context distillation is applied only to adversarial prompts, since applying it to helpful prompts degrades performance and produces more false refusals. Even on adversarial prompts it can make answers vague, because the model overemphasizes the preprompt when the original answer was already good.

The Safety RM filters the distilled outputs. A distilled answer is kept only when the reward model scores it higher than the original answer. The authors find this especially helpful on prompts where the model performs poorly, and it limits the negative side of context distillation.

Red teaming involved more than 350 people, including internal employees, contract workers and external vendors. Their domains included cybersecurity, election fraud, legal, policy, ethics and creative writing. Participants also varied in socioeconomic, gender, ethnic and racial background.

Probes covered risk categories such as criminal planning and human trafficking, and attack vectors such as hypothetical questions, misspelled inputs and extended dialogues. Tests on weapon production capabilities gave marginal findings, which were mitigated, and the authors say the work will continue in that area. All exercises targeted English outputs, though non-English prompts were included.

Early models produced unsafe responses without signaling that the content was problematic, and disguising requests as creative writing or positive framing often got past refusals. Later models acknowledged problematic content, and the latest models resolved these issues, according to the red team feedback.

Prompts that earlier exercises had found to trigger violations were mitigated in about 90% of cases in each new candidate release.

Helpfulness and safety results for Llama 2-Chat

GPT-4 was also used as a judge in win-rate comparisons, with response order randomly swapped to reduce bias, and ties removed by using win/(win + loss).

The safety evaluation used roughly 2,000 adversarial prompts, of which 1,351 are single-turn and 623 multi-turn. Raters used a five-point scale, and a rating of 1 or 2 counts as a violation.

Across model sizes, Llama 2-Chat has comparable or lower overall violation percentage, followed by ChatGPT and Falcon, then MPT and Vicuna. Figure 17 reports the overall violation percentage on the left and the mean safety and helpfulness rating on the right.

Falcon's replies are typically short, which makes them less prone to unsafe content but also less helpful. The reported mean ratings are 3.88 for Falcon and 4.45 for Llama 2-Chat 34B, although their violation percentages look similar.

Multi-turn conversations induce unsafe responses more often across the compared models, although Llama 2-Chat still performs well relative to the baselines on them.

Per risk category, the models perform similarly, except that Llama 2-Chat has relatively more violations under the unqualified advice category, partly because it sometimes lacks a disclaimer, though the absolute rate stays low. Figure 18 splits the violation percentages into single-turn and multi-turn conversations.

After fine-tuning, the 70B model moves from 50.18 to 64.14 on TruthfulQA, and its ToxiGen value falls from 24.60 to 0.01 relative to pretrained Llama 2. Among the fine-tuned Llama 2-Chat models, ToxiGen values range from 0.00 to 0.02, against 7.89 for Falcon-instruct 7B and 16.33 for MPT-instruct 7B.

Temporal knowledge, tool use and temperature

Several behaviors emerged during tuning, including the model organizing knowledge in time, calling external APIs and adapting temperature to the prompt type. The temperature behavior is covered in the RLHF section.

The authors report that the model generalizes this notion of time from minimal data, based on manual testing of dozens of examples.

Toolformer samples millions of API-augmented examples for tool use. Llama 2-Chat reaches 67.1 on ASDiv, 69.2 on SVAMP and 82.4 on MAWPS. Toolformer scores 40.4, 29.4 and 44.0 on the same three datasets, and GPT-3 scores 14.0, 10.0 and 19.8. The baseline scores come from Schick et al. (2023) rather than from a run under the same conditions.

Limitations

The human evaluation uses a prompt set of about 4k prompts, which the authors say does not cover the full range of real-world usage. The prompt set includes no coding- or reasoning-related prompts, so results for those tasks were not measured.

Human evaluation of generative models is subjective and noisy, and different prompts or instructions could give different results.

Testing so far has been in English and could not cover all scenarios, so developers should run safety testing and tuning for their own applications. The 34B model was trained but is not released because there was not enough time to red team it.

The safety evaluation uses content standards that are likely biased towards Llama 2-Chat, and the ratings carry the subjectivity of the review guidelines and individual raters.

Paper info

Authors
Hugo Touvron, Louis Martin, Kevin Stone, Peter Albert, Amjad Almahairi, Yasmine Babaei, Nikolay Bashlykov, Soumya Batra, Prajjwal Bhargava, Shruti Bhosale, Dan Bikel, Lukas Blecher, Cristian Canton Ferrer, Moya Chen, Guillem Cucurull, David Esiobu, Jude Fernandes, Jeremy Fu, Wenyin Fu, Brian Fuller, Cynthia Gao, Vedanuj Goswami, Naman Goyal, Anthony Hartshorn, Saghar Hosseini, Rui Hou, Hakan Inan, Marcin Kardas, Viktor Kerkez, Madian Khabsa, Isabel Kloumann, Artem Korenev, Punit Singh Koura, Marie-Anne Lachaux, Thibaut Lavril, Jenya Lee, Diana Liskovich, Yinghai Lu, Yuning Mao, Xavier Martinet, Todor Mihaylov, Pushkar Mishra, Igor Molybog, Yixin Nie, Andrew Poulton, Jeremy Reizenstein, Rashi Rungta, Kalyan Saladi, Alan Schelten, Ruan Silva, Eric Michael Smith, Ranjan Subramanian, Xiaoqing Ellen Tan, Binh Tang, Ross Taylor, Adina Williams, Jian Xiang Kuan, Puxin Xu, Zheng Yan, Iliyan Zarov, Yuchen Zhang, Angela Fan, Melanie Kambadur, Sharan Narang, Aurelien Rodriguez, Robert Stojnic, Sergey Edunov, Thomas Scialom
Venue
arXiv · Preprint
First published
2023-7-18
Added
2026-10-20
Updated
2023-7-19
Version
v2
arXiv
2307.09288
Category
cs.CL · cs.AI
Original paper terms
arXiv non-exclusive 1.0
What we show
Paper info and commentary

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.

Quote from the paper

Hugo Touvron, Louis Martin, Kevin Stone, Peter Albert, Amjad Almahairi, Yasmine Babaei, Nikolay Bashlykov, Soumya Batra, Prajjwal Bhargava, Shruti Bhosale, Dan Bikel, Lukas Blecher, Cristian Canton Ferrer, Moya Chen, Guillem Cucurull, David Esiobu, Jude Fernandes, Jeremy Fu, Wenyin Fu, Brian Fuller et al. (2023). Llama 2: Open Foundation and Fine-Tuned Chat Models. arXiv:2307.09288v2. https://arxiv.org/abs/2307.09288v2

BibTeX
@misc{touvron2023llama,
  title = {{Llama 2: Open Foundation and Fine-Tuned Chat Models}},
  author = {Hugo Touvron and Louis Martin and Kevin Stone and Peter Albert and Amjad Almahairi and Yasmine Babaei and Nikolay Bashlykov and Soumya Batra and Prajjwal Bhargava and Shruti Bhosale and Dan Bikel and Lukas Blecher and Cristian Canton Ferrer and Moya Chen and Guillem Cucurull and David Esiobu and Jude Fernandes and Jeremy Fu and Wenyin Fu and Brian Fuller and Cynthia Gao and Vedanuj Goswami and Naman Goyal and Anthony Hartshorn and Saghar Hosseini and Rui Hou and Hakan Inan and Marcin Kardas and Viktor Kerkez and Madian Khabsa and Isabel Kloumann and Artem Korenev and Punit Singh Koura and Marie-Anne Lachaux and Thibaut Lavril and Jenya Lee and Diana Liskovich and Yinghai Lu and Yuning Mao and Xavier Martinet and Todor Mihaylov and Pushkar Mishra and Igor Molybog and Yixin Nie and Andrew Poulton and Jeremy Reizenstein and Rashi Rungta and Kalyan Saladi and Alan Schelten and Ruan Silva and Eric Michael Smith and Ranjan Subramanian and Xiaoqing Ellen Tan and Binh Tang and Ross Taylor and Adina Williams and Jian Xiang Kuan and Puxin Xu and Zheng Yan and Iliyan Zarov and Yuchen Zhang and Angela Fan and Melanie Kambadur and Sharan Narang and Aurelien Rodriguez and Robert Stojnic and Sergey Edunov and Thomas Scialom},
  year = {2023},
  eprint = {2307.09288},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2307.09288v2}
}

See related papersBrowse other papers

Paper preview
Account security

Connect Google account

If you connect a Google account, you can sign in with it too.

Refivu

Delete account

Refivu
Refivu

Sign up