loubnabnl HF staff commited on
Commit
2cdb3d3
1 Parent(s): 088e2ed

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +150 -1
README.md CHANGED
@@ -1,5 +1,154 @@
1
  ---
 
 
 
 
 
 
 
 
2
  license: bigcode-openrail-m
 
 
 
3
  ---
4
 
5
- StarCoder2-3B (3.1T tokens) further trained on 200B of the pre-training corpus with a 16k context length.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ pipeline_tag: text-generation
3
+ inference: true
4
+ widget:
5
+ - text: 'def print_hello_world():'
6
+ example_title: Hello world
7
+ group: Python
8
+ datasets:
9
+ - bigcode/the-stack-v2-train
10
  license: bigcode-openrail-m
11
+ library_name: transformers
12
+ tags:
13
+ - code
14
  ---
15
 
16
+ # StarCoder2
17
+
18
+ <center>
19
+ <img src="https://huggingface.co/datasets/bigcode/admin_private/resolve/main/starcoder2_banner.png" alt="SC2" width="900" height="600">
20
+ </center>
21
+
22
+ ## Table of Contents
23
+
24
+ 1. [Model Summary](##model-summary)
25
+ 2. [Use](##use)
26
+ 3. [Limitations](##limitations)
27
+ 4. [Training](##training)
28
+ 5. [License](##license)
29
+ 6. [Citation](##citation)
30
+
31
+ ## Model Summary
32
+
33
+ StarCoder2-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.
34
+
35
+ - **Project Website:** [bigcode-project.org](https://www.bigcode-project.org)
36
+ - **Paper:** [Link](https://huggingface.co/datasets/bigcode/the-stack-v2/)
37
+ - **Point of Contact:** [contact@bigcode-project.org](mailto:contact@bigcode-project.org)
38
+ - **Languages:** 17 Programming languages
39
+
40
+ ## Use
41
+
42
+ ### Intended use
43
+
44
+ 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.
45
+
46
+ ### Generation
47
+ Here 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).
48
+
49
+ First, make sure to install `transformers` from source:
50
+ ```bash
51
+ pip install git+https://github.com/huggingface/transformers.git
52
+ ```
53
+
54
+ #### Running the model on CPU/GPU/multi GPU
55
+ * _Using full precision_
56
+ ```python
57
+ # pip install git+https://github.com/huggingface/transformers.git # TODO: merge PR to main
58
+ from transformers import AutoModelForCausalLM, AutoTokenizer
59
+
60
+ checkpoint = "bigcode/starcoder2-3b"
61
+ device = "cuda" # for GPU usage or "cpu" for CPU usage
62
+
63
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
64
+ # for multiple GPUs install accelerate and do `model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto")`
65
+ model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
66
+
67
+ inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to(device)
68
+ outputs = model.generate(inputs)
69
+ print(tokenizer.decode(outputs[0]))
70
+ ```
71
+ ```bash
72
+ >>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
73
+ Memory footprint: 12624.81 MB
74
+ ```
75
+ * _Using `torch.bfloat16`_
76
+ ```python
77
+ # pip install accelerate
78
+ import torch
79
+ from transformers import AutoTokenizer, AutoModelForCausalLM
80
+
81
+ checkpoint = "bigcode/starcoder2-3b"
82
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
83
+
84
+ # for fp16 use `torch_dtype=torch.float16` instead
85
+ model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16)
86
+
87
+ inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
88
+ outputs = model.generate(inputs)
89
+ print(tokenizer.decode(outputs[0]))
90
+ ```
91
+ ```bash
92
+ >>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
93
+ Memory footprint: 6312.41 MB
94
+ ```
95
+
96
+ #### Quantized Versions through `bitsandbytes`
97
+ * _Using 8-bit precision (int8)_
98
+
99
+ ```python
100
+ # pip install bitsandbytes accelerate
101
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
102
+
103
+ # to use 4bit use `load_in_4bit=True` instead
104
+ quantization_config = BitsAndBytesConfig(load_in_8bit=True)
105
+
106
+ checkpoint = "bigcode/starcoder2-3b"
107
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
108
+ model = AutoModelForCausalLM.from_pretrained(checkpoint, quantization_config=quantization_config)
109
+
110
+ inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
111
+ outputs = model.generate(inputs)
112
+ print(tokenizer.decode(outputs[0]))
113
+ ```
114
+ ```bash
115
+ >>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
116
+ # load_in_8bit
117
+ Memory footprint: 3434.07 MB
118
+ # load_in_4bit
119
+ >>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
120
+ Memory footprint: 1994.90 MB
121
+ ```
122
+ ### Attribution & Other Requirements
123
+
124
+ 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](TODO) that let's you search through the pretraining data to identify where generated code came from and apply the proper attribution to your code.
125
+
126
+ # Limitations
127
+
128
+ 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](TODO) for an in-depth discussion of the model limitations.
129
+
130
+ # Training
131
+
132
+ ## Model
133
+
134
+ - **Architecture:** Transformer decoder with grouped-query and sliding window attention and Fill-in-the-Middle objective
135
+ - **Pretraining steps:** 1.2 million
136
+ - **Pretraining tokens:** 3+ trillion
137
+ - **Precision:** bfloat16
138
+
139
+ ## Hardware
140
+
141
+ - **GPUs:** X A100
142
+
143
+ ## Software
144
+
145
+ - **Framework:** X
146
+ - **Neural networks:** [PyTorch](https://github.com/pytorch/pytorch)
147
+
148
+ # License
149
+
150
+ The 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).
151
+
152
+ # Citation
153
+
154
+ _Coming soon_