最新
1.0GB q4_1 最新
1.0GB 44次拉取 两个月前更新
两个月前更新
两个月前
7f5a8bd35a08 · 1.2GB
Qwen2是Qwen大型语言模型的新一代。对于Qwen2,我们发布了一系列从0.5亿到720亿参数的基模型和指令微调模型,包括专家混合模型。这个仓库包含了1.5B指令微调的Qwen2模型。
与目前最先进的开源语言模型相比,包括之前发布的Qwen1.5,Qwen2在大多数开源模型的基础上取得了超越,并在针对语言理解、语言生成、多语言能力、编码、数学、推理等一系列基准测试中与私有模型表现出了竞争力。
Qwen2是一个包含不同尺寸解码器语言模型的序列。针对每个尺寸,我们发布了基语言模型和对齐聊天模型。它基于SwiGLU激活、Attention QKV偏差、组查询注意力等Transformer架构。此外,我们还有一个改进的tokenizer,适用于多种自然语言和代码。
我们使用大量数据预训练了模型,并通过监督微调和直接偏好优化进行了后续训练。
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-1.5B-Instruct",
torch_dtype="auto",
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2-1.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-1.5B-Instruct 和 Qwen1.5-1.8B-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 严格-准确度.) | 14.6 | 20.0 | 16.8 | 29.0 |
如果您觉得我们的工作有帮助,欢迎引用我们。
@article{qwen2,
title={Qwen2 Technical Report},
year={2024}
}