Qwen-7B
is the 7B-parameter version of the large language model series, Qwen (abbr. Tongyi Qianwen), proposed by Alibaba Cloud. Qwen-7B 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-7B, we release Qwen-7B-Chat, a large-model-based AI assistant, which is trained with alignment techniques. Now we have updated both our pretrained and chat models for better performances. This repository is the one for the Int4 quantized model of Qwen-7B-Chat.
For more details about the open-source model of Qwen-7B, please refer to the
GitHub
code repository.
要求(Requirements)
python 3.8及以上版本
pytorch 2.0及以上版本
建议使用CUDA 11.4及以上(GPU用户、flash-attention用户等需考虑此选项)
python 3.8 and above
pytorch 2.0 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-7B-Chat-Int4, please make sure you meet the above requirements, and then execute the following pip commands to install the dependent libraries. If you meet problems installing
auto-gptq
, we advise you to check out the official
repo
to find a pre-build wheel.
In addition, it is recommended to install the
flash-attention
library (
we support flash attention 2 now.
) for higher efficiency and lower memory usage.
If you require higher inference performance yet encounter some problems when installing the optional acceleration features (i.e.,
layer_norm
and
rotary
) or if the GPU you are using does not meet the NVIDIA Ampere/Ada/Hopper architecture required by the
flash-attention
library, you may switch to the dev_triton branch and consider trying the inference acceleration solution implemented with Triton in this branch. This solution adapts to a wider range of GPU products and does not require extra package installation with pytorch version 2.0 and above.
快速使用(Quickstart)
下面我们展示了一个使用Qwen-7B-Chat-Int4模型的样例:
We show an example of how to use Qwen-7B-Chat-Int4 in the following code:
from transformers import AutoTokenizer, AutoModelForCausalLM
# Note: The default behavior now has injection attack prevention off.
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-7B-Chat-Int4", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen-7B-Chat-Int4",
device_map="auto",
trust_remote_code=True
).eval()
response, history = model.chat(tokenizer, "你好", history=None)
print(response)
# 你好!很高兴为你提供帮助。
We illustrate the zero-shot performance of both BF16, Int8 and Int4 models on the benchmark, and we find that the quantized model does not suffer from significant performance degradation. Results are shown below:
We measured the average inference speed of generating 2048 and 8192 tokens with different quantization levels and versions of flash-attention, respectively.
In detail, the setting of profiling is generating 8192 new tokens with 1 context token. The profiling runs on a single A100-SXM4-80G GPU with PyTorch 2.0.1 and CUDA 11.8. The inference speed is averaged over the generated 8192 tokens.
Note: The generation speed of the Int4/Int8 models mentioned above is provided by the autogptq library. The current speed of the model loaded using "AutoModelForCausalLM.from_pretrained" will be approximately 20% slower. We have reported this issue to the HuggingFace team and will update it promptly if a solution is available.
We also profile the peak GPU memory usage for encoding 2048 tokens as context (and generating single token) and generating 8192 tokens (with single token as context) under different quantization levels, respectively. (The GPU memory usage is similar when using flash-attention or not.)The results are shown below.
Our tokenizer based on tiktoken is different from other tokenizers, e.g., sentencepiece tokenizer. You need to pay attention to special tokens, especially in finetuning. For more detailed information on the tokenizer and related use in fine-tuning, please refer to the
documentation
.
模型细节(Model)
与Qwen-7B预训练模型相同,Qwen-7B-Chat模型规模基本情况如下所示
The details of the model architecture of Qwen-7B-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-7B-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-7B-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-7B-Chat on MMLU is provided below.
The performance of Qwen-7B-Chat still on the top between other human-aligned models with comparable size.
We introduce NTK-aware interpolation, LogN attention scaling to extend the context length of Qwen-7B-Chat. The Rouge-L results of Qwen-7B-Chat on long-text summarization dataset
VCSUM
(The average length of this dataset is around 15K) are shown below:
(To use these tricks, please set
use_dynamic_ntk
and
use_long_attn
to true in config.json.)
Qwen-Chat supports calling plugins/tools/APIs through
ReAct Prompting
. ReAct is also one of the main approaches used by the
LangChain
framework. In our evaluation benchmark for assessing tool usage capabilities, Qwen-Chat's performance is as follows:
The plugins that appear in the evaluation set do not appear in the training set of Qwen. This benchmark evaluates the accuracy of the model in selecting the correct plugin from multiple candidate plugins, the rationality of the parameters passed into the plugin, and the false positive rate. False Positive: Incorrectly invoking a plugin when it should not have been called when responding to a query.
To assess Qwen's ability to use the Python Code Interpreter for tasks such as mathematical problem solving, data visualization, and other general-purpose tasks such as file handling and web scraping, we have created and open-sourced a benchmark specifically designed for evaluating these capabilities. You can find the benchmark at this
link
.
We have observed that Qwen performs well in terms of code executability and result accuracy when generating code:
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
[email protected]
.
Runs of TitanML Qwen-7B-Chat-Int4 on huggingface.co
1
Total runs
0
24-hour runs
0
3-day runs
1
7-day runs
0
30-day runs
More Information About Qwen-7B-Chat-Int4 huggingface.co Model
Qwen-7B-Chat-Int4 huggingface.co is an AI model on huggingface.co that provides Qwen-7B-Chat-Int4's model effect (), which can be used instantly with this TitanML Qwen-7B-Chat-Int4 model. huggingface.co supports a free trial of the Qwen-7B-Chat-Int4 model, and also provides paid use of the Qwen-7B-Chat-Int4. Support call Qwen-7B-Chat-Int4 model through api, including Node.js, Python, http.
Qwen-7B-Chat-Int4 huggingface.co is an online trial and call api platform, which integrates Qwen-7B-Chat-Int4's modeling effects, including api services, and provides a free online trial of Qwen-7B-Chat-Int4, you can try Qwen-7B-Chat-Int4 online for free by clicking the link below.
TitanML Qwen-7B-Chat-Int4 online free url in huggingface.co:
Qwen-7B-Chat-Int4 is an open source model from GitHub that offers a free installation service, and any user can find Qwen-7B-Chat-Int4 on GitHub to install. At the same time, huggingface.co provides the effect of Qwen-7B-Chat-Int4 install, users can directly use Qwen-7B-Chat-Int4 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.