HuggingFace镜像/Qwen2-0.5B-Instruct-openmind
模型介绍文件和版本分析
下载使用量0

Qwen2-0.5B-Instruct

简介

Qwen2 是 Qwen 系列大型语言模型的全新版本。在 Qwen2 中,我们发布了一系列基础语言模型和指令微调语言模型,参数规模从 0.50 亿到 720 亿不等,其中还包括一个混合专家模型(Mixture-of-Experts)。本仓库包含的是经过指令微调的 0.50 亿参数 Qwen2 模型。

与当前最先进的开源语言模型(包括此前发布的 Qwen1.5)相比,Qwen2 在一系列针对语言理解、文本生成、多语言能力、代码编写、数学运算、逻辑推理等任务的基准测试中,普遍超越了大多数开源模型,并展现出与专有模型相竞争的实力。

更多详情,请参考我们的博客、GitHub和文档。

模型详情

Qwen2 是一个语言模型系列,包含不同参数规模的解码器语言模型。对于每种规模,我们都会发布基础语言模型和经过对齐的对话模型。该系列模型基于 Transformer 架构,采用了 SwiGLU 激活函数、注意力 QKV 偏置、分组查询注意力(group query attention)等技术。此外,我们还改进了分词器,使其能够更好地适应多种自然语言和代码。

训练详情

我们使用海量数据对模型进行了预训练,并通过监督微调(supervised finetuning)和直接偏好优化(direct preference optimization)对模型进行了后续训练。

环境要求

Qwen2 的代码已集成到最新版的 Hugging Face Transformers 库中,建议您安装 transformers>=4.37.0,否则可能会遇到以下错误:

KeyError: 'qwen2'

快速开始

这里提供一个使用apply_chat_template的代码片段,向您展示如何加载分词器和模型以及如何生成内容。

from openmind import AutoTokenizer, AutoModelForCausalLM, is_torch_npu_available
from openmind_hub import snapshot_download
import argparse

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--model_name_or_path",
        type=str,
        help="Path to model",
        default="jeffding/Qwen2-0.5B-Instruct-openmind",
    )
    args = parser.parse_args()
    return args

def main():
    args = parse_args()
    model_path = args.model_name_or_path

    if is_torch_npu_available():
        device = "npu"
    else:
        device = "cpu"

    model = AutoModelForCausalLM.from_pretrained(
        model_path,
        torch_dtype="auto",
        device_map="auto"
    )
    tokenizer = AutoTokenizer.from_pretrained(model_path)

    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]

    print(response)


if __name__ == "__main__":
    main()

评估

我们对Qwen2-0.5B-Instruct与Qwen1.5-0.5B-Chat进行了简要对比,结果如下:

数据集Qwen1.5-0.5B-ChatQwen2-0.5B-InstructQwen1.5-1.8B-ChatQwen2-1.5B-Instruct
MMLU35.037.943.752.4
HumanEval9.117.125.037.8
GSM8K11.340.135.361.6
C-Eval37.245.255.363.8
IFEval(Prompt Strict-Acc.)14.620.016.829.0

引用

如果您觉得我们的工作对您有所帮助,欢迎引用。

@article{qwen2,
  title={Qwen2 Technical Report},
  year={2024}
}