Papers · arXiv 2307.09288
Llama 2: Open Foundation and Fine-Tuned Chat Models
Summary in three lines
- 🎯 Open-access LLMs previously lacked the extensive alignment (RLHF) required to compete safely and effectively with closed proprietary chat models.
- 🔧 Pretrained 7B–70B models on 2T tokens with grouped-query attention, followed by high-quality SFT, dual reward modeling (safety and helpfulness), rejection sampling fine-tuning, PPO, and Ghost Attention (GAtt).
- 📈 Llama 2 70B reaches 68.9 on MMLU and 56.8 on GSM8K; Llama 2-Chat achieves a 36% win rate and 31.5% tie rate against ChatGPT in human evaluation.
Abstract
In this work, we develop and release Llama 2, a collection of pretrained and fine-tuned large language models (LLMs) ranging in scale from 7 billion to 70 billion parameters. Our fine-tuned LLMs, called Llama 2-Chat, are optimized for dialogue use cases. Our models outperform open-source chat models on most benchmarks we tested, and based on our human evaluations for helpfulness and safety, may be a suitable substitute for closed-source models. We provide a detailed description of our approach to fine-tuning and safety improvements of Llama 2-Chat in order to enable the community to build on our work and contribute to the responsible development of LLMs.
Reading guide
Problem and motivation
While open-access pretrained foundational models like LLaMA-1, BLOOM, and Falcon matched the raw base performance of models like GPT-3, closed commercial chat assistants (e.g., ChatGPT, Claude) maintained a significant lead. This performance advantage stemmed from intensive post-pretraining alignment via instruction tuning and Reinforcement Learning with Human Feedback (RLHF), which requires massive compute, proprietary annotation pipelines, and red-teaming. Meta developed and openly released Llama 2 and Llama 2-Chat (7B, 13B, and 70B parameters, plus an unreleased 34B variant) to democratize aligned dialogue models and provide transparent methodologies for alignment and safety.
Key ideas
- Expanded Pretraining: Pretrained on 2.0 trillion tokens (a 40% increase over Llama 1) with context doubled to 4,096 tokens, and Grouped-Query Attention (GQA) introduced for the 34B and 70B models to accelerate autoregressive decoding.
- Quality-Centric SFT: Demonstrates that tens of thousands of high-quality vendor annotations outperform millions of noisy third-party examples, capping SFT at 27,540 curated demonstrations.
- Dual Reward Modeling: Trains two distinct reward models—one for Helpfulness and one for Safety—to avoid the tension where safety constraints degrade helpfulness.
- Two-Stage RLHF Alignment: Combines iterative Rejection Sampling fine-tuning (distilled from 70B) with subsequent Proximal Policy Optimization (PPO).
- Ghost Attention (GAtt): A context-distillation technique applied across multi-turn dialogues to preserve persistent system instructions across 20+ conversation turns without instruction fading.
Method
Pretraining Architecture
Llama 2 uses an autoregressive transformer architecture featuring RMSNorm pre-normalization, SwiGLU activations, and rotary positional embeddings (RoPE), with GQA added to larger scales (34B and 70B). Models were trained with AdamW (eta_1=0.9, eta_2=0.95), cosine learning rate decay down to 10%, weight decay of 0.1, and gradient clipping of 1.0.
Reward Modeling
Human annotators provide 4-point scale comparative preferences between two sampled responses. Reward models are initialized from pretrained chat checkpoints and optimized with a margin-augmented binary ranking loss: where is the prompt context, is the preferred response, is the rejected response, and is a discrete margin dependent on annotator preference intensity.
RLHF Objectives
Optimization is performed via Rejection Sampling (sampling completions from the latest policy and picking the highest-reward completion) and PPO. The PPO objective maximizes expected reward while penalizing policy drift via KL divergence against the initial policy : where is a whitened, logit-transformed piecewise combination of safety () and helpfulness () reward models:
Ghost Attention (GAtt)
To force multi-turn consistency, instruction is synthetically appended to each user prompt in an existing dialogue. Responses are sampled from the latest policy, but the loss is computed exclusively on the target turn's tokens (zeroing loss on earlier turns) while retaining only in the first turn at inference time.
Results
- Base Model Benchmarks: Llama 2 70B outperforms all open-source base models, achieving 68.9 on MMLU (5-shot), 56.8 on GSM8K (8-shot), and 51.2 on Big-Bench Hard (3-shot), rivaling GPT-3.5 and PaLM-540B.
- Human Dialogue Evaluations: In human evaluations spanning ~4,000 prompts, Llama 2-Chat 70B scored a 36% win rate and 31.5% tie rate against ChatGPT (gpt-3.5-turbo-0301). Llama 2-Chat 34B won over 75% of head-to-head comparisons against Vicuna-33B and Falcon 40B.
- Safety & Toxicity: Safety-aligned Llama 2-Chat reduced toxic generation rates on ToxiGen from 24.60% (base 70B) down to 0.01%, showing lower safety violation percentages than ChatGPT and Falcon across human red-team benchmarks.
Limitations and open questions
- Coding & Complex Reasoning: Llama 2 70B lags substantially behind GPT-4 and PaLM-2-L on coding benchmarks (HumanEval pass@1 of 29.9% vs. 67.0% for GPT-4).
- Language Coverage: Approximately 89.7% of the pretraining data is English, making model performance and safety alignment brittle in other languages.
- False Refusals & Over-conservatism: Rigorous safety tuning introduces borderline prompt false refusals (e.g., refusing benign queries that mention words like 'bomb' or 'Christmas Crack').
- 34B Release Delay: The 34B model variant was withheld from public release due to insufficient red-teaming time prior to publication.
Key terms
- Grouped-Query Attention (GQA)
- An attention variant sharing key and value heads across query head groups to reduce KV-cache memory bandwidth and improve inference speed on large models.
- Reinforcement Learning with Human Feedback (RLHF)
- An alignment procedure using human pairwise preferences to train reward models that guide policy optimization via PPO and rejection sampling.
- Rejection Sampling fine-tuning
- A technique that samples multiple candidates per prompt, selects the highest scoring output under the reward model, and uses it as ground truth for supervised gradient updates.
- Ghost Attention (GAtt)
- A fine-tuning method that synthetically preserves instructions across multi-turn dialogues by adjusting prompt context and masking intermediate token loss.
- Safety RM and Helpfulness RM
- Two distinct reward models trained separately on safety-adversarial and general helpfulness comparisons to avoid optimization trade-offs.
- Context Distillation
- A technique that generates model completions conditioned on a safety preprompt and then fine-tunes the base model on those outputs without the preprompt.
- False Refusal
- An erroneous behavior where the model refuses to answer a legitimate, safe user prompt due to overly sensitive safety heuristics or trigger words.
- Inter-Rater Reliability (IRR)
- A statistical measure (evaluated using Gwet's AC1/2) quantifying the level of agreement among human annotators judging safety and helpfulness.
Questions
What parameter sizes of Llama 2 are publicly released?
Meta released 7B, 13B, and 70B parameter variants for both base Llama 2 and dialogue-optimized Llama 2-Chat; the 34B variant was evaluated in the paper but withheld from release due to time constraints on red-teaming.
How does Llama 2 differ from Llama 1 in pretraining data and architecture?
Llama 2 trained on 2.0 trillion tokens (40% more than Llama 1), doubled the context window to 4,096 tokens, and added Grouped-Query Attention (GQA) for the 34B and 70B configurations.
Why did the authors train separate safety and helpfulness reward models?
Helpfulness and safety frequently conflict during preference modeling (e.g., fulfilling an unsafe request is helpful but violating). Decoupling them allows dedicated optimization and prevents one objective from degrading the other.
How does Ghost Attention (GAtt) prevent multi-turn instruction forgetting?
GAtt appends the system instruction to user turns across synthetic multi-turn chats, samples responses, and trains the model while applying loss solely to the target turn with the instruction removed from intermediate turns, teaching attention layers to focus on the initial system message throughout long dialogues.
The overview on this page was written by AI from the paper and may contain mistakes. Read the paper for the details.