OPEA
/

Safetensors
File size: 6,937 Bytes
ee9e320
 
 
 
7c97270
 
ee9e320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c97270
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
---
license: apache-2.0
datasets:
- NeelNanda/pile-10k
base_model:
- Qwen/Qwen2-7B
---

---
license: apache-2.0
datasets:
- NeelNanda/pile-10k

## Model Details

This model is an int4 model with group_size 128 with quantized lm-head of [Qwen/Qwen2-7B](https://huggingface.co/Qwen/Qwen2-7B) generated by [intel/auto-round](https://github.com/intel/auto-round), auto-round is needed to run this model

## How To Use

### INT4 Inference



```python
##git clone https://github.com/intel/auto-round.git
##cd auto-round && pip install -vvv --no-build-isolation -e .
from auto_round.auto_quantizer import AutoHfQuantizer
from transformers import AutoModelForCausalLM,AutoTokenizer
quantized_model_dir = "OPEA/Qwen2-7B-int4-inc"
tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
model = AutoModelForCausalLM.from_pretrained(quantized_model_dir, device_map="auto")
text = "下面我来介绍一下阿里巴巴公司,"
text = "88+99等于多少?"
text = "Once upon a time,"
text = "There is a girl who likes adventure,"
inputs = tokenizer(text, return_tensors="pt").to(model.device)
print(tokenizer.decode(model.generate(**inputs, max_new_tokens=50, do_sample=False)[0]))
##下面我来介绍一下阿里巴巴公司,阿里巴巴公司是1999年9月8日由马云在杭州创立的,阿里巴巴集团主要经营业务包括:淘宝网、天猫、聚划算、全球速卖通、阿里巴巴国际交易市场、1688、阿里
##"88+99等于多少? 88+99=187 \n 计算: (1) 1 2 + 1 3 + 1 4 + 1 5 + 1 6 + 1 7 + 1 8"
##Once upon a time, there was a little girl named Emily who loved to read books. She would spend hours lost in the pages of her favorite stories, imagining herself in the worlds she read about. One day, Emily stumbled upon a book called "The Enchanted Forest
##There is a girl who likes adventure, and she is always looking for new experiences. She is a bit of a thrill-seeker, and she loves to push herself to the limit. She is also a bit of a free spirit, and she loves to explore new places and try new things
```

### Intel Gaudi-2 INT4 Inference
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
import habana_frameworks.torch.hpu as hthpu

from auto_round.auto_quantizer import AutoHfQuantizer

from transformers import AutoModelForCausalLM,AutoTokenizer
quantized_model_dir = "Intel/Qwen2-7B-int4-inc"
tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
model = AutoModelForCausalLM.from_pretrained(quantized_model_dir).to('hpu').to(bfloat16)
text = "下面我来介绍一下阿里巴巴公司,"
text = "9.8和9.11哪个大?"
text = "Once upon a time,"
text = "There is a girl who likes adventure,"
inputs = tokenizer(text, return_tensors="pt").to(model.device)
print(tokenizer.decode(model.generate(**inputs, max_new_tokens=50, do_sample=False)[0]))
##下面我来介绍一下阿里巴巴公司,阿里巴巴公司是1999年9月8日由马云在杭州创立的,阿里巴巴集团主要经营业务包括:淘宝网、天猫、聚划算、全球速卖通、阿里巴巴国际交易市场、1688、阿里
##9.8和9.11哪个大? 9.8和9.11哪个大? 解:9.8>9.11; 答:9.8大. 阅读下面的文字,完成下列各题。 ①“中国式现代化”是习近平
##Once upon a time, there was a little girl named Emily who loved to read books. She would spend hours lost in the pages of her favorite stories, imagining herself in the worlds she read about. One day, Emily stumbled upon a book called "The Enchanted Forest
##There is a girl who likes adventure, and she is always looking for new experiences. She is a bit of a thrill-seeker, and she loves to push herself to the limit. She is also a bit of a free spirit, and she loves to explore new places and try new things
```

### Evaluate the model 

pip3 install lm-eval==0.4.2

```bash
git clone https://github.com/intel/auto-round
cd auto-round/examples/language-modeling
python3 eval_042/evluation.py --model_name "OPEA/Qwen2-7B-int4-inc" --eval_bs 16  --tasks lambada_openai,hellaswag,piqa,winogrande,truthfulqa_mc1,openbookqa,boolq,arc_easy,arc_challenge,mmlu,gsm8k,cmmlu,ceval-valid
```

| Metric         | BF16   | INT4   | 
| -------------- | ------ | ------ |
| Avg            | 0.6655 | 0.6624 |
| mmlu           | 0.6706 | 0.6650 |
| cmmlu          | 0.8310 | 0.8151 |
| ceval-valid    | 0.8232 | 0.8053 |
| lambada_openai | 0.7182 | 0.7254 |
| hellaswag      | 0.5823 | 0.5758 |
| winogrande     | 0.7222 | 0.7174 | 
| piqa           | 0.7911 | 0.7905 |
| truthfulqa_mc1 | 0.3647 | 0.3599 |
| openbookqa     | 0.3520 | 0.3420 |
| boolq          | 0.8183 | 0.8168 |
| arc_easy       | 0.7660 | 0.7643 |
| arc_challenge  | 0.4505 | 0.4625 |
| gsm8k 5 shots  | 0.7619 | 0.7710 |





### Reproduce the model

Here is the sample command to reproduce the model. We observed a larger accuracy drop in Chinese tasks and recommend using a high-quality Chinese dataset for calibration. However, we did not achieve better accuracy with some public datasets.

```bash
git clone https://github.com/intel/auto-round
cd auto-round/examples/language-modeling
pip install -r requirements.txt
python3 main.py \
--model_name  Qwen/Qwen2-7B \
--device 0 \
--group_size 128 \
--nsamples 512 \
--bits 4 \
--iter 1000 \
--disable_eval \
--model_dtype "float16" \
--deployment_device 'auto_round' \
--output_dir "./tmp_autoround" 
```



## Ethical Considerations and Limitations

The model can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs.

Therefore, before deploying any applications of the model, developers should perform safety testing.

## 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 and Liu, Yi}, journal={arXiv preprint arXiv:2309.05516}, year={2023} }

[arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)