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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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-3b-quantized.w8a8
|
| 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.8
|
| 20 |
+
- task:
|
| 21 |
+
type: text-generation
|
| 22 |
+
dataset:
|
| 23 |
+
name: HumanEval
|
| 24 |
+
type: humaneval
|
| 25 |
+
metrics:
|
| 26 |
+
- type: pass@1
|
| 27 |
+
value: 31.4
|
| 28 |
+
---
|
| 29 |
+
|
| 30 |
+
# starcoder2-3b-quantized.w8a8
|
| 31 |
+
|
| 32 |
+
## Model Overview
|
| 33 |
+
- **Model Architecture:** StarCoder2
|
| 34 |
+
- **Input:** Text
|
| 35 |
+
- **Output:** Text
|
| 36 |
+
- **Model Optimizations:**
|
| 37 |
+
- **Activation quantization:** INT8
|
| 38 |
+
- **Weight quantization:** INT8
|
| 39 |
+
- **Intended Use Cases:** Intended for commercial and research use. Similarly to [starcoder2-3b](https://huggingface.co/bigcode/starcoder2-3b), 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.
|
| 40 |
+
- **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws).
|
| 41 |
+
- **Release Date:** 8/1/2024
|
| 42 |
+
- **Version:** 1.0
|
| 43 |
+
- **License(s):** bigcode-openrail-m
|
| 44 |
+
- **Model Developers:** Neural Magic
|
| 45 |
+
|
| 46 |
+
Quantized version of [starcoder2-3b](https://huggingface.co/bigcode/starcoder2-3b).
|
| 47 |
+
It achieves a HumanEval pass@1 of 31.4, whereas the unquantized model achieves 30.7 when evaluated under the same conditions.
|
| 48 |
+
|
| 49 |
+
### Model Optimizations
|
| 50 |
+
|
| 51 |
+
This model was obtained by quantizing the weights of [starcoder2-3b](https://huggingface.co/bigcode/starcoder2-3b) to INT8 data type.
|
| 52 |
+
This optimization reduces the number of bits used to represent weights and activations from 16 to 8, reducing GPU memory requirements (by approximately 50%) and increasing matrix-multiply compute throughput (by approximately 2x).
|
| 53 |
+
Weight quantization also reduces disk size requirements by approximately 50%.
|
| 54 |
+
|
| 55 |
+
Only weights and activations of the linear operators within transformers blocks are quantized.
|
| 56 |
+
Weights are quantized with a symmetric static per-channel scheme, where a fixed linear scaling factor is applied between INT8 and floating point representations for each output channel dimension.
|
| 57 |
+
Activations are quantized with a symmetric dynamic per-token scheme, computing a linear scaling factor at runtime for each token between INT8 and floating point representations.
|
| 58 |
+
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.
|
| 59 |
+
GPTQ used a 1% damping factor and 256 sequences of 8,192 random tokens.
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
## Deployment
|
| 63 |
+
|
| 64 |
+
### Use with vLLM
|
| 65 |
+
|
| 66 |
+
This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
|
| 67 |
+
|
| 68 |
+
```python
|
| 69 |
+
from vllm import LLM, SamplingParams
|
| 70 |
+
from transformers import AutoTokenizer
|
| 71 |
+
|
| 72 |
+
model_id = "neuralmagic/starcoder2-3b-quantized.w8a8"
|
| 73 |
+
number_gpus = 1
|
| 74 |
+
|
| 75 |
+
sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=256)
|
| 76 |
+
|
| 77 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 78 |
+
|
| 79 |
+
prompts = ["def print_hello_world():"]
|
| 80 |
+
|
| 81 |
+
llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
|
| 82 |
+
|
| 83 |
+
outputs = llm.generate(prompts, sampling_params)
|
| 84 |
+
|
| 85 |
+
generated_text = outputs[0].outputs[0].text
|
| 86 |
+
print(generated_text)
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
## Creation
|
| 93 |
+
|
| 94 |
+
This model was created by using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as presented in the code snipet below.
|
| 95 |
+
|
| 96 |
+
```python
|
| 97 |
+
from transformers import AutoTokenizer
|
| 98 |
+
from datasets import Dataset
|
| 99 |
+
from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
|
| 100 |
+
from llmcompressor.modifiers.quantization import GPTQModifier
|
| 101 |
+
import random
|
| 102 |
+
|
| 103 |
+
model_id = "bigcode/starcoder2-3b"
|
| 104 |
+
|
| 105 |
+
num_samples = 256
|
| 106 |
+
max_seq_len = 8192
|
| 107 |
+
|
| 108 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 109 |
+
|
| 110 |
+
max_token_id = len(tokenizer.get_vocab()) - 1
|
| 111 |
+
input_ids = [[random.randint(0, max_token_id) for _ in range(max_seq_len)] for _ in range(num_samples)]
|
| 112 |
+
attention_mask = num_samples * [max_seq_len * [1]]
|
| 113 |
+
ds = Dataset.from_dict({"input_ids": input_ids, "attention_mask": attention_mask})
|
| 114 |
+
|
| 115 |
+
recipe = GPTQModifier(
|
| 116 |
+
targets="Linear",
|
| 117 |
+
scheme="W8A8",
|
| 118 |
+
ignore=["lm_head"],
|
| 119 |
+
dampening_frac=0.01,
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
model = SparseAutoModelForCausalLM.from_pretrained(
|
| 123 |
+
model_id,
|
| 124 |
+
device_map="auto",
|
| 125 |
+
trust_remote_code=True,
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
oneshot(
|
| 129 |
+
model=model,
|
| 130 |
+
dataset=ds,
|
| 131 |
+
recipe=recipe,
|
| 132 |
+
max_seq_length=max_seq_len,
|
| 133 |
+
num_calibration_samples=num_samples,
|
| 134 |
+
)
|
| 135 |
+
model.save_pretrained("starcoder2-3b-quantized.w8a8")
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
## Evaluation
|
| 140 |
+
|
| 141 |
+
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).
|
| 142 |
+
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:
|
| 143 |
+
|
| 144 |
+
```
|
| 145 |
+
python codegen/generate.py \
|
| 146 |
+
--model neuralmagic/starcoder2-3b-quantized.w8a8 \
|
| 147 |
+
--bs 16 \
|
| 148 |
+
--temperature 0.2 \
|
| 149 |
+
--n_samples 50 \
|
| 150 |
+
--dataset humaneval \
|
| 151 |
+
-- root "."
|
| 152 |
+
|
| 153 |
+
python3 evalplus/sanitize.py humaneval/neuralmagic--starcoder2-3b-quantized.w8a8_vllm_temp_0.2
|
| 154 |
+
|
| 155 |
+
evalplus.evaluate --dataset humaneval --samples humaneval/neuralmagic--starcoder2-3b-quantized.w8a8_vllm_temp_0.2-sanitized
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+
### Accuracy
|
| 159 |
+
|
| 160 |
+
<table>
|
| 161 |
+
<tr>
|
| 162 |
+
<td><strong>Benchmark</strong>
|
| 163 |
+
</td>
|
| 164 |
+
<td><strong>starcoder2-3b</strong>
|
| 165 |
+
</td>
|
| 166 |
+
<td><strong>starcoder2-3b-quantized.w8a8 (this model)</strong>
|
| 167 |
+
</td>
|
| 168 |
+
<td><strong>Recovery</strong>
|
| 169 |
+
</td>
|
| 170 |
+
</tr>
|
| 171 |
+
<tr>
|
| 172 |
+
<td>HumanEval pass@1
|
| 173 |
+
</td>
|
| 174 |
+
<td>30.7
|
| 175 |
+
</td>
|
| 176 |
+
<td>31.4
|
| 177 |
+
</td>
|
| 178 |
+
<td>102.3%
|
| 179 |
+
</td>
|
| 180 |
+
</tr>
|
| 181 |
+
<tr>
|
| 182 |
+
<td>HumanEval pass@10
|
| 183 |
+
</td>
|
| 184 |
+
<td>44.9
|
| 185 |
+
</td>
|
| 186 |
+
<td>44.7
|
| 187 |
+
</td>
|
| 188 |
+
<td>99.6%
|
| 189 |
+
</td>
|
| 190 |
+
</tr>
|
| 191 |
+
<tr>
|
| 192 |
+
<td>HumanEval+ pass@1
|
| 193 |
+
</td>
|
| 194 |
+
<td>26.6
|
| 195 |
+
</td>
|
| 196 |
+
<td>26.8
|
| 197 |
+
</td>
|
| 198 |
+
<td>100.8%
|
| 199 |
+
</td>
|
| 200 |
+
</tr>
|
| 201 |
+
<tr>
|
| 202 |
+
<td>HumanEval+ pass@10
|
| 203 |
+
</td>
|
| 204 |
+
<td>39.2
|
| 205 |
+
</td>
|
| 206 |
+
<td>38.7
|
| 207 |
+
</td>
|
| 208 |
+
<td>98.7%
|
| 209 |
+
</td>
|
| 210 |
+
</tr>
|
| 211 |
+
<tr>
|
| 212 |
+
</table>
|