cicdatopea commited on
Commit
f2de9e6
·
verified ·
1 Parent(s): 037552f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +121 -3
README.md CHANGED
@@ -1,3 +1,121 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ datasets:
3
+ - NeelNanda/pile-10k
4
+ ---
5
+ ## Model Details
6
+
7
+ This model is an int4 model with group_size 128 and quantized lm-head 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`
8
+
9
+ ## How To Use
10
+
11
+ ### INT4 Inference on CPU/CUDA/HPU
12
+
13
+ ```python
14
+ from auto_round import AutoRoundConfig ## must import for auto-round format
15
+ from transformers import AutoModelForCausalLM, AutoTokenizer
16
+ import torch
17
+
18
+ quantized_model_dir = "OPEA/glm-4-9b-chat-int4-inc"
19
+
20
+ model = AutoModelForCausalLM.from_pretrained(quantized_model_dir,
21
+ device_map=backend.split(':')[0], torch_dtype=torch.float16,
22
+ quantization_config=quantization_config,
23
+ trust_remote_code=True
24
+ ).eval()
25
+
26
+ tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir, trust_remote_code=True)
27
+ query = "请介绍一下智谱华章科技有限公司"
28
+ inputs = tokenizer.apply_chat_template([{"role": "user", "content": query}],
29
+ add_generation_prompt=True,
30
+ tokenize=True,
31
+ return_tensors="pt",
32
+ return_dict=True
33
+ )
34
+ inputs = inputs.to(model.device)
35
+
36
+ gen_kwargs = {"max_length": 50, "do_sample": False, "top_k": 1}##change this to follow official usage
37
+ with torch.no_grad():
38
+ outputs = model.generate(**inputs, **gen_kwargs)
39
+ outputs = outputs[:, inputs['input_ids'].shape[1]:]
40
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
41
+
42
+
43
+
44
+
45
+
46
+ ### Evaluate the model
47
+
48
+ pip3 install lm-eval==0.4.5
49
+
50
+ pip3 install langdetect,immutabledict,antlr4-python3-runtime==4.11
51
+
52
+ ```bash
53
+ 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
54
+
55
+ ```
56
+
57
+ | Metric | BF16 | INT4(6.4G) | INT4-quanted-lm-head(5.5G) |
58
+ | ------------------------------------------ | ------ | ---------- | -------------------------- |
59
+ | Avg | 0.6260 | 0.6230 | 0.6204 |
60
+ | leaderboard_mmlu_pro 5shot | 0.3678 | 0.3616 | 0.3610 |
61
+ | leaderboard_ifeval inst_level_strict_acc | 0.5504 | 0.5600 | 0.5588 |
62
+ | leaderboard_ifeval prompt_level_strict_acc | 0.4067 | 0.4233 | 0.4067 |
63
+ | cmmlu | 0.7213 | 0.7137 | 0.7086 |
64
+ | ceval-valid | 0.7065 | 0.7058 | 0.6909 |
65
+ | gsm8k 5shot strict match | 0.7794 | 0.7597 | 0.7589 |
66
+ | lambada_openai | 0.6608 | 0.6493 | 0.6470 |
67
+ | hellaswag | 0.6195 | 0.6137 | 0.6134 |
68
+ | winogrande | 0.7561 | 0.7545 | 0.7522 |
69
+ | piqa | 0.8030 | 0.7976 | 0.8003 |
70
+ | truthfulqa_mc1 | 0.4223 | 0.4223 | 0.4284 |
71
+ | openbookqa | 0.3560 | 0.3640 | 0.3580 |
72
+ | boolq | 0.8691 | 0.8606 | 0.8578 |
73
+ | arc_easy | 0.8241 | 0.8249 | 0.8203 |
74
+ | arc_challenge | 0.5469 | 0.5341 | 0.5444 |
75
+
76
+
77
+
78
+ ### Generate the model
79
+
80
+ Here is the sample command to generate the model.
81
+
82
+ ```bash
83
+ auto-round \
84
+ --model THUDM/glm-4-9b-chat \
85
+ --iter 1000 \
86
+ --nsamples 512 \
87
+ --disable_eval \
88
+ --quant_lm_head \
89
+ --format "auto_round"
90
+ --output_dir "./tmp_autoround"
91
+ ```
92
+
93
+ copy all the *.py file to the quantized_model folder
94
+
95
+ 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
96
+
97
+ ## Ethical Considerations and Limitations
98
+
99
+ 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.
100
+
101
+ Therefore, before deploying any applications of the model, developers should perform safety testing.
102
+
103
+ ## Caveats and Recommendations
104
+
105
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
106
+
107
+ Here are a couple of useful links to learn more about Intel's AI software:
108
+
109
+ * Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
110
+
111
+ ## Disclaimer
112
+
113
+ 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.
114
+
115
+
116
+
117
+ ## Cite
118
+
119
+ @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} }
120
+
121
+ [arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)