File size: 4,188 Bytes
415e21a 00f1d7c 415e21a 00f1d7c 133f9a2 415e21a 00f1d7c f343c2b 00f1d7c f343c2b 1efa8e7 00f1d7c f343c2b 00f1d7c f343c2b 00f1d7c 415e21a 00f1d7c 415e21a 00f1d7c 14a5007 52e055e 415e21a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
---
datasets:
- NeelNanda/pile-10k
language:
- en
---
## Model Recipe Details
This is an int4 model recipe with group_size 128 of [facebook/opt-1.3b](https://huggingface.co/facebook/opt-1.3b) generated by [intel/auto-round](https://github.com/intel/auto-round).
Inference of this model is compatible with AutoGPTQ's Kernel.
### Quantize the model
Here is the sample command to reproduce the model
```bash
pip install auto-round
auto-round
--model facebook/opt-1.3b \
--device 0 \
--group_size 128 \
--bits 4 \
--iters 1000 \
--nsamples 512 \
--format 'auto_gptq' \
--minmax_lr 2e-3 \
--disable_quanted_input \
--output_dir "./tmp_autoround" \
```
## How to use
### INT4 Inference with IPEX on Intel CPU
Install the latest [Intel Extension for Pytorch](https://github.com/intel/intel-extension-for-pytorch) and [Intel Neural Compressor](https://github.com/intel/neural-compressor)
```bash
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install intel_extension_for_pytorch
pip install neural_compressor_pt
```
```python
from transformers import AutoTokenizer
from neural_compressor.transformers import AutoModelForCausalLM
## note: use quantized model directory name below
model_name_or_path="./tmp_autoround/<model directory name>"
q_model = AutoModelForCausalLM.from_pretrained(model_name_or_path)
prompt = "Once upon a time, a little girl"
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
print(tokenizer.decode(q_model.generate(**tokenizer(prompt, return_tensors="pt").to(q_model.device),max_new_tokens=50)[0]))
## Once upon a time, a little girl was born. She was a beautiful little girl, with a beautiful smile. She was a little girl who loved to play. She was a little girl who loved to sing.She was a little girl who loved to dance.
```
### INT4 Inference on Intel Gaudi Accelerator
docker image with Gaudi Software Stack is recommended. More details can be found in [Gaudi Guide](https://docs.habana.ai/en/latest/).
```python
import habana_frameworks.torch.core as htcore
from neural_compressor.torch.quantization import load
from transformers import AutoTokenizer, AutoModelForCausalLM
## note: use quantized model directory name below
model_name_or_path="./tmp_autoround/<model directory name>"
model = load(
model_name_or_path=model_name_or_path,
format="huggingface",
device="hpu"
)
prompt = "Once upon a time, a little girl"
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
print(tokenizer.decode(model.generate(**tokenizer(prompt, return_tensors="pt").to("hpu"),max_new_tokens=50)[0]))
```
## Accuracy Result
| Metric <img width=200> | FP16 <img width=200> | INT4 <img width=200> |
| :------------------ | :---------- | :---------- |
| Avg. | 0.4405 | 0.4315 |
| mmlu | 0.2502 | 0.2510 |
| lambada_openai | 0.5789 | 0.5389 |
| hellaswag | 0.4153 | 0.4076 |
| winogrande | 0.5927 | 0.5848 |
| piqa | 0.7165 | 0.7067 |
| truthfulqa_mc1 | 0.2362 | 0.2338 |
| openbookqa | 0.2320 | 0.2140 |
| boolq | 0.5765 | 0.5786 |
| arc_easy | 0.5724 | 0.5673 |
| arc_challenge | 0.2346 | 0.2321 |
## Caveats and Recommendations
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
Here are a couple of useful links to learn more about Intel's AI software:
* Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
* Intel Extension for Transformers [link](https://github.com/intel/intel-extension-for-transformers)
## Disclaimer
The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please consult an attorney before using this model for commercial purposes.
## Cite
@article{cheng2023optimize, title={Optimize weight rounding via signed gradient descent for the quantization of llms}, author={Cheng, Wenhua and Zhang, Weiwei and Shen, Haihao and Cai, Yiyang and He, Xin and Lv, Kaokao}, journal={arXiv preprint arXiv:2309.05516}, year={2023} }
[arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round) |