Code Llama

On this page 7

Code Llama is a family of open-weight large language models for programming released by Meta in August 2023, created by further training Llama 2 on code-heavy data. In AI for coding, it was one of the first openly available model families to approach the quality of proprietary coding assistants, offering code generation, completion, fill-in-the-middle infilling and instruction-following chat in sizes that teams could run on their own hardware.

The family appeared in 7B, 13B and 34B parameter sizes, with a 70B model added in January 2024, and in three variants: a general code model, a Python specialist and an instruction-tuned model. Although newer code models have since overtaken it on benchmarks, Code Llama remains an important reference point for self-hosted code models and a common base for fine-tuning experiments.

How Code Llama was built from Llama 2

Code Llama was built by continued pretraining of Llama 2 rather than training from scratch, which let it inherit general language understanding while specializing in source code. The base models were trained on about 500 billion tokens of code and code-related text, and the 70B model on about one trillion tokens.

Three further training steps shaped the family. Smaller models received an infilling objective, so they could complete code between a given prefix and suffix. All models received long-context fine-tuning, which raised the rotary position embedding base frequency so the models could handle sequences far longer than the 4,096 tokens of Llama 2. Finally, the Instruct variants were fine-tuned on instruction data, including self-generated programming exercises verified by unit tests.

The resulting models were trained on 16,000-token sequences and reported stable behavior on inputs of up to about 100,000 tokens, enough to place several source files in a single prompt.

Code Llama variants and model sizes

Code Llama is a matrix of variants and sizes, and the right choice depends on the task and the available hardware. The following table summarizes the three variants.

VariantExtra trainingBest suited for
Code LlamaCode pretraining and long contextCompletion and infilling in many languages
Code Llama – PythonAbout 100 billion extra Python tokensPython-heavy completion
Code Llama – InstructInstruction and safety fine-tuningChat, explanation and code from descriptions
The three Code Llama variants

Model size determines memory needs, latency and capability. The figures below are approximate and depend on quantization and context length.

SizeMemory at 16-bitMemory at 4-bitTypical role
7BAbout 14 GBAbout 4 to 5 GBFast local autocomplete
13BAbout 26 GBAbout 8 GBBalanced completion and infilling
34BAbout 68 GBAbout 20 GBStronger reasoning on a single large GPU
70BAbout 140 GBAbout 40 GBHighest quality, multi-GPU serving
Approximate size trade-offs

Infilling support was limited to the 7B and 13B base and Instruct models at launch, which made those sizes the usual choice for editor autocomplete where the cursor sits in the middle of a file.

Code Llama benchmark results and comparisons

Code Llama was evaluated mainly on HumanEval and MBPP, two Python benchmarks that measure whether generated functions pass hidden unit tests. At release, the 34B base model reported about 53.7 percent pass@1 on HumanEval, and the later 70B Instruct model about 67.8 percent, figures well above earlier open models but below the leading proprietary systems of the time.

The comparison below places Code Llama among other open code model families that appear in the same Topic.

Model familyMain differencePractical implication
Code LlamaLlama 2 base, 2023 training dataWidely supported but dated knowledge
StarCoderTrained on permissively licensed codeClearer data provenance
DeepSeek-CoderLarge code corpus trained from scratchHigher benchmark scores at similar size
Qwen-CoderNewer base models and long contextStronger multilingual code performance
CodestralDedicated code model from Mistral AIFast completion with fill-in-the-middle
Code Llama compared with later open code models

Benchmark scores should be read with care. HumanEval contamination in training data, the small number of problems and the focus on short Python functions mean that pass rates say little about performance on large repositories or multi-file editing tasks.

Using Code Llama in development workflows

Code Llama is typically deployed as a self-hosted model behind an editor plugin or an internal API, which keeps source code inside the organization’s infrastructure. Common serving options include llama.cpp with quantized weights on workstations and GPU inference servers in data centers.

  • Autocomplete: a 7B or 13B base model with infilling gives low-latency suggestions inside the editor.
  • Code chat: the Instruct variant explains code, writes tests and drafts functions from descriptions.
  • Fine-tuning base: teams adapt the base model to internal frameworks with parameter-efficient methods such as LoRA.
  • Offline environments: air-gapped or regulated teams use it where cloud assistants are not permitted.

Prompt format matters. The Instruct models expect the Llama 2 chat template, while infilling requires special prefix, suffix and middle tokens; using the wrong format is a frequent cause of poor output.

Limitations and licensing of Code Llama

Code Llama is released under the Llama 2 Community License, which permits commercial use but adds an acceptable use policy and a special condition for services with more than 700 million monthly active users. It is therefore open-weight rather than open source in the strict sense.

Technical limitations follow from its age and size. Its training data ends in 2023, so it does not know newer library versions, and it is prone to package hallucination, suggesting dependencies that do not exist. Like all code models, its output needs review, testing and security scanning before it reaches production.

Teams evaluating Code Llama today should also weigh opportunity cost. Newer open-weight code models of similar size usually score higher, support more languages and follow instructions more reliably, so Code Llama is now chosen mainly for compatibility with existing pipelines, for research reproducibility or for fine-tuning projects already built on it. For new deployments, a short side-by-side trial on the team’s own repositories is more informative than published benchmark tables.

Explained without jargon

Code Llama is a computer program that writes computer code. It learned by reading a huge amount of existing code. Developers can ask it to finish a line, fill a gap or explain what a piece of code does.

Its key advantage is that a company can run it on its own computers. The code never has to leave the building. It is like hiring a junior helper who works in your office instead of sending work to an outside agency. The helper is fast and useful, but every result still needs checking.

A typical use case

A mid-sized bank wants AI code completion but forbids sending source code to external services. Its platform team deploys Code Llama 13B with 4-bit quantization on an internal server with two GPUs and connects it to the developers’ editors through an open-source plugin that uses fill-in-the-middle prompts.

After a three-month pilot with 40 developers, the team reports that most accepted suggestions are short completions such as boilerplate, logging calls and test scaffolding. To reduce mistakes in internal APIs, it fine-tunes the model with LoRA on the bank’s own libraries. The result is a private assistant that keeps code on premises, with every suggestion still passing the usual code review and automated tests.