kp-forks/starcoder2-7b
035
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-7b19 results:20 - task:21 type: text-generation22 dataset:23 name: CruxEval-I24 type: cruxeval-i25 metrics:26 - type: pass@127 value: 34.628 - task:29 type: text-generation30 dataset:31 name: DS-100032 type: ds-100033 metrics:34 - type: pass@135 value: 27.836 - task:37 type: text-generation38 dataset:39 name: GSM8K (PAL)40 type: gsm8k-pal41 metrics:42 - type: accuracy43 value: 40.444 - task:45 type: text-generation46 dataset:47 name: HumanEval+48 type: humanevalplus49 metrics:50 - type: pass@151 value: 29.952 - task:53 type: text-generation54 dataset:55 name: HumanEval56 type: humaneval57 metrics:58 - type: pass@159 value: 35.460 - task:61 type: text-generation62 dataset:63 name: RepoBench-v1.164 type: repobench-v1.165 metrics:66 - type: edit-smiliarity67 value: 72.0768---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-7B model is a 7B 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.5+ trillion tokens. 88 89- **Project Website:** [bigcode-project.org](https://www.bigcode-project.org)90- **Paper:** [Link](https://huggingface.co/papers/2402.19173)91- **Point of Contact:** [contact@bigcode-project.org](mailto:contact@bigcode-project.org)92- **Languages:** 17 Programming languages93 94## Use95 96### Intended use97 98The 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.99 100### Generation101Here 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).102 103First, make sure to install `transformers` from source:104```bash105pip install git+https://github.com/huggingface/transformers.git106```107 108#### Running the model on CPU/GPU/multi GPU109* _Using full precision_110```python111# pip install git+https://github.com/huggingface/transformers.git # TODO: merge PR to main112from transformers import AutoModelForCausalLM, AutoTokenizer113 114checkpoint = "bigcode/starcoder2-7b"115device = "cuda" # for GPU usage or "cpu" for CPU usage116 117tokenizer = AutoTokenizer.from_pretrained(checkpoint)118# for multiple GPUs install accelerate and do `model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto")`119model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)120 121inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to(device)122outputs = model.generate(inputs)123print(tokenizer.decode(outputs[0]))124```125```bash126>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")127Memory footprint: 29232.57 MB128```129* _Using `torch.bfloat16`_130```python131# pip install accelerate132import torch133from transformers import AutoTokenizer, AutoModelForCausalLM134 135checkpoint = "bigcode/starcoder2-7b"136tokenizer = AutoTokenizer.from_pretrained(checkpoint)137 138# for fp16 use `torch_dtype=torch.float16` instead139model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16)140 141inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")142outputs = model.generate(inputs)143print(tokenizer.decode(outputs[0]))144```145```bash146>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")147Memory footprint: 14616.29 MB148```149 150#### Quantized Versions through `bitsandbytes`151* _Using 8-bit precision (int8)_152 153```python154# pip install bitsandbytes accelerate155from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig156 157# to use 4bit use `load_in_4bit=True` instead158quantization_config = BitsAndBytesConfig(load_in_8bit=True)159 160checkpoint = "bigcode/starcoder2-7b"161tokenizer = AutoTokenizer.from_pretrained(checkpoint)162model = AutoModelForCausalLM.from_pretrained(checkpoint, quantization_config=quantization_config)163 164inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")165outputs = model.generate(inputs)166print(tokenizer.decode(outputs[0]))167```168```bash169>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")170# load_in_8bit171Memory footprint: 7670.52 MB172# load_in_4bit173>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")174Memory footprint: 4197.64 MB175```176### Attribution & Other Requirements177 178The 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.179 180# Limitations181 182The model has been trained on source code from 17 programming languages. The predominant language in source is English although other languages are also present. As such the model is capable of generating code snippets provided some context but the generated code is not guaranteed to work as intended. It can be inefficient and contain bugs or exploits. See [the paper](https://huggingface.co/papers/2402.19173) for an in-depth discussion of the model limitations. 183 184# Training185 186## Model187 188- **Architecture:** Transformer decoder with grouped-query and sliding window attention and Fill-in-the-Middle objective189- **Pretraining steps:** 1 million190- **Pretraining tokens:** 3.5+ trillion191- **Precision:** bfloat16192 193## Hardware194 195- **GPUs:** 432 H100196 197## Software198 199- **Framework:** [nanotron](https://github.com/huggingface/nanotron/)200- **Neural networks:** [PyTorch](https://github.com/pytorch/pytorch)201 202# License203 204The 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).205 206# Citation207 208```bash209@misc{lozhkov2024starcoder,210 title={StarCoder 2 and The Stack v2: The Next Generation}, 211 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},212 year={2024},213 eprint={2402.19173},214 archivePrefix={arXiv},215 primaryClass={cs.SE}216}217```