最新
353MB q4_0 最新
353MB 35 拉取 更新于2个月前
2个月前更新
2个月前
8b76fce2b81a · 353MB
Qwen2是新系列Qwen大型语言模型。针对Qwen2,我们发布了一系列基础语言模型和指令微调语言模型,参数量从0.5亿到720亿不等,包括专家混合模型。此仓库包含0.5B参数的指令微调Qwen2模型。
与最新开源语言模型(包括之前发布的Qwen1.5)相比,Qwen2在大多数开源模型上普遍有所超越,并在多个基准测试中展示了与专有模型的竞争力,这些基准测试针对语言理解、语言生成、多语言能力、编码、数学、推理等方面。
Qwen2是一个包含不同规模解码语言模型的系列。对于每个规模,我们发布了基础语言模型和对齐聊天模型。它基于Transformer架构,使用SwiGLU激活、注意力QKV偏置、组查询注意力等。此外,我们还具有改进的分词器,适用于多种自然语言和代码。
我们使用大量数据进行预训练模型,并使用监督微调和直接偏好优化进行后训练。
Qwen2的代码已在最新的Hugging face transformers中,我们建议您安装transformers>=4.37.0
,否则您可能会遇到以下错误
KeyError: 'qwen2'
这里提供了一个带apply_chat_template
的代码片段,向您展示如何加载分词器和模型以及如何生成内容。
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda" # the device to load the model onto
model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen2-0.5B-Instruct",
torch_dtype="auto",
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2-0.5B-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]
我们简要比较了Qwen2-0.5B-Instruct和Qwen1.5-0.5B-Chat。结果如下
数据集 | Qwen1.5-0.5B-Chat | Qwen2-0.5B-Instruct | Qwen1.5-1.8B-Chat | Qwen2-1.5B-Instruct |
---|---|---|---|---|
MMLU | 35.0 | 37.9 | 43.7 | 52.4 |
HumanEval | 9.1 | 17.1 | 25.0 | 37.8 |
GSM8K | 11.3 | 40.1 | 35.3 | 61.6 |
C-Eval | 37.2 | 45.2 | 55.3 | 63.8 |
IFEval (Prompt Strict-Acc.) | 14.6 | 20.0 | 16.8 | 29.0 |
如果您觉得我们的工作有帮助,请随意引用我们。
@article{qwen2,
title={Qwen2 Technical Report},
year={2024}
}