File size: 10,785 Bytes
38b23d7 0cc5468 38b23d7 e7c4eda 38b23d7 b7b236d 38b23d7 b7b236d 38b23d7 b7b236d 38b23d7 |
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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
---
license: apache-2.0
datasets:
- NeelNanda/pile-10k
base_model:
- Qwen/Qwen2.5-32B-Instruct
---
## Model Details
This model is an int4 model with group_size 128 and symmetric quantization of [Qwen/Qwen2.5-32B-Instruct](https://huggingface.co/Qwen/Qwen2.5-32B-Instruct) generated by [intel/auto-round](https://github.com/intel/auto-round). We excluded 3 layers from quantization due to the overflow issue on some int4 backends.
## How To Use
### INT4 Inference(CPU/HPU/CUDA)
CPU/ CUDA requires auto-round version>0.3.1
```python
from auto_round import AutoRoundConfig ##must import for auto-round format
from transformers import AutoModelForCausalLM,AutoTokenizer
quantized_model_dir = "OPEA/Qwen2.5-32B-Instruct-int4-sym-mixed-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=200, ##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,"
##INT4:
"""It sounds like you're starting to tell a story! Would you like me to help you continue it? Here's one possible continuation:
There is a girl who loves adventure. Her name is Lily and she has always been drawn to the unknown. From a young age, she would spend hours exploring the woods behind her house, imagining herself as a brave explorer discovering new lands. As she grew older, her thirst for adventure only intensified. She began traveling the world, seeking out thrilling experiences and pushing herself out of her comfort zone at every turn.
Is there anything specific you had in mind for this character or story? I'd be happy to help develop it further if you have any ideas!"""
##BF16:
"""That sounds exciting! What would you like to know or do regarding this girl who loves adventure? Perhaps you're looking for ideas on activities she might enjoy or ways to support her adventurous spirit. Let me know how I can assist you further!"""
prompt = "9.11和9.8哪个数字大"
#INT4:
"""? 9.8 比 9.11 大。在比较这两个数字时,我们首先看整数部分,它们都是9,所以需要比较小数部分。0.8(即8/10)比0.11(即11/100)要大。因此,9.8 > 9.11。
具体来说:
- 9.8 = 9 + 0.8
- 9.11 = 9 + 0.11
显然,0.8 > 0.11,所以 9.8 > 9.11。"""
##BF16:
"""要比较两个数字的大小,我们可以从左到右逐位进行比较。
首先,我们看整数部分:
- 9.11 的整数部分是 9。
- 9.8 的整数部分也是 9。
因为它们的整数部分相同,我们需要比较小数部分:
- 9.11 的小数部分是 0.11。
- 9.8 的小数部分是 0.8。
接下来,我们比较小数部分的第一位:
- 0.11 的第一位是 1。
- 0.8 的第一位是 8。
显然,8 比 1 大。因此,0.8 比 0.11 大。
所以,9.8 比 9.11 大。"""
prompt = "Once upon a time,"
##INT4:
""" there was a king who loved to collect beautiful flowers. He had a vast garden filled with all sorts of colorful and fragrant blooms. However, one day he decided that he wanted to have the most unique flower in the world. So he sent out a proclamation to his kingdom, offering a great reward to anyone who could bring him a flower that no one else had ever seen before.
A young girl named Lily heard about the king's proclamation and became determined to win the prize. She spent days wandering through the forest, searching for the perfect flower. Finally, she stumbled upon a small, delicate flower that she had never seen before. It was a bright shade of purple and had a sweet fragrance.
Lily brought the flower back to the king, who was amazed by its beauty and uniqueness. He declared her the winner and gave her the reward. But as she was leaving, the king stopped her and asked if she would teach him how to grow this special flower. Lily agreed and spent the next
"""
##BF16:
"""Once upon a time, in a land far, far away, there was a small village nestled between rolling hills and dense forests. The villagers lived simple lives, farming the land and tending to their livestock. They were a close-knit community, always ready to help one another in times of need.
In the heart of this village stood an ancient oak tree, under which the elders would gather to share stories and make important decisions for the community. Among these tales were whispers of a hidden treasure, said to be guarded by a mythical creature deep within the forest.
One day, a young girl named Elara overheard these whispers while fetching water from the well. Her curiosity piqued, she decided to embark on a quest to uncover the truth behind the legend. With nothing but her wits, a small backpack, and a map drawn by the village cartographer, Elara set off into the unknown.
As she ventured deeper into the forest, she encountered various challenges and made unexpected friends along
"""
prompt = "请简短介绍一下阿里巴巴公司"
##INT4:
"""阿里巴巴集团(Alibaba Group)是一家总部位于中国杭州的全球领先的电子商务和科技公司。它成立于1999年,由马云等创始人共同创立。阿里巴巴旗下拥有包括淘宝网、天猫、阿里云、菜鸟网络等多个知名业务板块,涵盖了电子商务、零售、金融、物流、云计算等多个领域。阿里巴巴通过技术创新和商业模式创新,推动了数字经济的发展,并在全球范围内产生了深远影响。2014年,阿里巴巴在纽约证券交易所上市,成为当时全球最大的IPO之一。阿里巴巴集团的愿景是让世界各地的企业没有难做的生意。
"""
##BF16:
"""阿里巴巴集团是一家中国跨国科技公司,成立于1999年,总部位于中国杭州。该公司以B2B电子商务平台起家,现已发展成为涵盖零售、金融、物流、云计算等多个领域的综合性企业集团。旗下拥有淘宝、天猫、阿里云等知名业务,是全球最大的电子商务和零售平台之一。阿里巴巴致力于通过技术创新和商业生态系统建设,推动数字经济的发展,并为消费者和企业提供优质的产品与服务。
"""
```
### Evaluate the model
pip3 install lm-eval==0.4.5
```bash
auto-round --model "OPEA/Qwen2.5-32B-Instruct-int4-sym-mixed-inc" --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
```
| Metric | BF16 | INT4 |
| :----------------------------------------- | :----: | :----: |
| Avg | 0.7120 | 0.7089 |
| leaderboard_mmlu_pro 5 shots | 0.5917 | 0.5795 |
| leaderboard_ifeval inst_level_strict_acc | 0.7314 | 0.7254 |
| leaderboard_ifeval prompt_level_strict_acc | 0.6248 | 0.6285 |
| mmlu | 0.8169 | 0.8148 |
| cmmlu | 0.8673 | 0.8586 |
| ceval-valid | 0.8811 | 0.8700 |
| gsm8k 5 shots | 0.7680 | 0.8052 |
| lambada_openai | 0.7522 | 0.7417 |
| hellaswag | 0.6685 | 0.6643 |
| winogrande | 0.7372 | 0.7324 |
| piqa | 0.8085 | 0.8134 |
| truthfulqa_mc1 | 0.4871 | 0.4749 |
| openbookqa | 0.3580 | 0.3480 |
| boolq | 0.8966 | 0.8841 |
| arc_easy | 0.8237 | 0.8228 |
| arc_challenge | 0.5785 | 0.5785 |
### Generate the model
Here is the sample command to generate the model.
For symmetric quantization, we found overflow/NAN will occur for some backends, so better fallback some layers. auto_round requires version >=0.4.1
```bash
auto-round \
--model Qwen/Qwen2.5-32B-Instruct \
--device 0 \
--group_size 128 \
--nsamples 512 \
--bits 4 \
--iter 1000 \
--disable_eval \
--fp_layers "model.layers.5.mlp.down_proj,model.layers.5.mlp.up_proj,model.layers.5.mlp.gate_proj" \
--model_dtype "fp16" \
--format 'auto_round' \
--output_dir "./tmp_autoround"
```
Asym
```bash
auto-round \
--model Qwen/Qwen2.5-32B-Instruct \
--device 0 \
--group_size 128 \
--nsamples 512 \
--bits 4 \
--iter 1000 \
--disable_eval \
--asym
--model_dtype "fp16" \
--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)
## 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) |