🚀 Intel/Qwen2-7B-int4-inc模型
本项目是一个基于Qwen/Qwen2-7B
模型的量化模型,使用intel/auto-round
工具生成int4自动舍入模型。该模型在多种任务上进行了评估,为用户提供了高效的推理和评估方式。
🚀 快速开始
模型详情
此模型是由 intel/auto-round 生成的 Qwen/Qwen2-7B 的 int4 自动舍入模型,分组大小为 128。如果需要 AutoGPTQ 格式,请使用版本 07a117c
加载模型。
安装指南
pip3 install lm-eval==0.4.4,auto-round
💻 使用示例
基础用法
INT4 推理
from auto_round import AutoRoundConfig
from transformers import AutoModelForCausalLM,AutoTokenizer
quantized_model_dir = "Intel/Qwen2-7B-int4-inc"
tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
model = AutoModelForCausalLM.from_pretrained(quantized_model_dir,
device_map="auto"
)
text = "下面我来介绍一下阿里巴巴公司,"
text = "9.8和9.11哪个数字大?答案是"
text = "Once upon a time,"
text = "There is a girl who likes adventure,"
inputs = tokenizer(text, return_tensors="pt").to(model.device)
print(tokenizer.decode(model.generate(**inputs, max_new_tokens=50, do_sample=False)[0]))
Intel Gaudi - 2 INT4 推理
建议使用带有 Gaudi 软件栈的 Docker 镜像。更多详情可查看 Gaudi 指南。
import habana_frameworks.torch.core as htcore
import habana_frameworks.torch.hpu as hthpu
from auto_round import AutoRoundConfig
from transformers import AutoModelForCausalLM,AutoTokenizer
quantized_model_dir = "Intel/Qwen2-7B-int4-inc"
tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
model = AutoModelForCausalLM.from_pretrained(quantized_model_dir).to('hpu').to(bfloat16)
text = "下面我来介绍一下阿里巴巴公司,"
inputs = tokenizer(text, return_tensors="pt").to(model.device)
print(tokenizer.decode(model.generate(**inputs, max_new_tokens=50, do_sample=False)[0]))
高级用法
评估模型
auto-round --model "Intel/Qwen2-7B-int4-inc" --eval --eval_bs 16 --tasks lambada_openai,hellaswag,piqa,winogrande,truthfulqa_mc1,openbookqa,boolq,arc_easy,arc_challenge,mmlu,gsm8k,cmmlu,ceval-valid
指标 |
BF16 |
INT4 |
平均值 |
0.6659 |
0.6604 |
mmlu |
0.6697 |
0.6646 |
cmmlu |
0.8254 |
0.8118 |
ceval - valid |
0.8339 |
0.8053 |
lambada_openai |
0.7182 |
0.7136 |
hellaswag |
0.5823 |
0.5752 |
winogrande |
0.7222 |
0.7277 |
piqa |
0.7911 |
0.7933 |
truthfulqa_mc1 |
0.3647 |
0.3476 |
openbookqa |
0.3520 |
0.3440 |
boolq |
0.8183 |
0.8223 |
arc_easy |
0.7660 |
0.7635 |
arc_challenge |
0.4505 |
0.4633 |
gsm8k 5 shots(严格匹配) |
0.7619 |
0.7528 |
生成模型
以下是重现该模型的示例命令。我们发现中文任务的准确率下降较大,建议使用高质量的中文数据集进行校准。然而,使用一些公共数据集并未获得更好的准确率。
auto-round
--model_name Qwen/Qwen2-7B \
--device 0 \
--group_size 128 \
--nsamples 512 \
--bits 4 \
--iter 1000 \
--disable_eval \
--model_dtype "float16" \
--format 'auto_round' \
--output_dir "./tmp_autoround"
📚 详细文档
伦理考量与局限性
该模型可能会产生事实错误的输出,因此不应依赖其生成事实准确的信息。由于预训练模型和微调数据集的局限性,此模型有可能生成低俗、有偏见或其他冒犯性的输出。
因此,在部署该模型的任何应用之前,开发者应进行安全测试。
注意事项和建议
用户(直接用户和下游用户)应了解该模型的风险、偏差和局限性。
以下是一些了解英特尔 AI 软件的有用链接:
- 英特尔神经压缩器 链接
- 英特尔 Transformers 扩展 链接
免责声明
此模型的许可证不构成法律建议。我们不对使用此模型的第三方的行为负责。如需将此模型用于商业目的,请咨询律师。
引用
@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
📄 许可证
本模型使用 Apache - 2.0 许可证。