arXiv(opens in a new tab)Computer ScienceAug 2023Cited by 64 papers on PaperVantageClassic Paper

Manuscript Offprint

arXiv:2308.12950

Code Llama: Open Foundation Models for Code

Baptiste Rozière, Jonas Gehring, Fabian Gloeckle, Sten Sootla, Gat, Itai, Xiaoqing Ellen Tan, Yossi Adi, Jingyu Liu, Sauvestre, Romain, Tal Remez, Jérémy Rapin, Artyom Kozhevnikov, Ivan Evtimov, Joanna Bitton, Manish Bhatt, Cristian Canton Ferrer, Aaron Grattafiori, Wenhan Xiong, Défossez, Alexandre, Jade Copet, Azhar, Faisal, Hugo Touvron, Martin, Louis, Nicolas Usunier, Thomas Scialom, Gabriel Synnaeve

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

We release Code Llama, a family of large language models for code based on Llama 2 providing state-of-the-art performance among open models, infilling capabilities, support for large input contexts, and zero-shot instruction following ability for programming tasks. We provide multiple flavors to cover a wide range of applications: foundation models (Code Llama), Python specializations (Code Llama - Python), and instruction-following models (Code Llama - Instruct) with 7B, 13B, 34B, and 70B parameters each. These models are trained on sequences of 16k tokens and show improvements on inputs with up to 100k tokens. The 7B, 13B and 70B Code Llama and Code Llama - Instruct variants support infilling based on surrounding content. Code Llama reaches state-of-the-art performance among open models on several code benchmarks, with scores of up to 67% and 65% on HumanEval and MBPP, respectively. Notably, Code Llama - Python 7B outperforms Llama 2 70B on HumanEval and MBPP, and all our models outperform every other publicly available model on MultiPL-E. We release Code Llama under a permissive license that allows for both research and commercial use.

1 Introduction

Large language models (LLMs) power a rapidly increasing number of applications, having reached a proficiency in natural language that allows them to be commanded and prompted to perform a variety of tasks (OpenAI, 2023; Touvron et al., 2023b). By utilizing large, in-domain datasets, their efficacy can be greatly improved for applications that require a combination of both natural and domain-specific language and understanding of specialized terminology. By training on domain-specific datasets, they have proved effective more broadly on applications that require advanced natural language understanding. A prominent use-case is the formal interaction with computer systems, such as program synthesis from natural language specifications, code completion, debugging, and generating documentation (for a survey, see Xu & Zhu, 2022, also see Section 5). In this work, we present Code Llama, a family of LLMs for code generation and infilling derived from Llama 2 (Touvron et al., 2023b) and released under the same custom permissive license. We provide inference code for both completion and infilling models in the accompanying repository. Our approach is based on gradually specializing and increasing the capabilities of Llama 2 models by applying a cascade of training and fine-tuning steps (Figure 2):

  • Code-training from foundation models. While most LLMs for code generation such as AlphaCode (Li et al., 2022), InCoder (Fried et al., 2023) or StarCoder (Li et al., 2023) are trained on code only, Codex (Chen et al., 2021) was fine-tuned from a general language model. We also start from a foundation model (Touvron et al., 2023b, Llama 2,) pretrained on general-purpose text and code data. Our comparison (Section 3.4.1) shows that initializing our model with Llama 2 outperforms the same architecture trained on code only for a given budget.
  • Infilling. Autoregressive training and fine-tuning of LLMs is suitable for prompt completion, but does not provide the capability to fill a missing portion of text while taking the full surrounding context into account. Our code-training for 7B, 13B and 70B Code Llama models features a multitask objective (Fried et al., 2023) consisting of both autoregressive and causal infilling prediction, enabling applications such as real-time completion in source code editors or docstring generation.
  • Long input contexts. Unlocking repository-level reasoning for completion or synthesis – as opposed to function-level or file-level – requires prompting the model with much longer context than the 4,096 tokens supported by Llama 2. We propose an additional fine-tuning stage that extends the maximum context length from 4,096 tokens to 100,000 tokens by modifying the parameters of the RoPE positional embeddings (Su et al., 2021) used in Llama 2. Our experiments show Code Llama operating on very large contexts with a moderate impact on performances on standard coding benchmarks (Section 3.3).
  • Instruction fine-tuning. For end-users, the utility of LLMs is significantly improved by instruction fine-tuning (Ouyang et al., 2022; Wei et al., 2022; OpenAI, 2023; Touvron et al., 2023b), which also helps preventing unsafe, toxic or biased generations. Code Llama - Instruct variants are further fine-tuned on a mix of proprietary instruction data for improved safety and helpfulness, and a new machine-generated self-instruct dataset created by prompting Llama 2 for coding problems and Code Llama to generate associated unit tests and solutions. Our results show that Code Llama - Instruct significantly improves performance on various truthfulness, toxicity and bias benchmarks at moderate cost in terms of code generation performance (Section 4).

