OPEA
/

Safetensors

Model Details

This model is an int4 model with group_size 128 and symmetric quantization of Qwen/Qwen2.5-32B-Instruct generated by 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

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

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

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

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

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 github

Downloads last month
34
Safetensors
Model size
6.1B params
Tensor type
FP16
·
I32
·
Inference API
Unable to determine this model's library. Check the docs .

Dataset used to train OPEA/Qwen2.5-32B-Instruct-int4-sym-mixed-inc

Collection including OPEA/Qwen2.5-32B-Instruct-int4-sym-mixed-inc