lvwerra HF staff loubnabnl HF staff commited on
Commit
5c5e0d3
1 Parent(s): 44b897e

Update README.md (#1)

Browse files

- Update README.md (76e8fbdf1800812e71ff7368ce591f79010ecabe)
- fill some TODOs (305c68b8d60c3d6258156db913de66b8a93ed81e)
- add examples for loading in other precisions + banner (8db4e164d1ca9aa5ccbfe4ba9ec8f1264d887fb8)
- Update README.md (0115eb77d8f40af58a172b96659d1220c368adf2)
- Update README.md (db9afcd1f253b15e73983b420ad41fab36a14d7f)


Co-authored-by: Loubna Ben Allal <loubnabnl@users.noreply.huggingface.co>

Files changed (1) hide show
  1. README.md +148 -0
README.md CHANGED
@@ -1,3 +1,151 @@
1
  ---
 
 
 
 
 
 
 
 
2
  license: bigcode-openrail-m
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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-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.
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:** 600+ 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-15b"
61
+ device = "cuda" # for GPU usage or "cpu" for CPU usage
62
+
63
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
64
+ # to use Multiple GPUs 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
+
72
+ * _Using `torch.bfloat16`_
73
+ ```python
74
+ # pip install accelerate
75
+ import torch
76
+ from transformers import AutoTokenizer, AutoModelForCausalLM
77
+
78
+ checkpoint = "bigcode/starcoder2-15b"
79
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
80
+
81
+ # for fp16 use `torch_dtype=torch.float16` instead
82
+ model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16)
83
+
84
+ inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
85
+ outputs = model.generate(inputs)
86
+ print(tokenizer.decode(outputs[0]))
87
+ ```
88
+ ```bash
89
+ >>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
90
+ Memory footprint: 32251.33 MB
91
+ ```
92
+
93
+ #### Quantized Versions through `bitsandbytes`
94
+ * _Using 8-bit precision (int8)_
95
+
96
+ ```python
97
+ # pip install bitsandbytes accelerate
98
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
99
+
100
+ # to use 4bit use `load_in_4bit=True` instead
101
+ quantization_config = BitsAndBytesConfig(load_in_8bit=True)
102
+
103
+ checkpoint = "bigcode/starcoder2-15b_16k"
104
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
105
+ model = AutoModelForCausalLM.from_pretrained("bigcode/starcoder2-15b_16k", quantization_config=quantization_config)
106
+
107
+ inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
108
+ outputs = model.generate(inputs)
109
+ print(tokenizer.decode(outputs[0]))
110
+ ```
111
+ ```bash
112
+ >>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
113
+ # load_in_8bit
114
+ Memory footprint: 16900.18 MB
115
+ # load_in_4bit
116
+ >>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
117
+ Memory footprint: 9224.60 MB
118
+ ```
119
+ ### Attribution & Other Requirements
120
+
121
+ 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.
122
+
123
+ # Limitations
124
+
125
+ 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.
126
+
127
+ # Training
128
+
129
+ ## Model
130
+
131
+ - **Architecture:** Transformer decoder with grouped-query and sliding window attention and Fill-in-the-Middle objective
132
+ - **Pretraining steps:** 1 million
133
+ - **Pretraining tokens:** 4+ trillion
134
+ - **Precision:** bfloat16
135
+
136
+ ## Hardware
137
+
138
+ - **GPUs:** 1024 A100
139
+
140
+ ## Software
141
+
142
+ - **Framework:** [NeMo](https://github.com/NVIDIA/NeMo)
143
+ - **Neural networks:** [PyTorch](https://github.com/pytorch/pytorch)
144
+
145
+ # License
146
+
147
+ 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).
148
+
149
+ # Citation
150
+
151
+ _Coming soon_