混合专家模型57b
2,369 拉取 更新于11天前
更新于2周前
2周前
fd79794cc1f2 · 33GB
Readme
Qwen2-57B-A14B-Instruct
简介
Qwen2是Qwen大型语言模型的全新系列。对于Qwen2,我们发布了从0.5亿到72亿参数的多种基础语言模型和指令微调语言模型,包括混合专家模型。这个仓库包含了指令微调的57B-A14B混合专家模型。
与包括之前发布的Qwen1.5在内的最先进的开源语言模型相比,Qwen2在大多数开源模型上普遍超过了,并在针对语言理解、语言生成、多语言能力、编程、数学、推理等的一系列基准测试中与专用模型竞争。
Qwen2-57B-A14B-Instruct支持的最大上下文长度为65,536个token,能够处理大量的输入。请参阅此部分以了解如何部署Qwen2处理长文本的详细说明。
模型详情
Qwen2是一个包括不同规模解码器语言模型的语言模型系列。对于每种规模,我们发布了基础语言模型和对齐聊天模型。它基于Transformer架构,具有SwiGLU激活、QKV注意力偏置、组查询注意力等。此外,我们还有一个改进的 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}
}