File size: 6,101 Bytes
1919913
 
 
 
 
 
 
 
579c80b
1919913
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
579c80b
1919913
 
 
 
 
 
 
 
579c80b
1919913
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c06b7a2
1919913
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
148
149
150
151
152
153
154
155
156
157
---
license: apache-2.0
datasets:
- NeelNanda/pile-10k
---

## Model Details

This model is an int4 model with group_size 128 of [Qwen/Qwen2.5-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-3B-Instruct) 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 import AutoHfQuantizer ##must import
import torch
from transformers import AutoModelForCausalLM,AutoTokenizer
quantized_model_dir = "Intel/Qwen2.5-3B-Instruct-int4-inc"
tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)

model = AutoModelForCausalLM.from_pretrained(
    quantized_model_dir,
    torch_dtype='auto',
    device_map="auto",
)

##import habana_frameworks.torch.core as htcore ## uncommnet it for HPU
##import habana_frameworks.torch.hpu as hthpu ## uncommnet it for HPU
##model = model.to(torch.bfloat16).to("hpu") ## uncommnet it for HPU

prompt = "There is a girl who likes adventure,"
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": prompt}
]

text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

generated_ids = model.generate(
    model_inputs.input_ids,
    max_new_tokens=50,  ##change this to align with the official usage
    do_sample=False  ##change this to align with the official usage
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)

##prompt = "There is a girl who likes adventure,"
##That's great! Adventure can be a wonderful way to explore new experiences and push yourself out of your comfort zone. Here are some ideas for adventures that might appeal to someone who enjoys adventure:
##1. **Hiking**: Explore nature trails in parks or

##prompt = "Which one is bigger, 9.11 or 9.8"
##To determine which number is larger between 9.11 and 9.8, we can compare them digit by digit from left to right.
##1. Compare the whole number parts:
##   - Both numbers have the same whole number part:


##prompt = "Once upon a time,"
##Once upon a time, I imagine a story beginning. What kind of story do you want to tell? Do you have a specific plot in mind or a particular theme you'd like to explore? I'd be happy to help bring your story to life

##prompt = "请介绍一下阿里巴巴公司"
##阿里巴巴集团(Alibaba Group Holding Limited),简称“阿里”,创立于1999年,是一家总部位于中国杭州的全球性科技和电子商务公司。阿里巴巴旗下拥有多个知名业务,包括阿里巴巴集团、淘宝网、天猫、

```

### Evaluate the model 

pip3 install lm-eval==0.4.4

```bash
git clone https://github.com/intel/auto-round
cd auto-round
python -m auto_round --model "Intel/Qwen2.5-3B-Instruct-int4-inc" --eval --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(group_size 128)   | INT4(group_size 32)   |
|:-------------- | :----: | :----: |:------:|
| Avg            | 0.5902 | 0.5879 | 0.5837 |
| mmlu           | 0.6546 | 0.6425 | 0.6454 |
| cmmlu          | 0.7223 | 0.6998 | 0.7069 |
| ceval-valid    | 0.7221 | 0.7036 | 0.7140 |
| lambada_openai | 0.6612 | 0.6507 | 0.6542 |
| hellaswag      | 0.5636 | 0.5563 | 0.5578 |
| winogrande     | 0.6922 | 0.6898 | 0.6898 |
| piqa           | 0.7786 | 0.7731 | 0.7758 |
| truthfulqa_mc1 | 0.4186 | 0.4162 | 0.4247 |
| openbookqa     | 0.3280 | 0.3120 | 0.3040 |
| boolq          | 0.8018 | 0.8202 | 0.8183 |
| arc_easy       | 0.7698 | 0.7723 | 0.7807 |
| arc_challenge  | 0.4573 | 0.4787 | 0.4693 |
| gsm8k 5 shots  | 0.1031 | 0.1281 | 0.0470 |





### 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
python -m auto_round \
--model_name  Qwen/Qwen2.5-3B-Instruct \
--device 0 \
--group_size 128 \
--nsamples 512 \
--bits 4 \
--iter 1000 \
--disable_eval \
--model_dtype "float16" \
--format '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)