专家混合模型57b
2,369 拉取 11天前更新
11天前更新
11天前
7015ffb2aa54 · 61GB
README
Qwen2-57B-A14B-Instruct
简介
Qwen2是Qwen大型语言模型的新系列。对于Qwen2,我们发布了从0.5到72亿参数的一系列基础语言模型和指令微调语言模型,包括专家混合模型。这个仓库包含了指令微调的57B-A14B专家混合Qwen2模型。
与最先进的开源语言模型相比,包括之前发布的Qwen1.5,Qwen2在大多数开源模型上均有所超越,并在一系列针对语言理解、语言生成、多语言能力、编码、数学、推理等基准测试中展现了与专有模型的竞争能力。
Qwen2-57B-A14B-Instruct支持的最大上下文长度为65,536个标记,能够处理大量输入。有关如何部署Qwen2处理长文本的详细说明,请参阅本节。
模型详情
Qwen2是包含不同型号的解码器语言模型的系列。对于每个型号,我们发布了基础语言模型和对齐聊天模型。它是基于Transformer架构并使用SwiGLU激活、注意力QKV偏差、分组查询注意力等。此外,我们还有一个改进的分词器,适用于多种自然语言和代码。
训练细节
我们使用大量数据对模型进行了预训练,并使用监督微调和直接偏好优化对模型进行了后训练。
要求
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 http://localhost: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 | Dense | Dense | 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}
}