OPEA
/

Safetensors
llama
4-bit precision
intel/auto-round
cicdatopea commited on
Commit
1132e8c
1 Parent(s): 6e3ebe0

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +153 -0
README.md ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ datasets:
2
+ - NeelNanda/pile-10k
3
+ ---
4
+
5
+ ## Model Details
6
+
7
+ This model is an int4 model with group_size 128 and symmetric quantization of [meta-llama/Llama-3.3-70B-Instruct](https://huggingface.co/meta-llama/Llama-3.3-70B-Instruct) generated by [intel/auto-round](https://github.com/intel/auto-round). Load the model with revision `12cbcc0` to use AutoGPTQ format
8
+
9
+ ## How To Use
10
+ ### Inference on CPU/HPU/CUDA
11
+
12
+ HPU: docker image with Gaudi Software Stack is recommended, please refer to following script for environment setup. More details can be found in [Gaudi Guide](https://docs.habana.ai/en/latest/Installation_Guide/Bare_Metal_Fresh_OS.html#launch-docker-image-that-was-built).
13
+
14
+ ```python
15
+ from auto_round import AutoHfQuantizer ##must import for auto-round format
16
+ import torch
17
+ from transformers import AutoModelForCausalLM,AutoTokenizer
18
+ quantized_model_dir = "OPEA/Llama-3.3-70B-Instruct-int4-sym-inc"
19
+ tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
20
+
21
+ model = AutoModelForCausalLM.from_pretrained(
22
+ quantized_model_dir,
23
+ torch_dtype='auto',
24
+ device_map="auto",
25
+ ##revision="12cbcc0", ##AutoGPTQ format
26
+ )
27
+
28
+ ##import habana_frameworks.torch.core as htcore ## uncommnet it for HPU
29
+ ##import habana_frameworks.torch.hpu as hthpu ## uncommnet it for HPU
30
+ ##model = model.to(torch.bfloat16).to("hpu") ## uncommnet it for HPU
31
+
32
+ prompt = "There is a girl who likes adventure,"
33
+ messages = [
34
+ {"role": "system", "content": "You are a helpful assistant."},
35
+ {"role": "user", "content": prompt}
36
+ ]
37
+
38
+ tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
39
+ text = tokenizer.apply_chat_template(
40
+ messages,
41
+ tokenize=False,
42
+ add_generation_prompt=True
43
+ )
44
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
45
+
46
+ generated_ids = model.generate(
47
+ model_inputs.input_ids,
48
+ max_new_tokens=200, ##change this to align with the official usage
49
+ do_sample=False ##change this to align with the official usage
50
+ )
51
+ generated_ids = [
52
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
53
+ ]
54
+
55
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
56
+ print(response)
57
+ ##INT4:
58
+ ## That sounds like the start of an exciting story. What kind of adventures does she like? Is she into hiking, traveling, trying new foods, or something else? Tell me more about her!
59
+
60
+ ##BF16:
61
+ ##
62
+
63
+ prompt = "Which one is larger, 9.11 or 9.8"
64
+ ##INT4:
65
+ ## 9.11 is larger than 9.8.
66
+
67
+ ##BF16:
68
+ ##
69
+
70
+ prompt = "How many r in strawberry."
71
+ ##INT4:
72
+ ## There are 2 R's in the word "strawberry".
73
+
74
+ ##BF16:
75
+ ##
76
+
77
+ prompt = "Once upon a time,"
78
+ ##INT4:
79
+ ## ...in a far-off kingdom, where the sun dipped into the horizon and painted the sky with hues of crimson and gold, there lived a young adventurer named Sophia. She was a curious and brave soul, with a heart full of wonder and a mind full of questions. Sophia lived in a small village on the outskirts of the kingdom, surrounded by rolling hills and dense forests that whispered secrets to the wind.
80
+ ## One day, Sophia stumbled upon an ancient map that had been hidden away in the village library. The map was worn and torn, but it seemed to point to a mysterious location deep within the forest. The map was labeled with a single word: "Eldrador".
81
+ ## Sophia felt an inexplicable pull towards the map and the secrets it held. She decided to embark on a journey to uncover the truth about Eldrador, and to explore the unknown lands that lay beyond the edge of the kingdom.
82
+ ## As she set out on her quest, Sophia encountered a wise old wizard named Zephyr,
83
+
84
+ ##BF16:
85
+ ##
86
+
87
+ ```
88
+ ### Evaluate the model
89
+ pip3 install lm-eval==0.4.5
90
+
91
+ ```bash
92
+ auto-round --eval --model_name "OPEA/Llama-3.3-70B-Instruct-int4-sym-inc-private" --eval_bs 16 --tasks leaderboard_mmlu_pro,leaderboard_ifeval,lambada_openai,hellaswag,piqa,winogrande,truthfulqa_mc1,openbookqa,boolq,arc_easy,arc_challenge,mmlu,gsm8k
93
+ ```
94
+
95
+ | Metric | BF16 | INT4 |
96
+ | --------------------------- | ------------------------ | ------------------------ |
97
+ | avg | | |
98
+ | leaderboard_mmlu_pro 5shot | | |
99
+ | leaderboard_ifeval | | |
100
+ | lambada_openai | | 0.7599 |
101
+ | hellaswag | | 0.6540 |
102
+ | winogrande | | 0.7932 |
103
+ | piqa | | 0.8254 |
104
+ | truthfulqa_mc1 | | 0.4272 |
105
+ | openbookqa | | 0.3540 |
106
+ | boolq | | 0.8826 |
107
+ | arc_easy | | 0.8577 |
108
+ | arc_challenge | | 0.6015 |
109
+ | gsm8k(5shot) strict match | | |
110
+
111
+ ## Generate the model
112
+
113
+ Here is the sample command to reproduce the model. We found auto-round is not stable for this model, please do NOT use --model_dtype "fp16"
114
+
115
+ ```bash
116
+ auto-round \
117
+ --model meta-llama/Llama-3.3-70B-Instruct \
118
+ --device 0 \
119
+ --group_size 128 \
120
+ --nsamples 512 \
121
+ --bits 4 \
122
+ --iter 1000 \
123
+ --disable_eval \
124
+ --low_gpu_mem_usage \
125
+ --format 'auto_gptq,auto_round' \
126
+ --output_dir "./tmp_autoround"
127
+ ```
128
+
129
+
130
+
131
+ ## Ethical Considerations and Limitations
132
+
133
+ 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.
134
+
135
+ Therefore, before deploying any applications of the model, developers should perform safety testing.
136
+
137
+ ## Caveats and Recommendations
138
+
139
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
140
+
141
+ Here are a couple of useful links to learn more about Intel's AI software:
142
+
143
+ - Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
144
+
145
+ ## Disclaimer
146
+
147
+ 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.
148
+
149
+ ## Cite
150
+
151
+ @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} }
152
+
153
+ [arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)