TL;DR
Meta AI has released Code Llama, a family of open-source large language models specifically trained for code generation and understanding. These models, built on Llama 2, achieve state-of-the-art performance on various coding benchmarks, offer advanced capabilities like code infilling and handling long contexts, and are released under a permissive license for both research and commercial use.
What Problem Does This Paper Address?
The paper addresses the growing need for powerful, open-source AI models that can understand and generate code. While general-purpose LLMs have shown some coding capabilities, specialized models are crucial for tasks like program synthesis, code completion, debugging, and documentation. Existing open-source code models often lag behind proprietary ones in performance, lack advanced features like infilling or long-context understanding, or are not readily available for commercial use. This paper aims to bridge this gap by releasing a family of high-performing, versatile, and open code LLMs.
Methods
Code Llama is built upon the Llama 2 foundation model. The researchers employed a multi-stage fine-tuning process:
- Code-training: The base Llama 2 models were further trained on a massive dataset of publicly available code (500B tokens for most models, 1T for the 70B model). This stage imbues the models with strong code generation capabilities.
- Infilling: For some variants (7B, 13B, and 70B), an additional objective was introduced to enable "fill-in-the-middle" (FIM) capabilities. This allows the model to predict code that fits within a given context, not just at the end.
- Long Context Fine-Tuning (LCFT): To handle longer code sequences (up to 100k tokens, significantly more than Llama 2's 4k), the researchers modified the positional embeddings (ROPE) in the transformer architecture. This allows models to reason over much larger codebases.
- Instruction Fine-Tuning: For the "Instruct" variants, models were further fine-tuned on a mix of proprietary instruction data and a newly generated self-instruct dataset. This enhances their ability to follow human instructions, improves safety, and reduces bias.
- Python Specialization: A dedicated "Python" variant was created by further fine-tuning on a Python-heavy dataset, aiming to boost performance specifically for the Python language.
Datasets
- Training Data:
- Code-heavy dataset: Primarily near-deduplicated publicly available code.
- Natural language datasets related to code: Discussions and code snippets from Q&A sites.
- General natural language dataset: To retain natural language understanding skills.
- Python-heavy dataset: For the Code Llama - Python variant.
- Proprietary instruction tuning dataset: Inherited from Llama 2.
- Self-instruct dataset: Machine-generated question-test-solution triplets.
- Evaluation Benchmarks:
- HumanEval: For Python code generation.
- MBPP (Mostly Basic Python Problems): For Python code generation.
- APPS (Automated Programming Progress Standard): For code generation.
- MultiPL-E: A multilingual version of HumanEval for evaluating performance across various programming languages.
- GSM8K: For math reasoning capabilities.
- HumanEval infilling benchmarks: For evaluating code infilling capabilities.
- CodeXGLUE: For docstring generation.
- Safety benchmarks: TruthfulQA, ToxiGen, and BOLD for evaluating truthfulness, toxicity, and bias.
Key Insights and Ideas
- Specialization is Key: Fine-tuning a general LLM like Llama 2 on a large code dataset yields significant performance gains, even with a relatively small amount of additional data. Code Llama 7B, for instance, rivals Llama 2 70B on Python benchmarks.
- Long Context Matters: The ability to process long sequences (up to 100k tokens) is crucial for real-world code understanding and generation tasks, enabling reasoning over entire codebases. The modified ROPE embeddings are a novel way to achieve this.
- Infilling is Valuable: Code infilling capabilities are highly applicable for IDEs and code completion, and surprisingly, they can be integrated with minimal performance degradation on standard benchmarks.
- Safety and Instruction Following are Crucial: The "Instruct" variants demonstrate that fine-tuning for safety and instruction following can be achieved without significantly sacrificing coding performance, making the models more practical and responsible.
- Openness Drives Progress: Releasing these powerful models under a permissive license fosters research and commercial innovation in the AI for code space.
Key Results
- State-of-the-Art Performance: Code Llama achieves state-of-the-art performance among open models on benchmarks like HumanEval (up to 53% pass@1) and MBPP (up to 55% pass@1).
- Outperforming Larger Models: Code Llama - Python 7B outperforms Llama 2 70B on HumanEval and MBPP.
- Multilingual Strength: Code Llama models outperform all other publicly available models on the multilingual MultiPL-E benchmark.
- Long Context Extrapolation: Models show stable behavior and even slight perplexity decreases on sequences up to 100k tokens, far beyond their fine-tuning length.
- Safety Improvements: Code Llama - Instruct models show significant improvements in truthfulness and a drastic reduction in toxic generations, achieving near-zero toxicity.
- Commercial Viability: The permissive license allows for both research and commercial use.
Limitations and Future Work
- Performance on Short Contexts: Long context fine-tuning (LCFT) slightly degrades performance on standard benchmarks that focus on short code sequences. The authors believe this trade-off is acceptable given the benefits for real-world applications.
- Safety Evaluation Nuances: While safety benchmarks are used, the authors acknowledge that these evaluations alone don't provide a comprehensive understanding of risks. They complement this with red teaming and expert evaluations.
- False Refusals: Similar to other models, Code Llama - Instruct can sometimes exhibit "false refusals" (overly cautious responses), which they plan to investigate further.
- Further Training: The paper suggests that further training beyond 500B tokens could be beneficial, as indicated by the continued decrease in perplexity.
- Inference Schemes: Exploring more elaborate inference schemes on top of Code Llama is suggested as a future direction.
Summary updated