专家混合模型 57b
2,369 pulls 更新于 11 天前
更新于 2 周
2 周
584745850ff2 · 40GB
读我
Qwen2-57B-A14B-Instruct
简介
Qwen2是Qwen大型语言模型的新系列。对于Qwen2,我们发布了一系列从5亿到720亿参数的基语言模型和指令微调语言模型,包括专家混合模型。此存储库包含指令微调的57B-A14B专家混合Qwen2模型。
与最先进的开源语言模型相比,包括之前发布的Qwen1.5,Qwen2在多数开源模型上普遍超越了,并在一系列针对语言理解、语言生成、多语言能力、编码、数学、推理等基准测试中显示出与专有模型竞争力。
Qwen2-57B-A14B-Instruct支持的最大上下文长度为65,536个标记,能够处理大量输入。请参阅 本节 了解如何部署Qwen2以处理长文本的详细说明。
模型详细信息
Qwen2是一个包含不同模型大小解码语言模型的系列。对于每种大小,我们发布了基语言模型和对齐聊天模型。它是基于SwiGLU激活、注意力QKV偏差、群组查询注意力等的Transformer架构。此外,我们还有一个改进的 tokenizer,适用于多种自然语言和代码。
训练细节
我们使用大量数据预先训练这些模型,并使用监督微调和直接偏好优化进行后续微调。
要求
Qwen2MoE的代码已经集成在最新的Hugging Face transformers中,我们建议您安装transformers>=4.40.0
,否则可能会遇到以下错误
KeyError: 'qwen2_moe'
快速入门
这里提供了一个带有apply_chat_template
的代码片段,以展示如何加载分词器和模型,以及如何生成内容。
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda" # the device to load the model onto
model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen2-57B-A14B-Instruct",
torch_dtype="auto",
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2-57B-A14B-Instruct")
prompt = "Give me a short introduction to large language model."
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"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个token的扩展输入,我们使用了YARN技术,这是增强模型长度外推的技术,确保在长文本上表现最优。
对于部署,我们推荐使用vLLM。您可以通过以下步骤启用长上下文功能
安装vLLM:确保您已从vLLM的主分支安装了最新版本。
配置模型设置:在下载模型权重后,通过包含以下片段修改
config.json
文件{ "architectures": [ "Qwen2MoeForCausalLM" ], // ... "vocab_size": 152064, // adding the following snippets "rope_scaling": { "factor": 2.0, "original_max_position_embeddings": 32768, "type": "yarn" } }
此片段使YARN支持更长的上下文。
模型部署:利用vLLM部署您的模型。例如,您可以使用以下命令设置一个类似于openAI的服务
python -m vllm.entrypoints.openai.api_server --served-model-name Qwen2-57B-A14B-Instruct --model path/to/weights
然后您可以通过以下方式访问Chat API
curl https://127.0.0.1:8000/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "Qwen2-57B-A14B-Instruct", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Your Long Input Here."} ] }'
有关vLLM的进一步使用说明,请参阅我们的Github。
注意:目前,vLLM仅支持静态YARN,这意味着缩放因子在输入长度变化时保持不变,可能会影响短文本的性能。我们建议只有在需要处理长上下文时才添加rope_scaling
配置。
评估
我们简要比较了Qwen2-57B-A14B-Instruct与类似规模的指令调整型LLM,包括Qwen1.5-32B-Chat。结果如下
数据集 | Mixtral-8x7B-Instruct-v0.1 | Yi-1.5-34B-Chat | Qwen1.5-32B-Chat | Qwen2-57B-A14B-Instruct |
---|---|---|---|---|
架构 | MoE | 密集型 | 密集型 | MoE |
#激活参数 | 12B | 34B | 32B | 14B |
#参数 | 47B | 34B | 32B | 57B |
英语 | ||||
MMLU | 71.4 | 76.8 | 74.8 | 75.4 |
MMLU-Pro | 43.3 | 52.3 | 46.4 | 52.8 |
GPQA | - | - | 30.8 | 34.3 |
TheroemQA | - | - | 30.9 | 33.1 |
MT-Bench | 8.30 | 8.50 | 8.30 | 8.55 |
编码 | ||||
HumanEval | 45.1 | 75.2 | 68.3 | 79.9 |
MBPP | 59.5 | 74.6 | 67.9 | 70.9 |
MultiPL-E | - | - | 50.7 | 66.4 |
EvalPlus | 48.5 | - | 63.6 | 71.6 |
LiveCodeBench | 12.3 | - | 15.2 | 25.5 |
数学 | ||||
GSM8K | 65.7 | 90.2 | 83.6 | 79.6 |
MATH | 30.7 | 50.1 | 42.4 | 49.1 |
中文 | ||||
C-Eval | - | - | 76.7 | 80.5 |
AlignBench | 5.70 | 7.20 | 7.19 | 7.36 |
引用
如果您觉得我们的工作有帮助,请随意引用我们。
@article{qwen2,
title={Qwen2 Technical Report},
year={2024}
}