Different combinations of these approaches lead to a family of code-specialized Llama 2 models with three main variants that we release in four sizes (7B, 13B, 34B and 70B parameters):

  • Code Llama: a foundational model for code generation tasks,
  • Code Llama - Python: specialized for Python,
  • Code Llama - Instruct: fine-tuned with human instructions and self-instruct code synthesis data.

Prompt: In Bash, how do I list all text files in the current directory (excluding subdirectories) that have been modified in the last month Response: You can use the ‘find‘ command in Bash to list all text files in the current directory (excluding subdirectories) that have been modified in the last month. The command would be:

⬇

find . -maxdepth 1 -type f -mtime -30 -name "*.txt"

Here’s a breakdown of the command:

  • ‘.‘ specifies the current directory. * ‘-maxdepth 1‘ tells ‘find‘ to only search the current directory and not any subdirectories. * ‘-type f‘ tells ‘find‘ to only search for files (not directories or other types of files). * ‘-mtime -30‘ tells ‘find‘ to only search for files that have been modified in the last 30 days. * ‘-name "*.txt"‘ tells ‘find‘ to only search for files with the ‘.txt‘ extension.

Note that the ‘-mtime‘ option uses the number of days since the file was last modified, so ‘-mtime -30‘ means "modified in the last 30 days". If you want to search for files modified in the last month, you can use the ‘-mtime -30‘ option.

Figure 1: Example of response of Code Llama - Instruct (34B) when queried for a specific shell command.

An example of using Code Llama - Instruct is given in Figure 1. It show-cases that the model interprets natural language to determine suitable options for a command-line program and provides an explanation of the solution. We provide further qualitative examples in Appendix L. We perform exhaustive evaluations of our models on major code generation benchmarks: HumanEval (Chen et al., 2021), MBPP (Austin et al., 2021), and APPS (Hendrycks et al., 2021), as well as a multilingual version of HumanEval (Cassano et al., 2023, MultiPL-E,), where our best models establish a new state of the art amongst open-source LLMs. The technical details of our training and fine-tuning procedures are provided in Section 2, followed by in-depth experiments and ablation studies, details of the safety/helpfulness evaluations and a discussion of related work.

Figure 2: The Code Llama specialization pipeline. The different stages of fine-tuning annotated with the number of tokens seen during training. Infilling-capable models are marked with the ⇄\rightleftarrows symbol.

