TL;DR
Meta AI has released Code Llama, a family of state-of-the-art open-source large language models (LLMs) specialized for code. Built on Llama 2, these models support massive 100k token contexts, offer specialized Python and instruction-following variants, and provide "infilling" capabilities—all under a permissive license for research and commercial use.
What Problem Does This Paper Address?
While general-purpose LLMs like Llama 2 are proficient in natural language, they often struggle with the specific logic, syntax, and long-range dependencies inherent in programming. Existing open-source code models frequently lack the ability to "fill in the middle" of a file (infilling), handle large codebases (long context), or follow complex natural language instructions for debugging and documentation. Code Llama aims to bridge this gap, providing a suite of models that rival closed-source alternatives like GPT-3.5 in coding proficiency while remaining accessible to the community.
Methods
The authors employ a "cascade" approach to training, gradually specializing the models through several stages:
- Code-Training: Starting from Llama 2 weights, the models are trained on 500B tokens of a code-heavy dataset.
- Python Specialization: For the Python variants, an additional 100B tokens of Python-specific data are used.
- Long Context Fine-Tuning (LCFT): To handle large inputs, the authors increased the context length from 4,096 to 16,384 tokens during fine-tuning. Crucially, they modified the Rotary Position Embedding (RoPE) base period ($\theta$) from 10,000 to 1,000,000. This simple change allows the model to extrapolate and remain stable for inputs up to 100,000 tokens.
- Instruction Fine-Tuning: The "Instruct" variants are tuned on a mix of proprietary safety data and a novel self-instruct dataset. This dataset was created by prompting Llama 2 70B to generate programming problems and then using Code Llama to generate unit tests and solutions, keeping only those that passed the tests.
Datasets
The models were trained and evaluated using a variety of sources:
- Training Data: A near-deduplicated dataset of publicly available code, supplemented by natural language discussions about code (8% of the mix) and general natural language data (7%) to maintain conversational skills.
- Evaluation Benchmarks: The authors used standard benchmarks like HumanEval and MBPP for Python, APPS for high-level problem solving, and MultiPL-E for multilingual evaluation (C++, Java, PHP, etc.).
Key Insights and Ideas
- Initialization is Key: The paper demonstrates that initializing from a general-purpose model (Llama 2) significantly outperforms training on code from scratch for the same compute budget.
- The Power of Specialization: Remarkably, the Code Llama - Python 7B model outperforms the much larger Llama 2 70B on Python benchmarks, proving that domain-specific training is highly efficient.
- RoPE Scaling Works: The shift in the RoPE base period is a standout technical detail. It provides a non-architectural way to unlock repository-level reasoning without the quadratic cost of training on massive sequences from the start.
- Infilling at No Cost: The authors found that adding a multitask infilling objective (predicting missing code given surrounding context) results in almost no performance degradation for standard left-to-right generation.
Key Results
Code Llama establishes a new state-of-the-art for open-source models:
- Performance: Code Llama 70B reached 53% on HumanEval and 62.4% on MBPP. The Instruct variant pushed these even further to 67.8% and 62.2%, respectively.
- Multilingual Mastery: All Code Llama variants outperformed every other publicly available model on the MultiPL-E benchmark across all tested languages.
- Context Stability: Perplexity (a measure of model uncertainty) continued to decrease up to 100k tokens, showing that the LCFT stage successfully enabled long-range reasoning.
Limitations and Future Work
- The Alignment Tax: Instruction fine-tuning for safety and helpfulness can slightly decrease raw coding performance (e.g., the 34B Instruct model scored lower on HumanEval than the base 34B model).
- False Refusals: The safety tuning can lead to "false refusals," where the model declines to answer benign prompts that resemble malicious requests (e.g., refusing to "kill a process" in Linux).
- Natural Language Trade-off: While excellent at code, these models are generally less capable at non-coding natural language tasks than the original Llama 2.
- Future Directions: The authors suggest further work is needed to help LLMs better understand the nuance and context of complex human instructions.
Summary updated