wenhuach commited on
Commit
0a2be57
·
verified ·
1 Parent(s): 57366c0

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +134 -0
README.md ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - NeelNanda/pile-10k
5
+
6
+ ---
7
+
8
+ ---
9
+
10
+ license: apache-2.0
11
+ datasets:
12
+
13
+ - NeelNanda/pile-10k
14
+
15
+ ## Model Details
16
+
17
+ This model is an int4 auto-round model with group_size 128 of [Qwen/Qwen2-7B](https://huggingface.co/Qwen/Qwen2-7B) generated by [intel/auto-round](https://github.com/intel/auto-round)
18
+
19
+ ## How To Use
20
+
21
+ ### INT4 Inference
22
+
23
+ ```python
24
+ ##pip install auto-round
25
+ from auto_round import AutoRoundConfig ##must import for auto_round format
26
+ from transformers import AutoModelForCausalLM,AutoTokenizer
27
+ quantized_model_dir = "Intel/Qwen2-7B-int4-inc"
28
+ tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
29
+ model = AutoModelForCausalLM.from_pretrained(quantized_model_dir, device_map="auto")
30
+ ##model = AutoModelForCausalLM.from_pretrained(quantized_model_dir, device_map="auto",revision="07a117c")##AutoGPTQ format
31
+ text = "下面我来介绍一下阿里巴巴公司,"
32
+ text = "9.8和9.11哪个数字大?答案是"
33
+ text = "Once upon a time,"
34
+ text = "There is a girl who likes adventure,"
35
+ inputs = tokenizer(text, return_tensors="pt").to(model.device)
36
+ print(tokenizer.decode(model.generate(**inputs, max_new_tokens=50, do_sample=False)[0]))
37
+ ##下面我来介绍一下阿里巴巴公司,阿里巴巴公司是全球领先的电子商务公司,成立于1999年,总部位于中国杭州。阿里巴巴公司致力于为全球中小企业提供一个在线交易平台,帮助他们拓展业务,提高销售额。阿里巴巴公司拥有多个业务板块,包括淘宝、天猫
38
+ ##
39
+ ##9.8和9.11哪个数字大?答案是9.8,因为9.8比9.11大0.7。
40
+ ##Once upon a time, there was a little girl named Alice who loved to read. She had a special book that she had inherited from her grandmother, and it was filled with stories of magical creatures and far-off lands. One day, Alice decided to read the book in a
41
+ ##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 always up for a challenge, and she is not afraid to take risks. She is a bit
42
+ ```
43
+
44
+ ### Intel Gaudi-2 INT4 Inference
45
+
46
+ docker image with Gaudi Software Stack is recommended. More details can be found in [Gaudi Guide](https://docs.habana.ai/en/latest/).
47
+
48
+ ```python
49
+ import habana_frameworks.torch.core as htcore
50
+ import habana_frameworks.torch.hpu as hthpu
51
+
52
+ from auto_round import AutoRoundConfig
53
+ from transformers import AutoModelForCausalLM,AutoTokenizer
54
+
55
+ quantized_model_dir = "Intel/Qwen2-7B-int4-inc"
56
+ tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
57
+ model = AutoModelForCausalLM.from_pretrained(quantized_model_dir).to('hpu').to(bfloat16)
58
+ text = "下面我来介绍一下阿里巴巴公司,"
59
+ inputs = tokenizer(text, return_tensors="pt").to(model.device)
60
+ print(tokenizer.decode(model.generate(**inputs, max_new_tokens=50, do_sample=False)[0]))
61
+
62
+ ```
63
+
64
+ ### Evaluate the model
65
+
66
+ pip3 install lm-eval==0.4.4,auto-round
67
+
68
+ ```bash
69
+ auto-round --model "Intel/Qwen2-7B-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
70
+ ```
71
+
72
+ | Metric | BF16 | INT4 |
73
+ | :-------------------------- | :----: | :----: |
74
+ | Avg | 0.6659 | 0.6604 |
75
+ | mmlu | 0.6697 | 0.6646 |
76
+ | cmmlu | 0.8254 | 0.8118 |
77
+ | ceval-valid | 0.8339 | 0.8053 |
78
+ | lambada_openai | 0.7182 | 0.7136 |
79
+ | hellaswag | 0.5823 | 0.5752 |
80
+ | winogrande | 0.7222 | 0.7277 |
81
+ | piqa | 0.7911 | 0.7933 |
82
+ | truthfulqa_mc1 | 0.3647 | 0.3476 |
83
+ | openbookqa | 0.3520 | 0.3440 |
84
+ | boolq | 0.8183 | 0.8223 |
85
+ | arc_easy | 0.7660 | 0.7635 |
86
+ | arc_challenge | 0.4505 | 0.4633 |
87
+ | gsm8k 5 shots(strict match) | 0.7619 | 0.7528 |
88
+
89
+ ### Generate the model
90
+
91
+ 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.
92
+
93
+ ```bash
94
+ auto-round
95
+ --model_name Qwen/Qwen2-7B \
96
+ --device 0 \
97
+ --group_size 128 \
98
+ --nsamples 512 \
99
+ --bits 4 \
100
+ --iter 1000 \
101
+ --disable_eval \
102
+ --model_dtype "float16" \
103
+ --format 'auto_round' \
104
+ --output_dir "./tmp_autoround"
105
+ ```
106
+
107
+
108
+
109
+ ## Ethical Considerations and Limitations
110
+
111
+ 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.
112
+
113
+ Therefore, before deploying any applications of the model, developers should perform safety testing.
114
+
115
+ ## Caveats and Recommendations
116
+
117
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
118
+
119
+ Here are a couple of useful links to learn more about Intel's AI software:
120
+
121
+ * Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
122
+ * Intel Extension for Transformers [link](https://github.com/intel/intel-extension-for-transformers)
123
+
124
+ ## Disclaimer
125
+
126
+ 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.
127
+
128
+
129
+
130
+ ## Cite
131
+
132
+ @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} }
133
+
134
+ [arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)