cicdatopea commited on
Commit
e431807
1 Parent(s): e1f1fbe

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +137 -0
README.md ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Model Details
2
+
3
+ This model is an int4 model with group_size 128 of [THUDM/glm-4-9b-chat](https://huggingface.co/THUDM/glm-4-9b-chat) generated by [intel/auto-round](https://github.com/intel/auto-round). For GPTQ format, please load the model with revision `d1bb095`
4
+
5
+ ## How To Use
6
+
7
+ ### INT4 Inference on CPU/CUDA/HPU
8
+
9
+ ```python
10
+ from auto_round import AutoRoundConfig ## must import for auto-round format
11
+ from transformers import AutoModelForCausalLM, AutoTokenizer
12
+ import torch
13
+
14
+ quantized_model_dir = "OPEA/glm-4-9b-chat-int4-inc"
15
+
16
+ model = AutoModelForCausalLM.from_pretrained(quantized_model_dir,
17
+ device_map=backend.split(':')[0], torch_dtype=torch.float16,
18
+ quantization_config=quantization_config,
19
+ trust_remote_code=True
20
+ #revision=d1bb095, ##auto-gptq format
21
+ ).eval()
22
+
23
+ tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir, trust_remote_code=True)
24
+ query = "请介绍一下智谱华章科技有限公司"
25
+ inputs = tokenizer.apply_chat_template([{"role": "user", "content": query}],
26
+ add_generation_prompt=True,
27
+ tokenize=True,
28
+ return_tensors="pt",
29
+ return_dict=True
30
+ )
31
+ inputs = inputs.to(model.device)
32
+
33
+ gen_kwargs = {"max_length": 50, "do_sample": False, "top_k": 1}##change this to follow official usage
34
+ with torch.no_grad():
35
+ outputs = model.generate(**inputs, **gen_kwargs)
36
+ outputs = outputs[:, inputs['input_ids'].shape[1]:]
37
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
38
+
39
+ ##请介绍一下智谱华章科技有限公司
40
+ #智谱华章科技有限公司是一家专注于人工智能、大数据、云计算等前沿技术领域的创新型企业。公司成立于2016年,总部位于中国北京,是一家集技术研发、产品开发、
41
+
42
+
43
+ ##9.8大还是9.11大
44
+ ##9.8比9.11小。在数值上,9.8小于9.11。
45
+
46
+
47
+ ##Once upon a time,
48
+
49
+ #In a land where the sun kissed the horizon with a golden glow and the stars whispered secrets to the night, there was a village nestled among rolling hills and whispering forests. This was a place
50
+
51
+
52
+ ##There is a girl who likes adventure,
53
+ ##That's quite the intriguing starting point! If you're looking to create a story or a character, here's a brief introduction to a girl who likes adventure:
54
+
55
+ ##---
56
+
57
+ ##**Name:**
58
+ ```
59
+
60
+
61
+
62
+ ### Evaluate the model
63
+
64
+ pip3 install lm-eval==0.4.5
65
+
66
+ pip3 install langdetect,immutabledict,antlr4-python3-runtime==4.11
67
+
68
+ ```bash
69
+ auto-round --eval --eval_bs 16 --tasks leaderboard_ifeval,leaderboard_mmlu_pro,gsm8k,lambada_openai,hellaswag,piqa,winogrande,truthfulqa_mc1,openbookqa,boolq,arc_easy,arc_challenge,cmmlu,ceval-valid
70
+
71
+ ```
72
+
73
+ | Metric | BF16 | INT4(6.4G) | INT4-quanted-lm-head(5.5G) |
74
+ | ------------------------------------------ | ------ | ---------- | -------------------------- |
75
+ | Avg | 0.6260 | 0.6230 | 0.6204 |
76
+ | leaderboard_mmlu_pro 5shot | 0.3678 | 0.3616 | 0.3610 |
77
+ | leaderboard_ifeval inst_level_strict_acc | 0.5504 | 0.5600 | 0.5588 |
78
+ | leaderboard_ifeval prompt_level_strict_acc | 0.4067 | 0.4233 | 0.4067 |
79
+ | cmmlu | 0.7213 | 0.7137 | 0.7086 |
80
+ | ceval-valid | 0.7065 | 0.7058 | 0.6909 |
81
+ | gsm8k 5shot strict match | 0.7794 | 0.7597 | 0.7589 |
82
+ | lambada_openai | 0.6608 | 0.6493 | 0.6470 |
83
+ | hellaswag | 0.6195 | 0.6137 | 0.6134 |
84
+ | winogrande | 0.7561 | 0.7545 | 0.7522 |
85
+ | piqa | 0.8030 | 0.7976 | 0.8003 |
86
+ | truthfulqa_mc1 | 0.4223 | 0.4223 | 0.4284 |
87
+ | openbookqa | 0.3560 | 0.3640 | 0.3580 |
88
+ | boolq | 0.8691 | 0.8606 | 0.8578 |
89
+ | arc_easy | 0.8241 | 0.8249 | 0.8203 |
90
+ | arc_challenge | 0.5469 | 0.5341 | 0.5444 |
91
+
92
+
93
+
94
+ ### Generate the model
95
+
96
+ Here is the sample command to generate the model.
97
+
98
+ ```bash
99
+ auto-round \
100
+ --model THUDM/glm-4-9b-chat \
101
+ --iter 1000 \
102
+ --nsamples 512 \
103
+ --disable_eval \
104
+ --format "auto_round,auto_gptq"
105
+ --output_dir "./tmp_autoround"
106
+ ```
107
+
108
+ copy all the *.py file to the quantized_model folder
109
+
110
+ For gptq format, need to add "block_name_to_quantize":"transformer.encoder.layers" to config.json, we only tested it on transformers==4.46.1
111
+
112
+ ## Ethical Considerations and Limitations
113
+
114
+ 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.
115
+
116
+ Therefore, before deploying any applications of the model, developers should perform safety testing.
117
+
118
+ ## Caveats and Recommendations
119
+
120
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
121
+
122
+ Here are a couple of useful links to learn more about Intel's AI software:
123
+
124
+ * Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
125
+ * Intel Extension for Transformers [link](https://github.com/intel/intel-extension-for-transformers)
126
+
127
+ ## Disclaimer
128
+
129
+ 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.
130
+
131
+
132
+
133
+ ## Cite
134
+
135
+ @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} }
136
+
137
+ [arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)