XYZNOT

Papers · arXiv 2302.13971

LLaMA: Open and Efficient Foundation Language Models

Published cs.CL arXivPDF

Read with translation and AI

Summary in three lines

  1. 🎯 Most leading LLMs rely on massive parameter counts or proprietary datasets, creating high serving costs and research access barriers.
  2. 🔧 Train compact transformer models (7B to 65B) on 1.0T to 1.4T tokens using only open-source data, RMSNorm, SwiGLU, and RoPE.
  3. 📈 LLaMA-13B outperforms GPT-3 (175B) on most benchmarks, while LLaMA-65B reaches 68.9% on MMLU after simple instruction tuning.

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.

Reading guide

Problem and motivation

Standard scaling laws (such as Chinchilla) compute the optimal trade-off between parameter size and dataset size for a fixed training compute budget. However, this framing neglects the inference budget, which dominates the lifetime operational cost of serving language models. For serving efficiency, smaller models trained on significantly more data than compute-optimal guidelines recommend are preferable because they are substantially cheaper to host and run.

Furthermore, premier state-of-the-art models (like GPT-3, Chinchilla, and PaLM) rely on private, non-reproducible datasets or prohibitively large architectures. LLaMA demonstrates that competitive foundation models can be trained exclusively on publicly available data, allowing open distribution to researchers.

Key ideas

  • Inference-centric training: Rather than stopping training at compute-optimal dataset sizes (e.g., ~200B tokens for a 10B model), LLaMA trains 7B and 13B models on 1.0T tokens, and 33B and 65B models on 1.4T tokens.
  • Open datasets only: All pre-training data is drawn from public sources: CommonCrawl (67%), C4 (15%), GitHub (4.5%), Wikipedia (4.5%), Books (4.5%), ArXiv (2.5%), and Stack Exchange (2%).
  • Modernized Transformer architecture: Incorporates pre-normalization with RMSNorm for stability, SwiGLU activations, and Rotary Positional Embeddings (RoPE) instead of absolute positions.
  • Engineering efficiency: Employs memory-efficient attention (via xformers), custom activation checkpointing, and sequence/model parallelism.

Method

LLaMA uses an autoregressive Transformer decoder with modifications:

  1. Pre-normalization: Input normalization using RMSNorm before each sub-layer:
  2. SwiGLU activation: Replaces standard ReLU/GELU activations with SwiGLU, sizing the intermediate dimension to instead of .
  3. Rotary Embeddings (RoPE): Applied at every layer to encode relative positions without absolute position embeddings.
  4. Optimization: AdamW with , weight decay of , gradient clipping of , warmup steps, and a cosine learning rate schedule decaying to 10% of maximum learning rate. Batch size is 4M tokens across all model scales.

Energy and carbon footprint estimation across training runs follows:

Results

  • Common Sense Reasoning: LLaMA-13B beats GPT-3 (175B) across multiple benchmarks (e.g., 78.1% vs 60.5% on BoolQ; 73.0% vs 70.2% on WinoGrande). LLaMA-65B matches or surpasses PaLM-540B on PIQA (82.8% vs 82.3%) and HellaSwag (84.2% vs 83.4%).
  • Closed-book QA: On TriviaQA (0-shot), LLaMA-65B reaches 68.2%, and LLaMA-13B reaches 56.6% (surpassing GPT-3's comparable performance while running on a single V100 GPU).
  • Code Generation: On HumanEval (pass@1), LLaMA-65B achieves 23.7%, outperforming PaLM-62B (15.9%) and matching PaLM-cont 62B (23.7%).
  • MMLU & Instruction Finetuning: Base LLaMA-65B reaches 63.4% 5-shot accuracy on MMLU (trailing PaLM-540B's 69.3%, likely due to smaller pre-training book corpora). However, instruction finetuning on basic prompts (LLaMA-I 65B) lifts performance to 68.9%.

Limitations and open questions

  • Hallucination and Truthfulness: Scores on TruthfulQA remain modest (LLaMA-65B scores 0.57 on Truthful and 0.53 on Truthful*Informative), showing a continuing tendency to hallucinate.
  • Toxicity scaling: On RealToxicityPrompts, toxicity increases with model size, especially on respectful prompts (0.141 for 65B vs 0.081 for 7B).
  • Academic knowledge gap: Performance on MMLU lagged behind Chinchilla-70B and PaLM-540B, which the authors hypothesize is due to training on only ~177GB of books and academic papers compared to ~2TB in proprietary sets.

Key terms

LLaMA
A collection of foundation language models ranging from 7B to 65B parameters trained on up to 1.4 trillion tokens using only public datasets.
Inference Budget
The computational cost and latency incurred when serving a trained model, prioritized by training smaller models on more tokens.
RMSNorm
Root Mean Square Layer Normalization, used to normalize the inputs to transformer sub-layers for training stability.
SwiGLU
A gated linear unit variant using the Swish activation function, sized at a hidden dimension of 2/3 * 4d.
Rotary Positional Embeddings (RoPE)
A technique that injects relative position information into transformer attention layers by rotating query and key representations.
xformers
An open-source library providing an efficient causal multi-head attention implementation that avoids storing large attention weight matrices.
LLaMA-I
The instruction-finetuned version of LLaMA-65B trained following the Flan protocol to improve instruction-following and MMLU performance.
TruthfulQA
A benchmark measuring an LLM's propensity to imitate human falsehoods and hallucinations across adversarial factual questions.

Questions

What datasets were used to pre-train LLaMA?

Pre-training exclusively used public data: English CommonCrawl (67%), C4 (15%), GitHub (4.5%), Wikipedia in 20 languages (4.5%), Gutenberg and Books3 (4.5%), ArXiv (2.5%), and Stack Exchange (2%).

How does LLaMA-13B compare to GPT-3 (175B)?

LLaMA-13B outperforms GPT-3 on most standard benchmarks—including BoolQ, PIQA, and WinoGrande—despite being over 10 times smaller and capable of running inference on a single consumer/datacenter GPU.

How long did it take to train LLaMA-65B?

Training LLaMA-65B on 1.4 trillion tokens processed approximately 380 tokens/sec/GPU across 2,048 80GB A100 GPUs, completing in roughly 21 days.

What architectural modifications does LLaMA make over the original Transformer?

LLaMA applies RMSNorm pre-normalization to sub-layer inputs, replaces ReLU with SwiGLU activations (dimension 2/3 * 4d), and swaps absolute positional embeddings for rotary position embeddings (RoPE).

The overview on this page was written by AI from the paper and may contain mistakes. Read the paper for the details.

Read with translation and AI