bigcode/starcoder2-15b
6835.8k
1---2pipeline_tag: text-generation3inference:4 parameters:5 temperature: 0.26 top_p: 0.957widget:8- text: 'def print_hello_world():'9 example_title: Hello world10 group: Python11datasets:12- bigcode/the-stack-v2-train13license: bigcode-openrail-m14library_name: transformers15tags:16- code17model-index:18- name: starcoder2-15b19 results:20 - task:21 type: text-generation22 dataset:23 name: CruxEval-I24 type: cruxeval-i25 metrics:26 - type: pass@127 value: 48.128 - task:29 type: text-generation30 dataset:31 name: DS-100032 type: ds-100033 metrics:34 - type: pass@135 value: 33.836 - task:37 type: text-generation38 dataset:39 name: GSM8K (PAL)40 type: gsm8k-pal41 metrics:42 - type: accuracy43 value: 65.144 - task:45 type: text-generation46 dataset:47 name: HumanEval+48 type: humanevalplus49 metrics:50 - type: pass@151 value: 37.852 - task:53 type: text-generation54 dataset:55 name: HumanEval56 type: humaneval57 metrics:58 - type: pass@159 value: 46.360 - task:61 type: text-generation62 dataset:63 name: RepoBench-v1.164 type: repobench-v1.165 metrics:66 - type: edit-smiliarity67 value: 74.0868---69 70# StarCoder271 72<center>73 <img src="https://huggingface.co/datasets/bigcode/admin_private/resolve/main/starcoder2_banner.png" alt="SC2" width="900" height="600">74</center>75 76## Table of Contents77 781. [Model Summary](#model-summary)792. [Use](#use)803. [Limitations](#limitations)814. [Training](#training)825. [License](#license)836. [Citation](#citation)84 85## Model Summary86 87StarCoder2-15B model is a 15B parameter model trained on 600+ 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 4+ trillion tokens. 88The model was trained with [NVIDIA NeMo™ Framework](https://www.nvidia.com/en-us/ai-data-science/generative-ai/nemo-framework/) using the [NVIDIA Eos Supercomputer](https://blogs.nvidia.com/blog/eos/) built with [NVIDIA DGX H100](https://www.nvidia.com/en-us/data-center/dgx-h100/) systems.89 90- **Project Website:** [bigcode-project.org](https://www.bigcode-project.org)91- **Paper:** [Link](https://huggingface.co/papers/2402.19173)92- **Point of Contact:** [contact@bigcode-project.org](mailto:contact@bigcode-project.org)93- **Languages:** 600+ Programming languages94 95## Use96 97### Intended use98 99The 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.100 101### Generation102Here 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).103 104First, make sure to install `transformers` from source:105```bash106pip install git+https://github.com/huggingface/transformers.git107```108 109#### Running the model on CPU/GPU/multi GPU110* _Using full precision_111```python112# pip install git+https://github.com/huggingface/transformers.git # TODO: merge PR to main113from transformers import AutoModelForCausalLM, AutoTokenizer114 115checkpoint = "bigcode/starcoder2-15b"116device = "cuda" # for GPU usage or "cpu" for CPU usage117 118tokenizer = AutoTokenizer.from_pretrained(checkpoint)119# for multiple GPUs install accelerate and do `model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto")`120model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)121 122inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to(device)123outputs = model.generate(inputs)124print(tokenizer.decode(outputs[0]))125```126 127* _Using `torch.bfloat16`_128```python129# pip install accelerate130import torch131from transformers import AutoTokenizer, AutoModelForCausalLM132 133checkpoint = "bigcode/starcoder2-15b"134tokenizer = AutoTokenizer.from_pretrained(checkpoint)135 136# for fp16 use `torch_dtype=torch.float16` instead137model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16)138 139inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")140outputs = model.generate(inputs)141print(tokenizer.decode(outputs[0]))142```143```bash144>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")145Memory footprint: 32251.33 MB146```147 148#### Quantized Versions through `bitsandbytes`149* _Using 8-bit precision (int8)_150 151```python152# pip install bitsandbytes accelerate153from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig154 155# to use 4bit use `load_in_4bit=True` instead156quantization_config = BitsAndBytesConfig(load_in_8bit=True)157 158checkpoint = "bigcode/starcoder2-15b"159tokenizer = AutoTokenizer.from_pretrained(checkpoint)160model = AutoModelForCausalLM.from_pretrained(checkpoint, quantization_config=quantization_config)161 162inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")163outputs = model.generate(inputs)164print(tokenizer.decode(outputs[0]))165```166```bash167>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")168# load_in_8bit169Memory footprint: 16900.18 MB170# load_in_4bit171>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")172Memory footprint: 9224.60 MB173```174### Attribution & Other Requirements175 176The 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 let's you search through the pretraining data to identify where generated code came from and apply the proper attribution to your code.177 178# Limitations179 180The 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. 181 182# Training183 184## Model185 186- **Architecture:** Transformer decoder with grouped-query and sliding window attention and Fill-in-the-Middle objective187- **Pretraining steps:** 1 million188- **Pretraining tokens:** 4+ trillion189- **Precision:** bfloat16190 191## Hardware192 193- **GPUs:** 1024 x H100194 195## Software196 197- **Framework:** [NeMo Framework](https://www.nvidia.com/en-us/ai-data-science/generative-ai/nemo-framework/) 198- **Neural networks:** [PyTorch](https://github.com/pytorch/pytorch)199 200# License201 202The 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).203 204# Citation205 206```bash207@misc{lozhkov2024starcoder,208 title={StarCoder 2 and The Stack v2: The Next Generation}, 209 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},210 year={2024},211 eprint={2402.19173},212 archivePrefix={arXiv},213 primaryClass={cs.SE}214}215```