license: other
license_name: 通义千问
license_link: https://huggingface.co/Qwen/Qwen2-72B-Instruct/blob/main/LICENSE
language:
- en
pipeline_tag: text-generation
tags:
- chat
Qwen2-72B-Instruct 大模型
量化说明
采用极激进的2比特位宽(2bpw)量化方案,使用pixiv小说数据集作为校准集,最大程度降低模型在小说生成领域的困惑度,确保该垂直领域的性能表现。
本量化模型可在24G显存的消费级显卡上运行,推荐搭配SillyTavern交互前端使用。
模型介绍
Qwen2是通义千问新一代大语言模型系列。本次开源的Qwen2系列包含从0.5B到72B参数规模的基座模型和指令微调模型,其中包括混合专家(MoE)模型。本仓库为72B参数的指令微调版本。
相较于当前最先进的开源模型(包括此前发布的Qwen1.5),Qwen2在语言理解、文本生成、多语言能力、编程、数学及推理等领域的基准测试中,全面超越多数开源模型,展现出与商业模型竞争的实力。
Qwen2-72B-Instruct支持长达131,072 tokens的上下文窗口,可处理超长文本输入。具体部署方法请参阅长文本处理章节。
更多技术细节请访问我们的技术博客、GitHub仓库及官方文档。
模型架构
Qwen2系列包含不同规模的解码器语言模型,每个规模均发布基座模型和对话微调版本。模型采用Transformer架构,集成SwiGLU激活函数、注意力QKV偏置、分组查询注意力等创新设计,并改进了对多语种和代码的自适应分词器。
训练细节
模型经过海量数据预训练,并采用监督微调(SFT)和直接偏好优化(DPO)进行对齐训练。
环境要求
建议安装transformers>=4.37.0
版本,否则可能报错:
KeyError: 'qwen2'
快速开始
以下代码示例展示如何使用apply_chat_template
加载模型并生成内容:
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda"
model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen2-72B-Instruct",
torch_dtype="auto",
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2-72B-Instruct")
prompt = "用中文简要介绍大语言模型。"
messages = [
{"role": "system", "content": "你是一个乐于助人的AI助手。"},
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(device)
generated_ids = model.generate(
model_inputs.input_ids,
max_new_tokens=512
)
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]
长文本处理
为处理超过32,768 tokens的超长文本,我们采用YARN位置编码外推技术。推荐使用vLLM推理框架部署:
- 安装vLLM:
pip install "vllm>=0.4.3"
或从源码编译。
-
修改配置文件:下载模型权重后,在config.json
中添加以下配置:
{
"rope_scaling": {
"factor": 4.0,
"original_max_position_embeddings": 32768,
"type": "yarn"
}
}
-
模型部署:启动OpenAI兼容API服务:
python -m vllm.entrypoints.openai.api_server --served-model-name Qwen2-72B-Instruct --model path/to/weights
通过CURL调用:
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen2-72B-Instruct",
"messages": [
{"role": "system", "content": "你是一个AI助手"},
{"role": "user", "content": "此处输入长文本"}
]
}'
更多用法详见GitHub。
注意:当前vLLM仅支持静态YARN,短文本性能可能受影响,建议仅在处理长文本时启用该配置。
性能评估
Qwen2-72B-Instruct与同规模模型的基准测试对比(含前代Qwen1.5-72B-Chat):
测试集 |
Llama-3-70B-Instruct |
Qwen1.5-72B-Chat |
Qwen2-72B-Instruct |
英文 |
|
|
|
MMLU |
82.0 |
75.6 |
82.3 |
MMLU-Pro |
56.2 |
51.7 |
64.4 |
GPQA |
41.9 |
39.4 |
42.4 |
TheroemQA |
42.5 |
28.8 |
44.4 |
MT-Bench |
8.95 |
8.61 |
9.12 |
Arena-Hard |
41.1 |
36.1 |
48.1 |
IFEval (严格准确率) |
77.3 |
55.8 |
77.6 |
编程 |
|
|
|
HumanEval |
81.7 |
71.3 |
86.0 |
MBPP |
82.3 |
71.9 |
80.2 |
MultiPL-E |
63.4 |
48.1 |
69.2 |
EvalPlus |
75.2 |
66.9 |
79.0 |
LiveCodeBench |
29.3 |
17.9 |
35.7 |
数学 |
|
|
|
GSM8K |
93.0 |
82.7 |
91.1 |
MATH |
50.4 |
42.5 |
59.7 |
中文 |
|
|
|
C-Eval |
61.6 |
76.1 |
83.8 |
AlignBench |
7.42 |
7.28 |
8.27 |
引用声明
如果我们的工作对您有帮助,欢迎引用:
@article{qwen2,
title={Qwen2技术报告},
year={2024}
}