bigcode/starcoder2-3b
22445k
1---2pipeline_tag: text-generation3inference: true4widget:5- text: 'def print_hello_world():'6 example_title: Hello world7 group: Python8datasets:9- bigcode/the-stack-v2-train10license: bigcode-openrail-m11library_name: transformers12tags:13- code14model-index:15- name: starcoder2-3b16 results:17 - task:18 type: text-generation19 dataset:20 name: CruxEval-I21 type: cruxeval-i22 metrics:23 - type: pass@124 value: 32.725 - task:26 type: text-generation27 dataset:28 name: DS-100029 type: ds-100030 metrics:31 - type: pass@132 value: 25.033 - task:34 type: text-generation35 dataset:36 name: GSM8K (PAL)37 type: gsm8k-pal38 metrics:39 - type: accuracy40 value: 27.741 - task:42 type: text-generation43 dataset:44 name: HumanEval+45 type: humanevalplus46 metrics:47 - type: pass@148 value: 27.449 - task:50 type: text-generation51 dataset:52 name: HumanEval53 type: humaneval54 metrics:55 - type: pass@156 value: 31.757 - task:58 type: text-generation59 dataset:60 name: RepoBench-v1.161 type: repobench-v1.162 metrics:63 - type: edit-smiliarity64 value: 71.1965---66 67# StarCoder268 69<center>70 <img src="https://huggingface.co/datasets/bigcode/admin_private/resolve/main/starcoder2_banner.png" alt="SC2" width="900" height="600">71</center>72 73## Table of Contents74 751. [Model Summary](##model-summary)762. [Use](##use)773. [Limitations](##limitations)784. [Training](##training)795. [License](##license)806. [Citation](##citation)81 82## Model Summary83 84StarCoder2-3B model is a 3B parameter model trained on 17 programming languages from [The Stack v2](https://huggingface.co/datasets/bigcode/the-stack-v2-train), with opt-out requests excluded. The model uses [Grouped Query Attention](https://arxiv.org/abs/2305.13245), [a context window of 16,384 tokens](https://arxiv.org/abs/2205.14135) with [a sliding window attention of 4,096 tokens](https://arxiv.org/abs/2004.05150v2), and was trained using the [Fill-in-the-Middle objective](https://arxiv.org/abs/2207.14255) on 3+ trillion tokens. 85 86- **Project Website:** [bigcode-project.org](https://www.bigcode-project.org)87- **Paper:** [Link](https://huggingface.co/papers/2402.19173)88- **Point of Contact:** [contact@bigcode-project.org](mailto:contact@bigcode-project.org)89- **Languages:** 17 Programming languages90 91## Use92 93### Intended use94 95The 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.96 97### Generation98Here are some examples to get started with the model. You can find a script for fine-tuning in StarCoder2's [GitHub repository](https://github.com/bigcode-project/starcoder2).99 100First, make sure to install `transformers` from source:101```bash102pip install git+https://github.com/huggingface/transformers.git103```104 105#### Running the model on CPU/GPU/multi GPU106* _Using full precision_107```python108# pip install git+https://github.com/huggingface/transformers.git # TODO: merge PR to main109from transformers import AutoModelForCausalLM, AutoTokenizer110 111checkpoint = "bigcode/starcoder2-3b"112device = "cuda" # for GPU usage or "cpu" for CPU usage113 114tokenizer = AutoTokenizer.from_pretrained(checkpoint)115# for multiple GPUs install accelerate and do `model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto")`116model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)117 118inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to(device)119outputs = model.generate(inputs)120print(tokenizer.decode(outputs[0]))121```122```bash123>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")124Memory footprint: 12624.81 MB125```126* _Using `torch.bfloat16`_127```python128# pip install accelerate129import torch130from transformers import AutoTokenizer, AutoModelForCausalLM131 132checkpoint = "bigcode/starcoder2-3b"133tokenizer = AutoTokenizer.from_pretrained(checkpoint)134 135# for fp16 use `torch_dtype=torch.float16` instead136model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16)137 138inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")139outputs = model.generate(inputs)140print(tokenizer.decode(outputs[0]))141```142```bash143>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")144Memory footprint: 6312.41 MB145```146 147#### Quantized Versions through `bitsandbytes`148* _Using 8-bit precision (int8)_149 150```python151# pip install bitsandbytes accelerate152from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig153 154# to use 4bit use `load_in_4bit=True` instead155quantization_config = BitsAndBytesConfig(load_in_8bit=True)156 157checkpoint = "bigcode/starcoder2-3b"158tokenizer = AutoTokenizer.from_pretrained(checkpoint)159model = AutoModelForCausalLM.from_pretrained(checkpoint, quantization_config=quantization_config)160 161inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")162outputs = model.generate(inputs)163print(tokenizer.decode(outputs[0]))164```165```bash166>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")167# load_in_8bit168Memory footprint: 3434.07 MB169# load_in_4bit170>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")171Memory footprint: 1994.90 MB172```173### Attribution & Other Requirements174 175The 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](https://huggingface.co/spaces/bigcode/search-v2) that lets you search through the pretraining data to identify where the generated code came from, and apply the proper attribution to your code.176 177# Limitations178 179The 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](https://huggingface.co/papers/2402.19173) for an in-depth discussion of the model limitations. 180 181# Training182 183## Model184 185- **Architecture:** Transformer decoder with grouped-query and sliding window attention and Fill-in-the-Middle objective186- **Pretraining steps:** 1.2 million187- **Pretraining tokens:** 3+ trillion188- **Precision:** bfloat16189 190## Hardware191 192- **GPUs:** 160 A100193 194## Software195 196- **Framework:** TODO197- **Neural networks:** [PyTorch](https://github.com/pytorch/pytorch)198 199# License200 201The model is licensed under the BigCode OpenRAIL-M v1 license agreement. You can find the full agreement [here](https://huggingface.co/spaces/bigcode/bigcode-model-license-agreement).202 203# Citation204 205```bash206@misc{lozhkov2024starcoder,207 title={StarCoder 2 and The Stack v2: The Next Generation}, 208 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 Arthur Zucker and Younes Belkada and Zijian Wang and Qian Liu and Dmitry Abulkhanov and Indraneil Paul and Zhuang Li and Wen-Ding Li and Megan Risdal and Jia Li and Jian Zhu and Terry Yue Zhuo and Evgenii Zheltonozhskii and Nii Osae Osae Dade and Wenhao Yu and Lucas Krauß and Naman Jain and Yixuan Su and Xuanli He and Manan Dey and Edoardo Abati and Yekun Chai and Niklas Muennighoff and Xiangru Tang and Muhtasham Oblokulov and Christopher Akiki and Marc Marone and Chenghao Mou and Mayank Mishra and Alex Gu and Binyuan Hui and Tri Dao and Armel Zebaze and Olivier Dehaene and Nicolas Patry and Canwen Xu and Julian McAuley and Han Hu and Torsten Scholak and Sebastien Paquet and Jennifer Robinson and Carolyn Jane Anderson and Nicolas Chapados and Mostofa Patwary and Nima Tajbakhsh and Yacine Jernite and Carlos Muñoz Ferrandis and Lingming Zhang and Sean Hughes and Thomas Wolf and Arjun Guha and Leandro von Werra and Harm de Vries},209 year={2024},210 eprint={2402.19173},211 archivePrefix={arXiv},212 primaryClass={cs.SE}213}214```