References (78)

  • CM3: A causal masked multimodal model of the internet
  • Unified pre-training for program understanding and generation
  • SantaCoder: Don’t reach for the stars! arXiv:abs/2301.03988, 2023
  • Falcon-40B: An open large language model with state-of-the-art performance, 2023
  • Program synthesis with large language models
  • Efficient training of language models to fill in the middle
  • Longformer: The long-document transformer
  • GPT-Neo: Large scale autoregressive language modeling with mesh-tensorflow, 2021 (opens the publisher in a new tab)
  • GPT-NeoX-20B: An open-source autoregressive language model
  • MultiPL-E: A scalable and polyglot approach to benchmarking neural code generation
  • CodeT: Code generation with generated tests
  • Evaluating large language models trained on code
  • Extending context window of large language models via positional interpolation
  • PaLM: Scaling language modeling with pathways
  • Training verifiers to solve math word problems
  • Transformer-XL: Attentive language models beyond a fixed-length context
  • BOLD: Dataset and metrics for measuring biases in open-ended language generation
  • LongNet: Scaling transformers to 1, 000, 000, 000 tokens
  • CodeBERT: A pre-trained model for programming and natural languages
  • InCoder: A generative model for code infilling and synthesis
  • LLM censorship: A machine learning challenge or a computer security problem? arXiv:abs/2307.10719, 2023
  • Textbooks are all you need
  • GraphCodeBERT: Pre-training code representations with data flow
  • LongCoder: A long-range pre-trained language model for code completion
  • ToxiGen: A large-scale machine-generated dataset for adversarial and implicit hate speech detection
  • Transformer language models without positional encodings still learn positional information
  • Measuring coding challenge competence with APPS. In NeurIPS Datasets and Benchmarks, 2021
  • Training compute-optimal large language models
  • The curious case of neural text degeneration
  • Unnatural instructions: Tuning language models with (almost) no human labor
  • Hutto and Eric Gilbert
  • Contrastive code representation learning
  • Impossible distillation: From low-quality model to high-quality dataset & model for summarization and paraphrasing
  • The impact of positional encoding on length generalization in transformers
  • SentencePiece: A simple and language independent subword tokenizer and detokenizer for Neural Text Processing
  • DOBF: A deobfuscation pre-training objective for programming languages
  • CodeRL: Mastering code generation through pretrained models and deep reinforcement learning
  • StarCoder: May the source be with you! arXiv:abs/2305.06161, 2023
  • Competition-level code generation with AlphaCode
  • TruthfulQA: Measuring how models mimic human falsehoods
  • RLTF: Reinforcement learning from unit test feedback
  • Lost in the middle: How language models use long contexts
  • RoBERTa: A robustly optimized BERT pretraining approach
  • Decoupled weight decay regularization
  • CodeXGLUE: A machine learning benchmark dataset for code understanding and generation
  • Model cards for model reporting
  • Meet in the middle: A new pre-training paradigm
  • CodeGen2: Lessons for training LLMs on programming and natural languages
  • CodeGen: An open large language model for code with multi-turn program synthesis
  • Training language models to follow instructions with human feedback
  • Bleu: A method for automatic evaluation of machine translation
  • The RefinedWeb dataset for falcon LLM: Outperforming curated corpora with web data, and web data only
  • Integrating tree path in transformer for code representation
  • Can OpenAI’s codex fix bugs?: An evaluation on QuixBugs
  • Train short, test long: Attention with linear biases enables input length extrapolation
  • Scaling language models: Methods, analysis & insights from training gopher
  • Exploring the limits of transfer learning with a unified text-to-text transformer
  • Unsupervised translation of programming languages
  • Leveraging automated unit tests for unsupervised code translation
  • Neural machine translation of rare words with subword units
  • Novel positional encodings to enable tree-based transformers
  • RoFormer: Enhanced transformer with rotary position embedding
  • A length-extrapolatable transformer
  • Code translation with compiler representations
  • Learning to fix build errors with Graph2Diff neural networks
  • LLaMA: Open and efficient foundation language models
  • Llama 2: Open foundation and fine-tuned chat models
  • Unit test case generation with transformers
  • Attention is all you need
  • GPT-J-6B: A 6 billion parameter autoregressive language model, 2021
  • CodeT5: Identifier-aware unified pre-trained encoder-decoder models for code understanding and generation
  • Finetuned language models are zero-shot learners
  • A survey on pretrained language models for neural code intelligence
  • Break-it-fix-it: Unsupervised learning for program repair
  • MEGABYTE: Predicting million-byte sequences with multiscale transformers
  • Repairing bugs in python assignments using large language models
  • Planning with large language models for code generation
  • OPT: Open pre-trained transformer language models

Cited by (64)