Model reference · open weights
starcoder2 is an open-weight language model from bigcode. starcoder2-7b (BF16) weighs 14.3 GB; the smallest configuration that runs it is 2× RTX 3060 12 GB.
Summary of the bigcode/starcoder2-3b model card, 2026-10-01. The estimate below is for another build of the family.
What it is
| Released by | bigcode |
|---|---|
| Released | 2023-11-29 |
| Parameters | 3.0B |
| VRAM | 14.3 GB for the weights |
What it runs on
| Card | Requests at once | Context max | Memory |
|---|---|---|---|
| 8K each | |||
| RTX 3060 12 GB | — | — | 11.6 GB |
| RTX 4060 Ti 16 GB | — | 5K | 15.4 GB |
| RTX 3090 24 GB | 15 | all 16K | 23.4 GB |
| RTX 4090 24 GB | 15 | all 16K | 23.4 GB |
| RTX 5090 32 GB | 29 | all 16K | 31.0 GB |
| L40S 48 GB | 53 | all 16K | 44.0 GB |
| A100 80 GB | 117 | all 16K | 78.2 GB |
| H100 80 GB | 111 | all 16K | 78.1 GB |
| RTX PRO 6000 Blackwell 96 GB | 140 | all 16K | 93.8 GB |
| DGX Spark (GB10) 128 GB unified | 165 | all 16K | 107 GB |
| H200 141 GB | 222 | all 16K | 138 GB |
| B200 180 GB | 292 | all 16K | 176 GB |
| 2× RTX 3060 12 GB tensor parallel | 13 | all 16K | 11.6 GB a card |
| 2× RTX 4060 Ti 16 GB tensor parallel | 28 | all 16K | 15.4 GB a card |
| Requests at once | 8K tokens each |
|---|---|
| 1 | 15.6 GB |
| 5 | 17.7 GB |
| 8 | 19.3 GB |
| 16 | 23.6 GB |
| 32 | 32.2 GB |
| 64 | 49.4 GB |
One card, with vLLM's small-card settings.
Builds
| Build | Params | Precision | Weights | Smallest setup |
|---|---|---|---|---|
| starcoder2-3b ↗ | 3.0B | FP32 | 6.1 GB | RTX 3060 12 GB |
| starcoder2-7b (above) ↗ | 7.2B | BF16 | 14.3 GB | 2× RTX 3060 12 GB |
| starcoder2-15b ↗ | 16.0B | FP32 | 31.9 GB | L40S 48 GB |
| starcoder2-15b-instruct-v0.1 ↗ | 16.0B | BF16 | 31.9 GB | L40S 48 GB |
From the model card
StarCoder2-3B model is a 3B parameter model trained on 17 programming languages from The Stack v2, with opt-out requests excluded. The model uses Grouped Query Attention, a context window of 16,384 tokens with a sliding window attention of 4,096 tokens, and was trained using the Fill-in-the-Middle objective on 3+ trillion tokens.
The model was trained on GitHub code as well as additional selected data sources such as Arxiv and Wikipedia. As such it is not an instruction model and commands like "Write a function that computes the square root." do not work well.
Here are some examples to get started with the model. You can find a script for fine-tuning in StarCoder2's GitHub repository.
First, make sure to install transformers from source:
pip install git+https://github.com/huggingface/transformers.git
# pip install git+https://github.com/huggingface/transformers.git # TODO: merge PR to main
from transformers import AutoModelForCausalLM, AutoTokenizer
checkpoint = "bigcode/starcoder2-3b"
device = "cuda" # for GPU usage or "cpu" for CPU usage
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
# for multiple GPUs install accelerate and do `model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto")`
model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to(device)
outputs = model.generate(inputs)
print(tokenizer.decode(outputs[0]))
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
Memory footprint: 12624.81 MB
torch.bfloat16# pip install accelerate
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
checkpoint = "bigcode/starcoder2-3b"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
# for fp16 use `torch_dtype=torch.float16` instead
model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16)
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
outputs = model.generate(inputs)
print(tokenizer.decode(outputs[0]))
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
Memory footprint: 6312.41 MB
bitsandbytes# pip install bitsandbytes accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
# to use 4bit use `load_in_4bit=True` instead
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
checkpoint = "bigcode/starcoder2-3b"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForCausalLM.from_pretrained(checkpoint, quantization_config=quantization_config)
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
outputs = model.generate(inputs)
print(tokenizer.decode(outputs[0]))
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
# load_in_8bit
Memory footprint: 3434.07 MB
# load_in_4bit
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
Memory footprint: 1994.90 MB
The pretraining dataset of the model was filtered for permissive licenses and code with no license only. Nevertheless, the model can generate source code verbatim from the dataset. The code's license might require attribution and/or other specific requirements that must be respected. We provide a search index that lets you search through the pretraining data to identify where the generated code came from, and apply the proper attribution to your code.
The model has been trained on source code from 600+ programming languages. The predominant language in source is English although other languages are also present. As such the model is capable to generate code snippets provided some context but the generated code is not guaranteed to work as intended. It can be inefficient, contain bugs or exploits. See the paper for an in-depth discussion of the model limitations.
The model is licensed under the BigCode OpenRAIL-M v1 license agreement. You can find the full agreement here.
@misc{lozhkov2024starcoder,
title={StarCoder 2 and The Stack v2: The Next Generation},
author={Anton Lozhkov and Raymond Li and Loubna Ben Allal and Federico Cassano and Joel Lamy-Poirier and Nouamane Tazi and Ao Tang and Dmytro Pykhtar and Jiawei Liu and Yuxiang Wei and Tianyang Liu and Max Tian and Denis Kocetkov and ArthuQuoted from the model card on Hugging Face. The full card is behind the Hugging Face link above.
Benchmarks
As published on the model card: the maker's own numbers, not measured by AxForge.
| Task | Dataset | Metric | Score |
|---|---|---|---|
| text-generation | CruxEval-I | pass@1 | 32.700 |
| text-generation | DS-1000 | pass@1 | 25 |
| text-generation | GSM8K (PAL) | accuracy | 27.700 |
| text-generation | HumanEval+ | pass@1 | 27.400 |
| text-generation | HumanEval | pass@1 | 31.700 |
| text-generation | RepoBench-v1.1 | edit-smiliarity | 71.190 |