---
title: "Code Llama: Llama 2 learns to code"
description: "Code Llama is a family of 7B, 13B and 34B Llama 2 derivatives trained on 500B tokens of code."
url: "https://swe.quest/articles/code-llama-llama-2-learns-to-code-bbc6e9367fb26138"
canonical: "https://huggingface.co/blog/codellama"
source: "Hugging Face"
published: "2023-08-25"
difficulty: "medium"
kind: "How-to"
reading_minutes: 12
tags: ["llms","ai-coding","inference","python","evals"]
---

# Code Llama: Llama 2 learns to code

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2023-08-25, 12 min read, How-to. Original: [https://huggingface.co/blog/codellama](https://huggingface.co/blog/codellama)

## Summary

Code Llama is a family of 7B, 13B and 34B Llama 2 derivatives trained on 500B tokens of code. It comes in base, Python-specialized and instruction-tuned variants, has a 16k training context that extrapolates to 100k via RoPE frequency scaling, and supports fill-in-the-middle infilling in the 7B and 13B models. Hugging Face integration starts at transformers 4.33, with code for completion, infilling with the \<FILL\_ME\> token, the Llama 2 chat prompt template, and 4-bit bitsandbytes loading. Recommended setup is float16 for inference and bfloat16 for fine-tuning, plus GPU sizing guidance for TGI/Inference Endpoints and HumanEval/MultiPL-E evaluation.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [AI for coding](https://swe.quest/tags/ai-coding.md) (AI & ML)
- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)
- [Evaluation](https://swe.quest/tags/evals.md) (AI & ML)

## Prerequisites

- Hugging Face transformers
- PyTorch basics
- LLM prompting ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))

## Keywords

Code Llama, Llama 2, Hugging Face Transformers, Text Generation Inference, bitsandbytes, RoPE scaling, HumanEval, MultiPL-E

## Related posts

- [Code Llama: Meta’s state-of-the-art LLM for coding](https://swe.quest/articles/code-llama-meta-s-state-of-the-art-llm-for-coding-c2f826fd04e42ba1.md): Meta Engineering · 2023-08-24 · Easy · 7 min read · LLMs, AI for coding, Model training
  Code Llama is a code-specialized family of Llama 2 models, built by further training Llama 2 on 500B tokens of code (1T for the 70B model).
- [CodeGemma - an official Google release for code LLMs](https://swe.quest/articles/codegemma-an-official-google-release-for-code-llms-3ae6555e4222e566.md): Hugging Face · 2024-04-09 · Medium · 8 min read · LLMs, AI for coding, Inference & serving
  CodeGemma is a family of Gemma-based code models from Google: a 2B base model trained only on fill-in-the-middle infilling for fast, low-latency completion, a 7B base model mixing infilling (80%) with natural language, and a 7B instruct model for conversational coding.
- [Personal Copilot: Train Your Own Coding Assistant](https://swe.quest/articles/personal-copilot-train-your-own-coding-assistant-058d44307821dd4e.md): Hugging Face · 2023-10-27 · Hard · 15 min read · Model training, AI for coding, LLMs
  HugCoder is a code LLM fine-tuned on the top 10 Hugging Face GitHub repositories, built by cloning repos in parallel, filtering non-code files and training StarCoder with a fill-in-the-middle objective.
- [StarCoder: A State-of-the-Art LLM for Code](https://swe.quest/articles/starcoder-a-state-of-the-art-llm-for-code-ae224d2374e67db4.md): Hugging Face · 2023-05-04 · Easy · 5 min read · LLMs, AI for coding, Evaluation, Open source
  StarCoder and StarCoderBase are ~15B-parameter code LLMs trained on 1 trillion tokens of permissively licensed GitHub data from The Stack 1.2, covering 80+ languages, commits, issues and notebooks, with StarCoder further fine-tuned on 35B Python tokens.
- [StarCoder2-Instruct: Fully Transparent and Permissive Self-Alignment for Code Generation](https://swe.quest/articles/starcoder2-instruct-fully-transparent-and-permissive-self-alignment-for-code-7d548d6a3e65fc89.md): Hugging Face · 2024-04-29 · Hard · 6 min read · Model training, LLMs, AI for coding, Evaluation
  StarCoder2-15B-Instruct is instruction-tuned entirely on data generated by its own base model, with no human annotations or distillation from proprietary LLMs.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
