Qwen-72B is the 72B-parameter version of the large language model series, Qwen (abbr. Tongyi Qianwen), proposed by Alibaba Cloud. Qwen-72B is a Transformer-based large language model, which is pretrained on a large volume of data, including web texts, books, codes, etc. Additionally, based on the pretrained Qwen-72B, we release Qwen-72B-Chat, a large-model-based AI assistant, which is trained with alignment techniques. This repository is the one for Qwen-72B-Chat.
The features of Qwen-72B include:
Large-scale high-quality training corpora: It is pretrained on over 3 trillion tokens, including Chinese, English, multilingual texts, code, and mathematics, covering general and professional fields. The distribution of the pre-training corpus has been optimized through a large number of ablation experiments.
Competitive performance: It significantly surpasses existing open-source models on multiple Chinese and English downstream evaluation tasks (including commonsense, reasoning, code, mathematics, etc.). See below for specific evaluation results.
More comprehensive vocabulary coverage: Compared with other open-source models based on Chinese and English vocabularies, Qwen-72B uses a vocabulary of over 150K tokens. This vocabulary is more friendly to multiple languages, enabling users to directly further enhance the capability for certain languages without expanding the vocabulary.
pytorch 1.12 and above, 2.0 and above are recommended
CUDA 11.4 and above are recommended (this is for GPU users, flash-attention users, etc.)
To run Qwen-72B-Chat in bf16/fp16, at least 144GB GPU memory is required (e.g., 2xA100-80G or 5xV100-32G). To run it in int4, at least 48GB GPU memory is required (e.g., 1xA100-80G or 2xV100-32G)
依赖项(Dependency)
使用HuggingFace进行推理
运行Qwen-72B-Chat,请确保满足上述要求,再执行以下pip命令安装依赖库
To run Qwen-72B-Chat, please make sure you meet the above requirements, and then execute the following pip commands to install the dependent libraries.
In addition, it is recommended to install the flash-attention library (we support flash attention 2 now.) for higher efficiency and lower memory usage.
bash
1git clone https://github.com/Dao-AILab/flash-attention
2cd flash-attention && pip install.3# 下方安装可选,安装可能比较缓慢。4# Below are optional. Installing them might be slow.5# pip install csrc/layer_norm6# 如果你的flash-attn版本高于2.1.1,下方不需要安装。7# If the version of flash-attn is higher than 2.1.1, the following is not needed.8# pip install csrc/rotary
使用vLLM进行推理
使用vLLM进行推理可以支持更长的上下文长度并获得至少两倍的生成加速。你需要满足以下要求:
Using vLLM for inference can support longer context lengths and obtain at least twice the generation speedup. You need to meet the following requirements:
pytorch >= 2.0
cuda 11.8 or 12.1
如果你使用cuda12.1和pytorch2.1,可以直接使用以下命令安装vLLM。
If you use cuda 12.1 and pytorch 2.1, you can directly use the following command to install vLLM.
bash
1# pip install vllm # This line is faster but it does not support quantization models.23# The below lines support int4 quantization (int8 will be supported soon). The installation are slower (~10 minutes).4git clone https://github.com/QwenLM/vllm-gptq
5cd vllm-gptq
6pip install -e .
使用HuggingFace Transformers进行推理(Inference with Huggingface Transformers)
下面我们展示了一个使用Qwen-72B-Chat模型,进行多轮对话交互的样例:
We show an example of multi-turn interaction with Qwen-72B-Chat in the following code:
python
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from transformers.generation import GenerationConfig
34# Note: The default behavior now has injection attack prevention off.5tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-72B-Chat", trust_remote_code=True)67# use bf168# model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-72B-Chat", device_map="auto", trust_remote_code=True, bf16=True).eval()9# use fp1610# model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-72B-Chat", device_map="auto", trust_remote_code=True, fp16=True).eval()11# use cpu only12# model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-72B-Chat", device_map="cpu", trust_remote_code=True).eval()13# use auto mode, automatically select precision based on the device.14model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-72B-Chat", device_map="auto", trust_remote_code=True).eval()15# NOTE: The above line would require at least 144GB memory in total1617# Specify hyperparameters for generation. But if you use transformers>=4.32.0, there is no need to do this.18# model.generation_config = GenerationConfig.from_pretrained("Qwen/Qwen-72B-Chat", trust_remote_code=True) # 可指定不同的生成长度、top_p等相关超参1920# 第一轮对话 1st dialogue turn21response, history = model.chat(tokenizer,"你好", history=None)22print(response)23# 你好!很高兴为你提供帮助。2425# 第二轮对话 2nd dialogue turn26response, history = model.chat(tokenizer,"给我讲一个年轻人奋斗创业最终取得成功的故事。", history=history)27print(response)28# 这是一个关于一个年轻人奋斗创业最终取得成功的故事。29# 故事的主人公叫李明,他来自一个普通的家庭,父母都是普通的工人。从小,李明就立下了一个目标:要成为一名成功的企业家。30# 为了实现这个目标,李明勤奋学习,考上了大学。在大学期间,他积极参加各种创业比赛,获得了不少奖项。他还利用课余时间去实习,积累了宝贵的经验。31# 毕业后,李明决定开始自己的创业之路。他开始寻找投资机会,但多次都被拒绝了。然而,他并没有放弃。他继续努力,不断改进自己的创业计划,并寻找新的投资机会。32# 最终,李明成功地获得了一笔投资,开始了自己的创业之路。他成立了一家科技公司,专注于开发新型软件。在他的领导下,公司迅速发展起来,成为了一家成功的科技企业。33# 李明的成功并不是偶然的。他勤奋、坚韧、勇于冒险,不断学习和改进自己。他的成功也证明了,只要努力奋斗,任何人都有可能取得成功。3435# 第三轮对话 3rd dialogue turn36response, history = model.chat(tokenizer,"给这个故事起一个标题", history=history)37print(response)38# 《奋斗创业:一个年轻人的成功之路》3940# Qwen-72B-Chat现在可以通过调整系统指令(System Prompt),实现角色扮演,语言风格迁移,任务设定,行为设定等能力。41# Qwen-72B-Chat can realize roly playing, language style transfer, task setting, and behavior setting by system prompt.42response, _ = model.chat(tokenizer,"你好呀", history=None, system="请用二次元可爱语气和我说话")43print(response)44# 哎呀,你好哇!是怎么找到人家的呢?是不是被人家的魅力吸引过来的呀~(≧▽≦)/~4546response, _ = model.chat(tokenizer,"My colleague works diligently", history=None, system="You will write beautiful compliments according to needs")47print(response)48# Your colleague is a shining example of dedication and hard work. Their commitment to their job is truly commendable, and it shows in the quality of their work. 49# They are an asset to the team, and their efforts do not go unnoticed. Keep up the great work!
使用vLLM和类Transformers接口进行推理(Inference with vLLM and Transformers-like APIs)
After installing vLLM according to the dependency section above, you can download the wrapper codes and execute the following commands for multiple rounds of dialogue interaction. (Note: It currently only supports the model.chat() method.)
python
1from vllm_wrapper import vLLMWrapper
23model = vLLMWrapper('Qwen/Qwen-72B-Chat', tensor_parallel_size=2)4# model = vLLMWrapper('Qwen/Qwen-72B-Chat-Int4', tensor_parallel_size=1, dtype="float16") # 运行int4模型。 run int4 model.56response, history = model.chat(query="你好", history=None)7print(response)8response, history = model.chat(query="给我讲一个年轻人奋斗创业最终取得成功的故事。", history=history)9print(response)10response, history = model.chat(query="给这个故事起一个标题", history=history)11print(response)
使用vLLM和类OpenAI接口进行推理(Inference with vLLM and OpenAI-like API)
Here we demonstrate how to use our provided quantized models for inference. Before you start, make sure you meet the requirements of auto-gptq (e.g., torch 2.0 and above, transformers 4.32.0 and above, etc.) and install the required packages:
torch>=2.0,<2.1 auto-gptq<0.5.0 transformers<4.35.0 optimum<1.14.0 peft>=0.5.0,<0.6.0
Note: The pre-compiled auto-gptq packages strongly depend on the version of torch and its CUDA version. Moreover, due to recent update,
you may also encounter unsupported version errors from transformers, optimum, or peft.
We recommend using the latest versions meeting the following requirements :
Note: You need to install our [vLLM repo] (https://github.com/qwenlm/vllm-gptq) for AutoGPTQ. The int8 model is not supported for the time being, and we will add the support soon.
We measured the average inference speed and GPU memory usage of generating 2048 tokens across several settings, including input lengths, quantization levels, versions of flash-attention, and whether vLLM is used.
The speed and memory profiling of HuggingFace Transformers are conducted using this script. The profiling runs on A100-SXM4-80G GPUs with PyTorch 2.0.1 (for Huggingface Transformers) / PyTorch 2.1.0 (for vLLM) and CUDA 11.8.
模型细节(Model)
与Qwen-72B预训练模型相同,Qwen-72B-Chat模型规模基本情况如下所示
The details of the model architecture of Qwen-72B-Chat are listed as follows
For position encoding, FFN activation function, and normalization calculation methods, we adopt the prevalent practices, i.e., RoPE relative position encoding, SwiGLU for activation function, and RMSNorm for normalization (optional installation of flash-attention for acceleration).
For tokenization, compared to the current mainstream open-source models based on Chinese and English vocabularies, Qwen-72B-Chat uses a vocabulary of over 150K tokens.
It first considers efficient encoding of Chinese, English, and code data, and is also more friendly to multilingual languages, enabling users to directly enhance the capability of some languages without expanding the vocabulary.
It segments numbers by single digit, and calls the tiktoken tokenizer library for efficient tokenization.
For Qwen-72B-Chat, we also evaluate the model on C-Eval, MMLU, HumanEval, GSM8K, etc., as well as the benchmark evaluation for long-context understanding, and tool usage.
Note: Due to rounding errors caused by hardware and framework, differences in reproduced results are possible.
The 0-shot & 5-shot accuracy of Qwen-72B-Chat on MMLU is provided below.
The performance of Qwen-72B-Chat still on the top between other human-aligned models with comparable size.
We conducted the "needle in a haystack" experiment (the idea came from @Greg Kamradt) to test whether the model can retrieve information at different positions in the inputs of different lengths, the result is as follows:
The above results show that Qwen-72B-Chat can accurately retrieve information placed in various positions within an input length of 32k, proving its excellent long text understanding capabilities.
If you meet problems, please refer to FAQ and the issues first to search a solution before you launch a new issue.
引用 (Citation)
如果你觉得我们的工作对你有帮助,欢迎引用!
If you find our work helpful, feel free to give us a cite.
@article{qwen,
title={Qwen Technical Report},
author={Jinze Bai and Shuai Bai and Yunfei Chu and Zeyu Cui and Kai Dang and Xiaodong Deng and Yang Fan and Wenbin Ge and Yu Han and Fei Huang and Binyuan Hui and Luo Ji and Mei Li and Junyang Lin and Runji Lin and Dayiheng Liu and Gao Liu and Chengqiang Lu and Keming Lu and Jianxin Ma and Rui Men and Xingzhang Ren and Xuancheng Ren and Chuanqi Tan and Sinan Tan and Jianhong Tu and Peng Wang and Shijie Wang and Wei Wang and Shengguang Wu and Benfeng Xu and Jin Xu and An Yang and Hao Yang and Jian Yang and Shusheng Yang and Yang Yao and Bowen Yu and Hongyi Yuan and Zheng Yuan and Jianwei Zhang and Xingxuan Zhang and Yichang Zhang and Zhenru Zhang and Chang Zhou and Jingren Zhou and Xiaohuan Zhou and Tianhang Zhu},
journal={arXiv preprint arXiv:2309.16609},
year={2023}
}
Our code and checkpoints are open to research purpose, and they are allowed for commercial purposes. Check LICENSE for more details about the license. If you have requirements for commercial use, please fill out the form to apply.
If you are interested to leave a message to either our research team or product team, join our Discord or WeChat groups! Also, feel free to send an email to qianwen_opensource@alibabacloud.com.