StarCoder2 is a 3-billion-parameter code-generation model designed for practical local inference. It was trained on more than 3 trillion tokens spanning 17 programming languages and curated natural-language sources. Grouped-query attention speeds inference, while its 16,384-token context includes 4,096-token sliding-window attention. section 7.2.4
Use StarCoder2 with these operational boundaries:
- Prompt a function header, comment, or docstring when generating code; because the model is not instruction-tuned, function-body completion is its strongest stated use. section 7.2.4
- Load the model through Hugging Face Transformers, then generate with AutoModelForCausalLM or a text-generation pipeline. section 7.2.4
- Reduce memory requirements with Bitsandbytes 8-bit or 4-bit quantization; 4-bit loading reduces model size by about 75% while preserving acceptable quality. section 7.2.4 section 7.4
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "bigcode/starcoder2-3b"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id,
device_map='auto',
torch_dtype=torch.bfloat16)
model.eval()
Shows the practical loading pattern for the StarCoder2-3B checkpoint with automatic device placement and bfloat16 inference. section 7.2.4
