TL;DR
StarCoder and StarCoderBase are open-access language models for source code, each with 15.5 billion parameters. StarCoderBase is trained on 1 trillion tokens of permissively licensed code, and StarCoder is that model fine-tuned on 35 billion more Python tokens. Three design choices stand out: the models can fill a gap in the middle of a file, they read 8,000 tokens at once, and they answer quickly with large batches because of multi-query attention. The abstract reports that StarCoder, prompted well, reaches 40% pass@1 on HumanEval, and that the team also built tools for licensing and privacy.
Builds on: Language Model, Transformer, Multi-Query Attention, Fine-Tuning · Leads to: the open code models that followed, which reuse its data governance and evaluation harness
Why it mattered
Code models became a daily tool quickly. The paper cites a major code assistant that had attracted over a million professional developers, and a vendor report that its users wrote about 35% of their code with it for some languages. That speed raised three concerns the paper takes seriously: copyright, privacy and openness. Lawsuits had been filed over training on public code, and European privacy rules asked model builders to say what personal data they had collected.
StarCoder answered with an open approach. The code was trained on The Stack, a dataset of permissively licensed code with a governance tool that lets developers check whether their files are in it and an opt-out process for removing them. The model weights were released under a responsible-use license, with restrictions on identified high-risk uses. For practitioners, the result was an open model that matched or beat the closed model code-cushman-001 on several benchmarks, which was the model behind the first version of a major code assistant.
The problem
Before StarCoder, the strongest code models were mostly closed. Open code models existed, but most were small, trained on less data, or released without their training data. Two gaps mattered for real use.
First, most code models read code only from left to right. A developer who edits the middle of a function needs the model to see the code after the cursor as well. Second, generating code is expensive when a model is serving many requests at once, because each request keeps a memory of its past tokens. The paper names both problems in its feature list: infilling and fast large-batch inference.
The third problem was trust. A model trained on public code can reproduce copyrighted or private text, and the authors wanted tools to detect that after release. The paper therefore covers data curation, personal-information removal and attribution along with the model itself.
How it works
The pipeline runs in the order the paper describes it, from data to model to evaluation. The numbers are the paper's own.
-
Collect permissively licensed code. The Stack v1.2 holds 6.4 TB of permissively licensed source code in 384 programming languages, plus GitHub issues and repository metadata. The team kept 80+ programming languages and also used GitHub issues, Git commits and Jupyter notebooks, each formatted differently.
-
Clean and redact. Duplicate files are removed, and the team trained a dedicated detector to find personal information. Its training set has 12,000 files with 22,950 annotated entities. Before training, the code data is also decontaminated: files containing solutions to test benchmarks such as HumanEval and MBPP are removed.
-
Format each example. A code file gets a short header with its repository name, file name and star count. Each header field is dropped at random with probability 0.2, so the model still works when the metadata is missing. Then the fill-in-the-middle transformation is applied to half of the files. The file is cut into three pieces: a prefix, a middle and a suffix. The model sees the prefix and suffix first and learns to write the middle last.
Tiny instance: the file is
x = 1 + 2. Cut it into prefixx =, middle1 +and suffix2. In the prefix-suffix-middle order, the model sees the words "x = ", then the suffix "2", then a marker that says "the middle comes next". Its training target is "1 + ". Check: on the rearranged files, the model predicts the missing piece while the suffix is already in view. -
Tokenize. A byte-level byte pair encoding turns text into 49,152 tokens, including the special markers used for formatting. Numbers are split into single digits before this step.
-
Pretrain StarCoderBase. The model is a decoder-only transformer with multi-query attention and learned absolute positional embeddings. It sees 1 trillion tokens with an 8,000-token context.
-
Fine-tune StarCoder. Starting from StarCoderBase, the team trained a Python variant on 35 billion Python tokens for about 2 epochs.
-
Evaluate. The models are tested on HumanEval and MBPP for simple Python problems, on DS-1000 for data-science workflows, on ODEX for open-domain library use, and on long-context perplexity.
flowchart LR A["The Stack: 6.4 TB, 384 languages"] --> B["Dedup and PII redaction"] B --> C["Format, add metadata, FIM on half the files"] C --> D["Byte-level BPE tokenizer"] D --> E["StarCoderBase: 1T tokens, 8K context"] E --> F["StarCoder: 35B Python tokens"] F --> G["Benchmarks and attribution tool"]
The math
Step 5 in symbols: the training objective
The model reads a sequence of tokens and is trained to predict each token from the ones before it. Its quality on held-out code is measured with perplexity:
A perplexity of 1 means the model predicted every token with certainty. Lower is better. The paper reports perplexity on 1K-token regions, computed with an 8K window and with a 2K window.
Step 3 in symbols: the infilling objective
Let a file be split into a prefix , a middle and a suffix . The rearranged training sequence is one of two orders. In the prefix-suffix-middle order the model reads , then , then predicts . The fill-in-the-middle rate is the fraction of files that receive this rearrangement, here 0.5. The paper applies the transformation at the character level.
Step 5 in symbols: why multi-query attention is cheap at inference
In attention, each token produces a key and a value for every head. Those keys and values are stored while generating, a store called the key-value cache. Let be the number of heads and the size of each head, so the hidden size is . For one layer, standard multi-head attention stores numbers per token. Multi-query attention stores one key and one value per layer, which is numbers per token. The saving factor is .
The architecture table gives StarCoder 48 heads and a hidden size of 6144, so each head has . Per layer, a token costs numbers with standard attention and with multi-query attention. That is a factor of 48. This is a calculation from the table, not a figure the paper reports as such.
Scoring code: pass@k
For a problem, generate samples and count the that pass every test. The unbiased estimate of pass@k, from the HumanEval paper, is
When , this reduces to , the fraction of samples that pass. The paper samples for open models, with temperature 0.2 for pass@1 and 0.8 for larger .
Worked examples
A model generates 200 solutions to one problem and 50 pass every test.
- Here and .
- With , pass@1 is .
- Across a benchmark, the score is the average of this fraction over all problems.
Interpretation: a pass@1 of 25% means that a single attempt solves this problem one time in four.
Use the architecture numbers from the paper's table: 40 layers, hidden size 6144, 48 heads. Store the cache in 16-bit numbers, which take 2 bytes each.
- Standard attention per token: numbers, which is bytes, about 0.98 MB.
- Multi-query attention per token: numbers, which is bytes, about 20 KB.
- For one full 8,192-token sequence, standard attention needs about GB and multi-query attention needs about GB.
Interpretation: with a cache this small, a GPU can hold many sequences at once. That is the reason the paper gives for fast large-batch inference.
Try it: if a model had 32 heads with the same hidden size, how many times smaller would its cache be under multi-query attention? Answer: 32 times, because the saving factor is the number of heads.
Results
Code benchmarks in Python. On HumanEval and MBPP, StarCoder is the strongest open-access model in the paper's comparison. Pass@1 figures:
| Model | Size | HumanEval | MBPP |
|---|---|---|---|
| LLaMA | 65B | 23.7 | 37.7 |
| CodeGen-Mono | 16B | 29.3 | 35.3 |
| StarCoderBase | 15.5B | 30.4 | 49.0 |
| StarCoder | 15.5B | 33.6 | 52.7 |
| code-cushman-001 | 12B | 33.5 | 45.9 |
| code-davinci-002 | 175B | 45.9 | 60.3 |
StarCoder is slightly above code-cushman-001 on HumanEval and well above it on MBPP. Its HumanEval score is well below the largest closed model, code-davinci-002.
Realistic data-science code. DS-1000 has 1,000 problems drawn from seven libraries. Overall completion scores are StarCoder 26.0, StarCoderBase 23.8, code-cushman-001 18.1 and CodeGen-16B-Mono 11.7. The paper's point is that HumanEval rankings do not always carry over: StarCoderBase and CodeGen-Mono are close on HumanEval (30.4 and 29.3), but on DS-1000 StarCoderBase scores 23.8 and CodeGen-Mono only 11.7.
Long context. Perplexity falls when the window grows from 2K to 8K tokens, for every one of the ten languages tested. Examples: C++ falls from 2.01 to 1.79, Go from 1.35 to 1.21 and Rust from 1.84 to 1.65.
Limits. The paper states several of its own limits. HumanEval and MBPP are short puzzles and do not represent most real code. Results for low-resource languages such as R vary between training checkpoints, and the authors trace this to the amount of data for each language. Training used 512 A100 GPUs, and the paper reports 16.68 tonnes of CO2-equivalent emissions for StarCoderBase. The license is a responsible-use license, not a free one. Attribution is a search tool, so it can flag possible copies but cannot prove that a generation is not new.
Reading guide
- §1 Introduction. Read it for the motivation (copyright, privacy, openness) and the list of contributions. The bullet points are the paper's own summary.
- §3 Data curation. Language coverage, Jupyter notebooks, GitHub issues and commits. Read it with Subword Tokenization in mind for later.
- §4 PII redaction. The detector and its training set. Skim §4.2 on StarEncoder unless you want the model details.
- §5.1 Data formatting. The sentinel-token templates and the fill-in-the-middle rate. Fill-in-the-Middle is the idea to hold onto here.
- §5.4–5.5 Architecture and training. Read these with Multi-Query Attention, Autoregressive Model, Adam Optimizer and Positional Encoding open. Table 11 is the one to compare with SantaCoder.
- §5.6 Multi-node setup. Read with Model Parallelism and Data Parallelism for the 16-GPU replica and 32-fold data parallelism.
- §6 Evaluation. Table 12 for HumanEval and MBPP, Table 13 for DS-1000. Pass@k and Evaluating Large Language Models Trained on Code define the scoring. Perplexity appears in §6.4.
- §7 Natural-language evaluation. Math, reading comprehension and harmful-generation tests. Lighter reading unless you care about general-purpose use.
- §9 Attribution tools. The membership check and the search index. Read after §4 to see how privacy and copying are handled.
- §10 Social impact and limitations. Read in full. It sets out the team's own doubts.
Check yourself
QuestionWhat does fill-in-the-middle let the model do that a plain left-to-right model cannot do as easily?Show answer
It lets the model write a missing piece of code in the middle of a file, using the code that comes after the gap as well as the code before it. The training data is rearranged so that the suffix is shown first and the model learns to write the middle last.
QuestionA model generates 200 solutions to a problem, and 50 of them pass all tests. What is its pass@1 for that problem?Show answer
With and , pass@1 is , or 25%.
QuestionWhy does multi-query attention matter for serving, and what is the saving on StarCoder's cache?Show answer
Every head in multi-query attention shares a single key and a single value per layer, so the cache stores one pair instead of one pair per head. Under the paper's architecture (48 heads), that is a factor of 48 smaller. A smaller cache lets the server hold more sequences at once, which is what makes large-batch inference fast.
QuestionA team wants a code model for data-science scripts. The announcement says StarCoder roughly matches code-cushman-001 on HumanEval. What evidence should they look at instead, and why?Show answer
They should look at DS-1000. HumanEval consists of short puzzles, where StarCoder (33.6) and code-cushman-001 (33.5) are nearly tied. On DS-1000, a benchmark of realistic data-science problems, StarCoder scores 26.0 overall against 18.1 for code-cushman-001. The paper also shows that the two benchmarks can rank models differently, so the one that matches the team's use is the more useful signal.
Sources
- Li et al., StarCoder: may the source be with you!, arXiv:2305.06161 (Transactions on Machine Learning Research). arxiv.org/abs/2305.06161
- DOI 10.48550/arXiv.2305.06161: doi.org/10.48550/arXiv.2305.06161