StarCoder2 pairs fully auditable code provenance with aggressive data scaling beyond Chinchilla-optimal ratios. Built by the BigCode collaboration atop the Software Heritage (SWH) archive, The Stack v2 expands from 67.5 TB of raw snapshots (10x The Stack v1) into a curated 3 TB, 913.23B-token pretraining corpus spanning 619 programming languages, 4x larger than the original StarCoder dataset.

Training 3B, 7B, and 15B models for 4.49 to 5.31 epochs (3.1T to 4.1T tokens, plus 200B long-context tokens at 16k) makes the smallest and largest variants punch far above their weight: StarCoder2-3B beats StarCoderBase-15B on EvalPlus and DS-1000, while StarCoder2-15B matches or outperforms CodeLlama-34B and beats DeepSeekCoder-33B on math (65.1% vs 58.7% GSM8K PAL) and low-resource languages.

  • Full source lineage: every repository snapshot ties to immutable Software Heritage persistent identifiers (SWHIDs), backed by a 70 GB Bloom-filter Data Portrait and an Elasticsearch index for membership auditing.
  • Repository-level context and richer artifacts: replaces random-file packing with full-repository file grouping, 19.54B Pull Request tokens, 11.06B Issues, 32.71B notebooks, 10.26B Llama-2-70B-filtered StackOverflow Q&A, and 6B LLVM IR translation pairs.
  • Small and large standouts: StarCoder2-3B scores 27.4% on HumanEval+ and 47.4% on MBPP+ (beating StarCoderBase-15B’s 25.6% and 43.6%), while StarCoder2-15B reaches 37.8% HumanEval+, 53.1% MBPP+, and 48.1% CRUXEval-I.
  • Native Issue prompting: formatting bug-fix prompts like GitHub issues lifts StarCoder2-15B on HumanEvalFix from 22.0% (Instruct) to 38.7%, ahead of CodeLlama-34B-Instruct (28.4%).
Code completion and math reasoning across size classes (Pass@1 %, higher is better)
HumanEval+ (80x stricter unit tests)
StarCoder2-3B
27.4%
StarCoderBase-15B
25.6%
StarCoder2-15B
37.8%
DeepSeekCoder-33B
46.3%
GSM8K 8-shot PAL (Python program-aided math)
StarCoder2-15B
65.1%
DeepSeekCoder-33B
58.7%
CodeLlama-34B
54.2%

Bars scaled to 65.1% max. Source: Lozhkov et al. (2024), Tables 9 and 14.

Building The Stack v2 and StarCoder2

Because GitHub repositories change licenses, rename branches, or vanish, BigCode anchored The Stack v2 on Software Heritage’s deduplicated Merkle DAG (2023-09-06 crawl). The Stack v2 retains both permissively licensed and unlicensed code while dropping copyleft and commercial-restricted code; because GHArchive lacked repo-level license metadata for 96.93% of repositories, the team ran ScanCode Toolkit over license files and propagated SPDX IDs down directory trees.

To tailor capacity across model sizes, BigCode did not feed identical data to all three models. StarCoder2-3B trains on 622.09B unique tokens (17 major languages plus documentation, notebooks, PRs, issues, StackOverflow, and LLVM IR), StarCoder2-7B adds OpenWebMath, Wikipedia, and ArXiv (658.58B unique tokens), and StarCoder2-15B unlocks all 619 languages (913.23B unique tokens). All three use RoPE and Grouped Query Attention (2 KV heads on 3B, 4 on 7B and 15B), train past Chinchilla-optimal token counts for roughly 4.5 to 5.3 epochs under data-constrained scaling, and finish with 200B tokens at 16,384 context using FlashAttention-2 (4,096 sliding window).

How The Stack v2 turns a 67.5 TB archive into model-tiered training mixes
1. Source & hygiene
MinHashLSH (5-gram, Jaccard 0.7), ClamAV scan (59,442 malware files dropped), StarPII redaction, whitespace-normalized decontamination, and 1,561 opt-out repos removed.
2. Repo-context mix
Files from the same repo stay grouped; Java and JS downsampled to 200 GB each; 3B gets 17 languages (622B unique), 7B adds math/Wiki/ArXiv (659B), 15B adds all 619 languages (913B).
3. Audit & provenance
SWHID pointers for every snapshot, 70 GB Bloom Data Portrait for verbatim checks, and public Elasticsearch index.

Source: Lozhkov et al. (2024), Sections 2 through 5 and Section 8.

Key findings

Across repository-level completion (RepoBench v1.1 and CrossCodeEval), all StarCoder2 sizes consistently beat their StarCoderBase counterparts, reflecting both 16k context and grouping files by repository. StarCoder2-15B also excels on reasoning-heavy benchmarks (48.1% CRUXEval-I vs 47.2% for CodeLlama-34B; 43.08% descriptive / 38.45% lazy pass@1 on CanItEdit) and beats DeepSeekCoder-33B on four low-resource MultiPL-E languages (D 23.6%, Julia 33.2%, Lua 43.8%, Perl 37.2%), aided by 4M compiled LLVM IR pairs bridging 11 languages.

Equally important, the paper candidly documents three stumbles. First, a training bug lowered the Fill-in-the-Middle (FIM) rate for most of StarCoder2-15B’s run, leaving its Python FIM exact match (48.4%) well behind StarCoder2-7B (61.1%) and StarCoderBase-15B (62%). Second, a config-parsing bug trained 15B with RoPE theta = 1e4 instead of 1e5 and stopped at 1M iterations (4.1T tokens) rather than 1.1M. Third, StarCoder2-7B lags DeepSeekCoder-6.7B (35.4% vs 47.6% HumanEval), a gap the authors explicitly leave unexplained.

Caveats and builder takeaway

Openness cuts both ways on security and governance. On the Asleep at the Keyboard CWE suite, StarCoder2-7B (39.8%) and 15B (39.2%) emit insecure patterns at higher rates than CodeLlama-13B (30.2%), partly because generating valid, complete code exposes more vulnerability paths; downstream deployments still require static analysis and secret scanning. Traceable SWHIDs solve corpus auditability for compliance teams, though tracing individual snippets back to upstream repos remains non-trivial tooling work.

For teams picking an open code base model, StarCoder2-3B and StarCoder2-15B stand out for local completion, Python/math reasoning, and repository-level tasks (while 7B is a better choice than 15B only if single-line FIM infilling is critical).