alexmarques
commited on
Commit
•
8c06594
1
Parent(s):
576d7bf
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
pipeline_tag: text-generation
|
3 |
+
datasets:
|
4 |
+
- bigcode/the-stack-v2-train
|
5 |
+
license: bigcode-openrail-m
|
6 |
+
library_name: transformers
|
7 |
+
tags:
|
8 |
+
- code
|
9 |
+
model-index:
|
10 |
+
- name: starcoder2-7b-quantized.w8a16
|
11 |
+
results:
|
12 |
+
- task:
|
13 |
+
type: text-generation
|
14 |
+
dataset:
|
15 |
+
name: HumanEval+
|
16 |
+
type: humanevalplus
|
17 |
+
metrics:
|
18 |
+
- type: pass@1
|
19 |
+
value: 26.4
|
20 |
+
- task:
|
21 |
+
type: text-generation
|
22 |
+
dataset:
|
23 |
+
name: HumanEval
|
24 |
+
type: humaneval
|
25 |
+
metrics:
|
26 |
+
- type: pass@1
|
27 |
+
value: 31.0
|
28 |
+
---
|
29 |
+
|
30 |
+
# starcoder2-7b-quantized.w8a16
|
31 |
+
|
32 |
+
## Model Overview
|
33 |
+
- **Model Architecture:** StarCoder2
|
34 |
+
- **Input:** Text
|
35 |
+
- **Output:** Text
|
36 |
+
- **Model Optimizations:**
|
37 |
+
- **Weight quantization:** INT8
|
38 |
+
- **Intended Use Cases:** Intended for commercial and research use. Similarly to [starcoder2-7b](https://huggingface.co/bigcode/starcoder2-7b), this model is intended for code generation and is _not_ an instruction model. Commands like "Write a function that computes the square root." do not work well.
|
39 |
+
- **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws).
|
40 |
+
- **Release Date:** 8/1/2024
|
41 |
+
- **Version:** 1.0
|
42 |
+
- **License(s):** bigcode-openrail-m
|
43 |
+
- **Model Developers:** Neural Magic
|
44 |
+
|
45 |
+
Quantized version of [starcoder2-7b](https://huggingface.co/bigcode/starcoder2-7b).
|
46 |
+
It achieves a HumanEval pass@1 of 34.6, whereas the unquantized model achieves 34.9 when evaluated under the same conditions.
|
47 |
+
|
48 |
+
### Model Optimizations
|
49 |
+
|
50 |
+
This model was obtained by quantizing the weights of [starcoder2-7b](https://huggingface.co/bigcode/starcoder2-7b) to INT8 data type.
|
51 |
+
This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%.
|
52 |
+
|
53 |
+
Only the weights of the linear operators within transformers blocks are quantized. Symmetric per-channel quantization is applied, in which a linear scaling per output dimension maps the INT8 and floating point representations of the quantized weights.
|
54 |
+
The [GPTQ](https://arxiv.org/abs/2210.17323) algorithm is applied for quantization, as implemented in the [llm-compressor](https://github.com/vllm-project/llm-compressor) library.
|
55 |
+
GPTQ used a 1% damping factor and 256 sequences of 8,192 random tokens.
|
56 |
+
|
57 |
+
|
58 |
+
## Deployment
|
59 |
+
|
60 |
+
### Use with vLLM
|
61 |
+
|
62 |
+
This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
|
63 |
+
|
64 |
+
```python
|
65 |
+
from vllm import LLM, SamplingParams
|
66 |
+
from transformers import AutoTokenizer
|
67 |
+
|
68 |
+
model_id = "neuralmagic/starcoder2-7b-quantized.w8a16"
|
69 |
+
number_gpus = 1
|
70 |
+
|
71 |
+
sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=256)
|
72 |
+
|
73 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
74 |
+
|
75 |
+
prompts = ["def print_hello_world():"]
|
76 |
+
|
77 |
+
llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
|
78 |
+
|
79 |
+
outputs = llm.generate(prompts, sampling_params)
|
80 |
+
|
81 |
+
generated_text = outputs[0].outputs[0].text
|
82 |
+
print(generated_text)
|
83 |
+
```
|
84 |
+
|
85 |
+
vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
|
86 |
+
|
87 |
+
|
88 |
+
## Creation
|
89 |
+
|
90 |
+
This model was created by using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as presented in the code snipet below.
|
91 |
+
|
92 |
+
```python
|
93 |
+
from transformers import AutoTokenizer
|
94 |
+
from datasets import Dataset
|
95 |
+
from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
|
96 |
+
from llmcompressor.modifiers.quantization import GPTQModifier
|
97 |
+
import random
|
98 |
+
|
99 |
+
model_id = "bigcode/starcoder2-7b"
|
100 |
+
|
101 |
+
num_samples = 256
|
102 |
+
max_seq_len = 8192
|
103 |
+
|
104 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
105 |
+
|
106 |
+
max_token_id = len(tokenizer.get_vocab()) - 1
|
107 |
+
input_ids = [[random.randint(0, max_token_id) for _ in range(max_seq_len)] for _ in range(num_samples)]
|
108 |
+
attention_mask = num_samples * [max_seq_len * [1]]
|
109 |
+
ds = Dataset.from_dict({"input_ids": input_ids, "attention_mask": attention_mask})
|
110 |
+
|
111 |
+
recipe = GPTQModifier(
|
112 |
+
targets="Linear",
|
113 |
+
scheme="W8A16",
|
114 |
+
ignore=["lm_head"],
|
115 |
+
dampening_frac=0.01,
|
116 |
+
)
|
117 |
+
|
118 |
+
model = SparseAutoModelForCausalLM.from_pretrained(
|
119 |
+
model_id,
|
120 |
+
device_map="auto",
|
121 |
+
trust_remote_code=True,
|
122 |
+
)
|
123 |
+
|
124 |
+
oneshot(
|
125 |
+
model=model,
|
126 |
+
dataset=ds,
|
127 |
+
recipe=recipe,
|
128 |
+
max_seq_length=max_seq_len,
|
129 |
+
num_calibration_samples=num_samples,
|
130 |
+
)
|
131 |
+
model.save_pretrained("starcoder2-7b-quantized.w8a16")
|
132 |
+
```
|
133 |
+
|
134 |
+
|
135 |
+
|
136 |
+
## Evaluation
|
137 |
+
|
138 |
+
The model was evaluated on the [HumanEval](https://arxiv.org/abs/2107.03374) and [HumanEval+](https://arxiv.org/abs/2305.01210) benchmarks, using the generation configuration from [Big Code Models Leaderboard](https://huggingface.co/spaces/bigcode/bigcode-models-leaderboard).
|
139 |
+
We used Neural Magic's fork of [evalplus](https://github.com/neuralmagic/evalplus) and the [vLLM](https://docs.vllm.ai/en/stable/) engine, using the following commands:
|
140 |
+
|
141 |
+
```
|
142 |
+
python codegen/generate.py \
|
143 |
+
--model neuralmagic/starcoder2-7b-quantized.w8a16 \
|
144 |
+
--bs 16 \
|
145 |
+
--temperature 0.2 \
|
146 |
+
--n_samples 50 \
|
147 |
+
--dataset humaneval \
|
148 |
+
-- root "."
|
149 |
+
|
150 |
+
python3 evalplus/sanitize.py humaneval/neuralmagic--starcoder2-7b-quantized.w8a16_vllm_temp_0.2
|
151 |
+
|
152 |
+
evalplus.evaluate --dataset humaneval --samples humaneval/neuralmagic--starcoder2-7b-quantized.w8a16_vllm_temp_0.2-sanitized
|
153 |
+
```
|
154 |
+
|
155 |
+
### Accuracy
|
156 |
+
|
157 |
+
<table>
|
158 |
+
<tr>
|
159 |
+
<td><strong>Benchmark</strong>
|
160 |
+
</td>
|
161 |
+
<td><strong>starcoder2-7b </strong>
|
162 |
+
</td>
|
163 |
+
<td><strong>starcoder2-7b-quantized.w8a16 (this model)</strong>
|
164 |
+
</td>
|
165 |
+
<td><strong>Recovery</strong>
|
166 |
+
</td>
|
167 |
+
</tr>
|
168 |
+
<tr>
|
169 |
+
<td>HumanEval pass@1
|
170 |
+
</td>
|
171 |
+
<td>34.9
|
172 |
+
</td>
|
173 |
+
<td>34.6
|
174 |
+
</td>
|
175 |
+
<td>99.1%
|
176 |
+
</td>
|
177 |
+
</tr>
|
178 |
+
<tr>
|
179 |
+
<td>HumanEval pass@10
|
180 |
+
</td>
|
181 |
+
<td>50.7
|
182 |
+
</td>
|
183 |
+
<td>50.4
|
184 |
+
</td>
|
185 |
+
<td>99.4%
|
186 |
+
</td>
|
187 |
+
</tr>
|
188 |
+
<tr>
|
189 |
+
<td>HumanEval+ pass@1
|
190 |
+
</td>
|
191 |
+
<td>30.0
|
192 |
+
</td>
|
193 |
+
<td>29.8
|
194 |
+
</td>
|
195 |
+
<td>99.3%
|
196 |
+
</td>
|
197 |
+
</tr>
|
198 |
+
<tr>
|
199 |
+
<td>HumanEval+ pass@10
|
200 |
+
</td>
|
201 |
+
<td>43.0
|
202 |
+
</td>
|
203 |
+
<td>43.6
|
204 |
+
</td>
|
205 |
+
<td>101.4%
|
206 |
+
</td>
|
207 |
+
</tr>
|
208 |
+
<tr>
|
209 |
+
</table>
|