Model Details
This model is an int4 model with group_size 128 and symmetric quantization of Qwen/Qwen2.5-3B-Instruct generated by intel/auto-round. Load the model with revision="f636d1"
to use AutoGPTQ format
How To Use
INT4 Inference(CPU/HPU/CUDA)
CPU 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-3B-Instruct-int4-inc"
tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
model = AutoModelForCausalLM.from_pretrained(
quantized_model_dir,
torch_dtype='auto',
device_map="auto",
##revision="f636d1" ## AutoGPTQ format
)
##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:
"""That's great! Exploring new adventures can be very exciting and fulfilling. What kind of adventures does this girl like to go on? Is there a particular place or activity she enjoys the most? Knowing more specifics might help me provide better advice or suggestions.
"""
##BF16:
"""That's great! Adventure can be a wonderful way to explore new experiences and push oneself out of comfort zones. What kind of adventures does this girl like? Is there a particular type of activity or location she enjoys? Knowing more specifics might help me provide better advice or suggestions.
"""
prompt = "9.11和9.8哪个数字大"
#INT4:
"""在数值比较中,9.11大于9.8。因为9.11比9.8多0.11,即使小数部分再小,也比整数9大。"""
##BF16:
"""要比较9.11和9.8的大小,可以按照以下步骤进行:
1. 比较整数部分:两个数字的整数部分都是9,所以需要进一步比较小数部分。
2. 比较小数部分:
- 9.11的小数部分是0.11
- 9.8的小数部分是0.8
显然,0.11小于0.8。
因此,9.8大于9.11。"""
prompt = "Once upon a time,"
##INT4:
"""Once upon a time, in a land far, far away...
Would you like to continue the story or have a specific setting and characters in mind? I'd be happy to help you develop your tale!"""
##BF16:
"""Once upon a time, sounds like the beginning of an enchanting story! What kind of story would you like to hear? Is there a particular theme or character you'd like to see in your tale?
"""
prompt = "请简短介绍一下阿里巴巴公司"
##INT4:
"""阿里巴巴集团(Alibaba Group)是一家总部位于中国杭州的跨国科技公司,由马云于1999年创立。阿里巴巴旗下拥有淘宝、天猫、菜鸟网络等知名电商平台和物流平台。阿里巴巴是全球最大的电子商务公司之一,也是中国最大的互联网服务提供商之一。阿里巴巴在2014年成功上市,成为当时全球最大的IPO之一。"""
##BF16:
"""阿里巴巴集团(Alibaba Group Holding Limited),简称“阿里”,是一家以互联网原生的电子商务、金融、物流、云计算等业务为主的大型企业,总部位于中国杭州。阿里巴巴旗下拥有淘宝网、天猫、聚划算等多个知名电商平台,以及支付宝、菜鸟网络等业务板块。阿里巴巴在全球范围内拥有超过20万家商家和数亿用户,是全球最大的在线零售平台之一。阿里巴巴在2014年9月19日在香港联交所上市,成为全球第二大互联网上市公司。
"""
Evaluate the model
pip3 install lm-eval==0.4.5
auto-round --model "OPEA/Qwen2.5-3B-Instruct-int4-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.5716 | 0.5610 |
leaderboard_mmlu_pro 5 shots | 0.3757 | 0.3575 |
leaderboard_ifeval inst_level_strict_acc | 0.6103 | 0.5923 |
leaderboard_ifeval prompt_level_strict_acc | 0.4861 | 0.4769 |
mmlu | 0.6544 | 0.6421 |
cmmlu | 0.7222 | 0.6937 |
ceval-valid | 0.7214 | 0.7051 |
gsm8k 5 shots | 0.1069 | 0.0940 |
lambada_openai | 0.6604 | 0.6497 |
hellaswag | 0.5633 | 0.5520 |
winogrande | 0.6906 | 0.6859 |
piqa | 0.7742 | 0.7742 |
truthfulqa_mc1 | 0.4174 | 0.4088 |
openbookqa | 0.3340 | 0.3080 |
boolq | 0.8009 | 0.8116 |
arc_easy | 0.7698 | 0.7681 |
arc_challenge | 0.4573 | 0.4565 |
Generate the model
Here is the sample command to generate the model. We observed a larger accuracy drop in Chinese tasks and recommend using a high-quality Chinese dataset for calibration or smaller group_size like 32.
auto-round \
--model Qwen/Qwen2.5-3B-Instruct \
--device 0 \
--group_size 128 \
--nsamples 512 \
--bits 4 \
--iter 1000 \
--disable_eval \
--model_dtype "fp16" \
--format 'auto_gptq,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} }
- Downloads last month
- 5