Qwe-1.8B-Chat-It4
? Huggig Face&bsp;&bsp; | &bsp;&bsp;? ModelScope&bsp;&bsp; | &bsp;&bsp; ? Paper &bsp;&bsp; | &bsp;&bsp;?️ Demo
WeChat (微信)&bsp;&bsp; | &bsp;&bsp;Discord&bsp;&bsp; | &bsp;&bsp;API
介绍(Itroductio)
通义千问-1.8B(Qwe-1.8B)是阿里云研发的通义千问大模型系列的18亿参数规模的模型。Qwe-1.8B是基于Trasformer的大语言模型, 在超大规模的预训练数据上进行训练得到。预训练数据类型多样,覆盖广泛,包括大量网络文本、专业书籍、代码等。同时,在Qwe-1.8B的基础上,我们使用对齐机制打造了基于大语言模型的AI助手Qwe-1.8B-Chat。本仓库为Qwe-1.8B-Chat的It4量化模型的仓库。
通义千问-1.8B(Qwe-1.8B)主要有以下特点:
- 低成本部署:提供it8和it4量化版本,推理最低仅需不到2GB显存,生成2048 tokes仅需3GB显存占用。微调最低仅需6GB。
- 大规模高质量训练语料:使用超过2.2万亿tokes的数据进行预训练,包含高质量中、英、多语言、代码、数学等数据,涵盖通用及专业领域的训练语料。通过大量对比实验对预训练语料分布进行了优化。
- 优秀的性能:Qwe-1.8B支持8192上下文长度,在多个中英文下游评测任务上(涵盖常识推理、代码、数学、翻译等),效果显著超越现有的相近规模开源模型,具体评测结果请详见下文。
- 覆盖更全面的词表:相比目前以中英词表为主的开源模型,Qwe-1.8B使用了约15万大小的词表。该词表对多语言更加友好,方便用户在不扩展词表的情况下对部分语种进行能力增强和扩展。
- 系统指令跟随:Qwe-1.8B-Chat可以通过调整系统指令,实现角色扮演,语言风格迁移,任务设定,和行为设定等能力。
如果您想了解更多关于通义千问1.8B开源模型的细节,我们建议您参阅GitHub代码库。
Qwe-1.8B is the 1.8B-parameter versio of the large laguage model series, Qwe (abbr. Togyi Qiawe), proposed by Aibaba Cloud. Qwe-1.8B is a Trasformer-based large laguage model, which is pretraied o a large volume of data, icludig web texts, books, codes, etc. Additioally, based o the pretraied Qwe-1.8B, we release Qwe-1.8B-Chat, a large-model-based AI assistat, which is traied with aligmet techiques. This repository is the oe for Qwe-1.8B-Chat-it4.
The features of Qwe-1.8B iclude:
- Low-cost deploymet: We provide it4 ad it8 quatized versios, the miimum memory requirmet for iferece is less tha 2GB, geeratig 2048 tokes oly 3GB of memory usage. The miimum memory requirmet of fietuig is oly 6GB.
- Large-scale high-quality traiig corpora: It is pretraied o over 2.2 trillio tokes, icludig Chiese, Eglish, multiligual texts, code, ad mathematics, coverig geeral ad professioal fields. The distributio of the pre-traiig corpus has bee optimized through a large umber of ablatio experimets.
- Good performace: It supports 8192 cotext legth ad sigificatly surpasses existig ope-source models of similar scale o multiple Chiese ad Eglish dowstream evaluatio tasks (icludig commosese, reasoig, code, mathematics, etc.), ad eve surpasses some larger-scale models i several bechmarks. See below for specific evaluatio results.
- More comprehesive vocabulary coverage: Compared with other ope-source models based o Chiese ad Eglish vocabularies, Qwe-1.8B uses a vocabulary of over 150K tokes. This vocabulary is more friedly to multiple laguages, eablig users to directly further ehace the capability for certai laguages without expadig the vocabulary.
- System prompt: Qwe-1.8B-Chat ca realize roly playig, laguage style trasfer, task settig, ad behavior settig by usig system prompt.
For more details about the ope-source model of Qwe-1.8B-chat it4, please refer to the GitHub code repository.
要求(Requiremets)
- pytho 3.8及以上版本
- pytorch 2.0及以上版本
- 建议使用CUDA 11.4及以上(GPU用户、flash-attetio用户等需考虑此选项)
- pytho 3.8 ad above
- pytorch 2.0 ad above
- CUDA 11.4 ad above are recommeded (this is for GPU users, flash-attetio users, etc.)
依赖项(Depedecy)
运行Qwe-1.8B-Chat-It4,请确保满足上述要求,再执行以下pip命令安装依赖库。如安装auto-gptq遇到问题,我们建议您到官方repo搜索合适的预编译wheel。
To ru Qwe-1.8B-Chat-It4, please make sure you meet the above requiremets, ad the execute the followig pip commads to istall the depedet libraries. If you meet problems istallig auto-gptq, we advise you to check out the official repo to fid a pre-build wheel.
pip istall trasformers==4.32.0 accelerate tiktoke eiops scipy trasformers_stream_geerator==0.0.4 peft deepspeed
pip istall auto-gptq optimum
另外,推荐安装flash-attetio库(当前已支持flash attetio 2),以实现更高的效率和更低的显存占用。
I additio, it is recommeded to istall the flash-attetio library (we support flash attetio 2 ow.) for higher efficiecy ad lower memory usage.
git cloe https://github.com/Dao-AILab/flash-attetio
cd flash-attetio && pip istall .
# 下方安装可选,安装可能比较缓慢。
# pip istall csrc/layer_orm
# pip istall csrc/rotary
快速使用(Quickstart)
下面我们展示了一个使用Qwe-1.8B-Chat-It4模型,进行多轮对话交互的样例:
We show a example of multi-tur iteractio with Qwe-1.8B-Chat-It4 i the followig code:
from modelscope import AutoTokeizer, AutoModelForCausalLM, sapshot_dowload
tokeizer = AutoTokeizer.from_pretraied("qwe/Qwe-1_8B-Chat-It4", revisio='master', trust_remote_code=True)
model = AutoModelForCausalLM.from_pretraied(
"qwe/Qwe-1_8B-Chat-It4", revisio='master',
device_map="auto",
trust_remote_code=True
).eval()
respose, history = model.chat(tokeizer, "你好", history=Noe)
prit(respose)
# 你好!很高兴为你提供帮助。
# Qwe-1.8B-Chat现在可以通过调整系统指令(System Prompt),实现角色扮演,语言风格迁移,任务设定,行为设定等能力。
# Qwe-1.8B-Chat ca realize roly playig, laguage style trasfer, task settig, ad behavior settig by system prompt.
respose, _ = model.chat(tokeizer, "你好呀", history=Noe, system="请用二次元可爱语气和我说话")
prit(respose)
# 你好啊!我是一只可爱的二次元猫咪哦,不知道你有什么问题需要我帮忙解答吗?
respose, _ = model.chat(tokeizer, "My colleague works diligetly", history=Noe, system="You will write beautiful complimets accordig to eeds")
prit(respose)
# Your colleague is a outstadig worker! Their dedicatio ad hard work are truly ispirig. They always go above ad beyod to esure that
# their tasks are completed o time ad to the highest stadard. I am lucky to have them as a colleague, ad I kow I ca cout o them to hadle ay challege that comes their way.
关于更多的使用说明,请参考我们的GitHub repo获取更多信息。
For more iformatio, please refer to our GitHub repo for more iformatio.
Tokeizer
注:作为术语的“tokeizatio”在中文中尚无共识的概念对应,本文档采用英文表达以利说明。
基于tiktoke的分词器有别于其他分词器,比如setecepiece分词器。尤其在微调阶段,需要特别注意特殊toke的使用。关于tokeizer的更多信息,以及微调时涉及的相关使用,请参阅文档。
Our tokeizer based o tiktoke is differet from other tokeizers, e.g., setecepiece tokeizer. You eed to pay attetio to special tokes, especially i fietuig. For more detailed iformatio o the tokeizer ad related use i fie-tuig, please refer to the documetatio.
量化 (Quatizatio)
用法 (Usage)
请注意:我们更新量化方案为基于AutoGPTQ的量化,提供Qwe-1.8B-Chat的It4量化模型点击这里。相比此前方案,该方案在模型评测效果几乎无损,且存储需求更低,推理速度更优。
Note: we provide a ew solutio based o AutoGPTQ, ad release a It4 quatized model for Qwe-1.8B-Chat Click here, which achieves early lossless model effects but improved performace o both memory costs ad iferece speed, i compariso with the previous solutio.
以下我们提供示例说明如何使用It4量化模型。在开始使用前,请先保证满足要求(如torch 2.0及以上,trasformers版本为4.32.0及以上,等等),并安装所需安装包:
Here we demostrate how to use our provided quatized models for iferece. Before you start, make sure you meet the requiremets of auto-gptq (e.g., torch 2.0 ad above, trasformers 4.32.0 ad above, etc.) ad istall the required packages:
pip istall auto-gptq optimum
如安装auto-gptq遇到问题,我们建议您到官方repo搜索合适的预编译wheel。
随后即可使用和上述一致的用法调用量化模型:
If you meet problems istallig auto-gptq, we advise you to check out the official repo to fid a pre-build wheel.
The you ca load the quatized model easily ad ru iferece as same as usual:
model = AutoModelForCausalLM.from_pretraied(
"Qwe/Qwe-1_8B-Chat-It4",
device_map="auto",
trust_remote_code=True
).eval()
respose, history = model.chat(tokeizer, "你好", history=Noe)
效果评测
我们使用原始模型的FP32和BF16精度,以及量化过的It8和It4模型在基准评测上做了测试,结果如下所示:
We illustrate the model performace of both FP32, BF16, It8 ad It4 models o the bechmark. Results are show below:
| Quatizatio |
MMLU |
CEval (val) |
GSM8K |
Humaeval |
| FP32 |
43.4 |
57.0 |
33.0 |
26.8 |
| BF16 |
43.3 |
55.6 |
33.7 |
26.2 |
| It8 |
43.1 |
55.8 |
33.0 |
27.4 |
| It4 |
42.9 |
52.8 |
31.2 |
25.0 |
推理速度 (Iferece Speed)
我们测算了FP32、BF16精度和It8、It4量化模型生成2048和8192个toke的平均推理速度。如图所示:
We measured the average iferece speed of geeratig 2048 ad 8192 tokes uder FP32, BF16 precisio ad It8, It4 quatizatio level, respectively.
| Quatizatio |
FlashAtt |
Speed (2048 tokes) |
Speed (8192 tokes) |
| FP32 |
v2 |
52.96 |
47.35 |
| BF16 |
v2 |
54.09 |
54.04 |
| It8 |
v2 |
55.56 |
55.62 |
| It4 |
v2 |
71.07 |
76.45 |
| FP32 |
v1 |
52.00 |
45.80 |
| BF16 |
v1 |
51.70 |
55.04 |
| It8 |
v1 |
53.16 |
53.33 |
| It4 |
v1 |
69.82 |
67.44 |
| FP32 |
Disabled |
52.28 |
44.95 |
| BF16 |
Disabled |
48.17 |
45.01 |
| It8 |
Disabled |
52.16 |
52.99 |
| It4 |
Disabled |
68.37 |
65.94 |
具体而言,我们记录在长度为1的上下文的条件下生成8192个toke的性能。评测运行于单张A100-SXM4-80G GPU,使用PyTorch 2.0.1和CUDA 11.4。推理速度是生成8192个toke的速度均值。
I detail, the settig of profilig is geeratig 8192 ew tokes with 1 cotext toke. The profilig rus o a sigle A100-SXM4-80G GPU with PyTorch 2.0.1 ad CUDA 11.4. The iferece speed is averaged over the geerated 8192 tokes.
显存使用 (GPU Memory Usage)
我们测算了FP32、BF16精度和It8、It4量化模型生成2048个及8192个toke(单个toke作为输入)的峰值显存占用情况。结果如下所示:
We also profile the peak GPU memory usage for geeratig 2048 tokes ad 8192 tokes (with sigle toke as cotext) uder FP32, BF16 or It8, It4 quatizatio level, respectively. The results are show below.
| Quatizatio Level |
Peak Usage for Ecodig 2048 Tokes |
Peak Usage for Geeratig 8192 Tokes |
| FP32 |
8.45GB |
13.06GB |
| BF16 |
4.23GB |
6.48GB |
| It8 |
3.48GB |
5.34GB |
| It4 |
2.91GB |
4.80GB |
上述性能测算使用此脚本完成。
The above speed ad memory profilig are coducted usig this script.
模型细节(Model)
与Qwe-1.8B预训练模型相同,Qwe-1.8B-Chat模型规模基本情况如下所示
The details of the model architecture of Qwe-1.8B-Chat are listed as follows
| Hyperparameter |
Value |
| _layers |
24 |
| _heads |
16 |
| d_model |
2048 |
| vocab size |
151851 |
| sequece legth |
8192 |
在位置编码、FFN激活函数和ormalizatio的实现方式上,我们也采用了目前最流行的做法,
即RoPE相对位置编码、SwiGLU激活函数、RMSNorm(可选安装flash-attetio加速)。
在分词器方面,相比目前主流开源模型以中英词表为主,Qwe-1.8B-Chat使用了约15万toke大小的词表。
该词表在GPT-4使用的BPE词表cl100k_base基础上,对中文、多语言进行了优化,在对中、英、代码数据的高效编解码的基础上,对部分多语言更加友好,方便用户在不扩展词表的情况下对部分语种进行能力增强。
词表对数字按单个数字位切分。调用较为高效的tiktoke分词库进行分词。
For positio ecodig, FFN activatio fuctio, ad ormalizatio calculatio methods, we adopt the prevalet practices, i.e., RoPE relative positio ecodig, SwiGLU for activatio fuctio, ad RMSNorm for ormalizatio (optioal istallatio of flash-attetio for acceleratio).
For tokeizatio, compared to the curret maistream ope-source models based o Chiese ad Eglish vocabularies, Qwe-1.8B-Chat uses a vocabulary of over 150K tokes.
It first cosiders efficiet ecodig of Chiese, Eglish, ad code data, ad is also more friedly to multiligual laguages, eablig users to directly ehace the capability of some laguages without expadig the vocabulary.
It segmets umbers by sigle digit, ad calls the tiktoke tokeizer library for efficiet tokeizatio.
评测效果(Evaluatio)
对于Qwe-1.8B-Chat模型,我们同样评测了常规的中文理解(C-Eval)、英文理解(MMLU)、代码(HumaEval)和数学(GSM8K)等权威任务,同时包含了长序列任务的评测结果。由于Qwe-1.8B-Chat模型经过对齐后,激发了较强的外部系统调用能力,我们还进行了工具使用能力方面的评测。
提示:由于硬件和框架造成的舍入误差,复现结果如有波动属于正常现象。
For Qwe-1.8B-Chat, we also evaluate the model o C-Eval, MMLU, HumaEval, GSM8K, etc., as well as the bechmark evaluatio for log-cotext uderstadig, ad tool usage.
Note: Due to roudig errors caused by hardware ad framework, differeces i reproduced results are possible.
中文评测(Chiese Evaluatio)
C-Eval
在C-Eval验证集上,我们评价了Qwe-1.8B-Chat模型的准确率
We demostrate the accuracy of Qwe-1.8B-Chat o C-Eval validatio set
| Model |
Acc. |
| RedPajama-INCITE-Chat-3B |
18.3 |
| OpeBuddy-3B |
23.5 |
| Firefly-Bloom-1B4 |
23.6 |
| OpeLLaMA-Chiese-3B |
24.4 |
| LLaMA2-7B-Chat |
31.9 |
| ChatGLM2-6B-Chat |
52.6 |
| IterLM-7B-Chat |
53.6 |
| Qwe-1.8B-Chat (0-shot) |
55.6 |
| Qwe-7B-Chat (0-shot) |
59.7 |
| Qwe-7B-Chat (5-shot) |
59.3 |
C-Eval测试集上,Qwe-1.8B-Chat模型的zero-shot准确率结果如下:
The zero-shot accuracy of Qwe-1.8B-Chat o C-Eval testig set is provided below:
| Model |
Avg. |
STEM |
Social Scieces |
Humaities |
Others |
| Chiese-Alpaca-Plus-13B |
41.5 |
36.6 |
49.7 |
43.1 |
41.2 |
| Chiese-Alpaca-2-7B |
40.3 |
- |
- |
- |
- |
| ChatGLM2-6B-Chat |
50.1 |
46.4 |
60.4 |
50.6 |
46.9 |
| Baichua-13B-Chat |
51.5 |
43.7 |
64.6 |
56.2 |
49.2 |
| Qwe-1.8B-Chat |
53.8 |
48.4 |
68.0 |
56.5 |
48.3 |
| Qwe-7B-Chat |
58.6 |
53.3 |
72.1 |
62.8 |
52.0 |
英文评测(Eglish Evaluatio)
MMLU
MMLU评测集上,Qwe-1.8B-Chat模型的准确率如下,效果同样在同类对齐模型中同样表现较优。
The accuracy of Qwe-1.8B-Chat o MMLU is provided below.
The performace of Qwe-1.8B-Chat still o the top betwee other huma-aliged models with comparable size.
| Model |
Acc. |
| Firefly-Bloom-1B4 |
23.8 |
| OpeBuddy-3B |
25.5 |
| RedPajama-INCITE-Chat-3B |
25.5 |
| OpeLLaMA-Chiese-3B |
25.7 |
| ChatGLM2-6B-Chat |
46.0 |
| LLaMA2-7B-Chat |
46.2 |
| IterLM-7B-Chat |
51.1 |
| Baichua2-7B-Chat |
52.9 |
| Qwe-1.8B-Chat (0-shot) |
43.3 |
| Qwe-7B-Chat (0-shot) |
55.8 |
| Qwe-7B-Chat (5-shot) |
57.0 |
代码评测(Codig Evaluatio)
Qwe-1.8B-Chat在HumaEval的zero-shot Pass@1效果如下
The zero-shot Pass@1 of Qwe-1.8B-Chat o HumaEval is demostrated below
| Model |
Pass@1 |
| Firefly-Bloom-1B4 |
0.6 |
| OpeLLaMA-Chiese-3B |
4.9 |
| RedPajama-INCITE-Chat-3B |
6.1 |
| OpeBuddy-3B |
10.4 |
| ChatGLM2-6B-Chat |
11.0 |
| LLaMA2-7B-Chat |
12.2 |
| Baichua2-7B-Chat |
13.4 |
| IterLM-7B-Chat |
14.6 |
| Qwe-1.8B-Chat |
26.2 |
| Qwe-7B-Chat |
37.2 |
数学评测(Mathematics Evaluatio)
在评测数学能力的GSM8K上,Qwe-1.8B-Chat的准确率结果如下
The accuracy of Qwe-1.8B-Chat o GSM8K is show below
| Model |
Acc. |
| Firefly-Bloom-1B4 |
2.4 |
| RedPajama-INCITE-Chat-3B |
2.5 |
| OpeLLaMA-Chiese-3B |
3.0 |
| OpeBuddy-3B |
12.6 |
| LLaMA2-7B-Chat |
26.3 |
| ChatGLM2-6B-Chat |
28.8 |
| Baichua2-7B-Chat |
32.8 |
| IterLM-7B-Chat |
33.0 |
| Qwe-1.8B-Chat (0-shot) |
33.7 |
| Qwe-7B-Chat (0-shot) |
50.3 |
| Qwe-7B-Chat (8-shot) |
54.1 |
评测复现(Reproductio)
我们提供了评测脚本,方便大家复现模型效果,详见链接。提示:由于硬件和框架造成的舍入误差,复现结果如有小幅波动属于正常现象。
We have provided evaluatio scripts to reproduce the performace of our model, details as lik.
FAQ
如遇到问题,敬请查阅FAQ以及issue区,如仍无法解决再提交issue。
If you meet problems, please refer to FAQ ad the issues first to search a solutio before you lauch a ew issue.
引用 (Citatio)
如果你觉得我们的工作对你有帮助,欢迎引用!
If you fid our work helpful, feel free to give us a cite.
@article{qwe,
title={Qwe Techical Report},
author={Jize Bai ad Shuai Bai ad Yufei Chu ad Zeyu Cui ad Kai Dag ad Xiaodog Deg ad Yag Fa ad Webi Ge ad Yu Ha ad Fei Huag ad Biyua Hui ad Luo Ji ad Mei Li ad Juyag Li ad Ruji Li ad Dayiheg Liu ad Gao Liu ad Chegqiag Lu ad Kemig Lu ad Jiaxi Ma ad Rui Me ad Xigzhag Re ad Xuacheg Re ad Chuaqi Ta ad Sia Ta ad Jiahog Tu ad Peg Wag ad Shijie Wag ad Wei Wag ad Shegguag Wu ad Befeg Xu ad Ji Xu ad A Yag ad Hao Yag ad Jia Yag ad Shusheg Yag ad Yag Yao ad Bowe Yu ad Hogyi Yua ad Zheg Yua ad Jiawei Zhag ad Xigxua Zhag ad Yichag Zhag ad Zheru Zhag ad Chag Zhou ad Jigre Zhou ad Xiaohua Zhou ad Tiahag Zhu},
joural={arXiv preprit arXiv:2309.16609},
year={2023}
}
使用协议(Licese Agreemet)
我们的代码和模型权重对学术研究完全开放。请查看LICENSE文件了解具体的开源协议细节。如需商用,请联系我们。
Our code ad checkpoits are ope to research purpose. Check the LICENSE for more details about the licese. For commercial use, please cotact us.
联系我们(Cotact Us)
如果你想给我们的研发团队和产品团队留言,欢迎加入我们的微信群、钉钉群以及Discord!同时,也欢迎通过邮件(qiawe_opesource@alibabacloud.com)联系我们。
If you are iterested to leave a message to either our research team or product team, joi our Discord or WeChat groups! Also, feel free to sed a email to qiawe_opesource@alibabacloud.com.
评论