Purpose
Code Llama is a series of large language models for code released by Meta, developed based on Llama 2, and intended to provide code generation, code completion, and instruction-following capabilities for programming tasks. This repository (github.com/facebookresearch/codellama) provides minimal example code for loading Code Llama models and running inference.
Main Capabilities
- Provides leading performance among open-source models.
- Has infilling capability, allowing it to complete code based on surrounding content.
- Supports large input contexts: all models are trained on 16k token sequences and show improved performance on inputs of up to 100k tokens.
- Has zero-shot instruction-following capability for programming tasks.
- Provides multiple model variants: base models (Code Llama), Python-specialized models (Code Llama - Python), and instruction-following models (Code Llama - Instruct), each including 7B, 13B, and 34B parameter versions.
- The 7B and 13B Code Llama and Code Llama - Instruct variants support infilling based on contextual content.
Usage
- Download the model weights and tokenizer: visit the Meta website and accept the license agreement. After the request is approved, you will receive a signed URL by email. Then run the download.sh script, passing in that URL when prompted to start the download. Be careful to copy the URL text itself, not use the right-click "Copy link address" option. If the copied URL text starts with https://download.llamameta.net , then it was copied correctly; if it starts with https://l.facebook.com , then it was copied incorrectly.
- Prerequisites: make sure wget and md5sum are installed. Run the script: bash download.sh.
- The link expires after 24 hours and after a certain number of downloads. If you start seeing errors such as 403: Forbidden, you can request a new link.
- In a conda environment with PyTorch / CUDA, clone the repository and run it from the top-level directory.
- Different models require different model parallel (MP) values.
- Except for the 70B python and instruct versions, all models support sequence lengths of up to 100,000 tokens, but caches are preallocated according to the max_seq_len and max_batch_size values, so these values need to be set according to the hardware and use case.
Pretrained Code Models
The Code Llama and Code Llama - Python models have not been fine-tuned for instruction following and should be prompted so that the expected answer becomes a natural continuation of the prompt. See the examples in example_completion.py. The pretrained code models include: the Code Llama models CodeLlama-7b, CodeLlama-13b, CodeLlama-34b, CodeLlama-70b, and the Code Llama - Python models CodeLlama-7b-Python, CodeLlama-13b-Python, CodeLlama-34b-Python, CodeLlama-70b-Python.
Infilling
The 7B and 13B models of Code Llama and Code Llama - Instruct are able to infill code based on surrounding context. See the examples in example_infilling.py. The pretrained infilling models include: the Code Llama models CodeLlama-7b and CodeLlama-13b, and the Code Llama - Instruct models CodeLlama-7b-Instruct, CodeLlama-13b-Instruct.
Fine-Tuned Instruction Models
The Code Llama - Instruct models have been fine-tuned to follow instructions. To obtain 7B, 13B and the expected functionality and performance of the 34B variant, it is necessary to follow the specific format defined in chat_completion(), including the INST and <<SYS>> tags, the BOS and EOS tokens, and the whitespace and newlines between them (it is recommended to call strip() on the input to avoid double spaces). CodeLlama-70b-Instruct requires the separate turn prompt format defined in dialog_prompt_tokens(). You can directly use chat_completion() to generate answers for all instruct models, and it will automatically perform the required formatting.
Additional classifiers can also be deployed to filter inputs and outputs considered unsafe. See the examples in the llama-recipes repository on how to add safety checkers to the input and output of inference code. Fine-tuned instruction-following models include: Code Llama - Instruct models CodeLlama-7b-Instruct, CodeLlama-13b-Instruct, CodeLlama-34b-Instruct, CodeLlama-70b-Instruct.
Applicable Scenarios
Code Llama is aimed at individuals, creators, researchers, and businesses of all sizes, enabling them to responsibly experiment, innovate, and scale ideas. This release includes model weights and starter code for pretrained and fine-tuned Llama language models, with parameter ranges from 7B to 34B.
Limitations and Safety
Code Llama is a new technology, and there are potential risks in its use. The tests conducted so far have not covered, and cannot cover, all scenarios. To help developers address these risks, Meta created the Responsible Use Guide, and more details can be found in the research paper.
Output generated by the code generation capabilities of Llama Materials (including Code Llama) may be subject to third-party licenses, including but not limited to open source licenses.
The model and weights are licensed to both researchers and commercial entities, following open principles. See the LICENSE file and the accompanying Acceptable Use Policy.
Feedback
- Report model issues: github.com/facebookresearch/codellama
- Report risky content generated by the model:developers.facebook.com/llama_output_feedback
- Report bugs and security issues: facebook.com/whitehat/info
See MODEL_CARD.md for the model card of Code Llama.