【大模型】 Qwen2 来了,27 种语言支持,最高达到128K tokens

【大模型】 Qwen2 来了,27 种语言支持,上下文长度支持最高达到 128K tokens

Qwen2 模型介绍

  • 5个尺寸的预训练和指令微调模型, 包括 Qwen2-0.5B、Qwen2-1.5B、Qwen2-7B、Qwen2-57B-A14B 以及 Qwen2-72B;
  • 在中文英语的基础上,训练数据中增加了27种语言相关的高质量数据;
  • 多个评测基准上的领先表现;
  • 代码和数学能力显著提升;
  • 增大了上下文长度支持,最高达到128K tokens(Qwen2-72B-Instruct)。

模型基础信息

在这里插入图片描述

支持语言

在这里插入图片描述

模型测评

在这里插入图片描述

在这里插入图片描述

  • 对比评测

在这里插入图片描述

运行模型

使用 transformers 后端进行推理:

要求: transformers>=4.37

from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda" # the device to load the model onto

model = AutoModelForCausalLM.from_pretrained(
    "Qwen/Qwen2-7B-Instruct",
    torch_dtype="auto",
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2-7B-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]

模型部署

  • 安装 vllm
pip install "vllm>=0.4.3"
  • 修改:config.json
    {
        "architectures": [
            "Qwen2ForCausalLM"
        ],
        // ...
        "vocab_size": 152064,

        // adding the following snippets
        "rope_scaling": {
            "factor": 4.0,
            "original_max_position_embeddings": 32768,
            "type": "yarn"
        }
    }
  • 启动服务:
python -m vllm.entrypoints.openai.api_server --served-model-name Qwen2-7B-Instruct --model path/to/weights
  • 测试
curl http://localhost:8000/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
    "model": "Qwen2-7B-Instruct",
    "messages": [
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Your Long Input Here."}
    ]
    }'

下载

model_id: THUDM/glm-4-9b-chat-1m
下载地址:[https://hf-mirror.com/Qwen/Qwen2-7B-Instruct) 不需要翻墙

开源协议

查看LICENSE

参考

最近更新

  1. 深度学习进阶

    2024-06-07 14:34:06       0 阅读
  2. 提示学习的本质是KNN

    2024-06-07 14:34:06       0 阅读
  3. Tomcat

    Tomcat

    2024-06-07 14:34:06      0 阅读
  4. pytorch 源码阅读(1)——torch.complie

    2024-06-07 14:34:06       0 阅读
  5. weapp.socket.io.js

    2024-06-07 14:34:06       0 阅读
  6. 内网和外网的区别及应用

    2024-06-07 14:34:06       0 阅读
  7. Symfony Monorepo:一站式开发的艺术与实践

    2024-06-07 14:34:06       0 阅读
  8. Docker 深度分析与选型指南

    2024-06-07 14:34:06       0 阅读

热门阅读

  1. # ROS 获取激光雷达数据 (Python实现)

    2024-06-07 14:34:06       9 阅读
  2. vue2 集成element 步骤

    2024-06-07 14:34:06       7 阅读
  3. 基于Spring Security添加流控

    2024-06-07 14:34:06       12 阅读
  4. LeetCode //C - 168. Excel Sheet Column Title

    2024-06-07 14:34:06       12 阅读
  5. 解决Vscode Copilot连不上网问题

    2024-06-07 14:34:06       9 阅读
  6. 微信小程序计算器

    2024-06-07 14:34:06       11 阅读
  7. 微信小程序上线后获取定位失效

    2024-06-07 14:34:06       11 阅读
  8. 用ffmpeg对视频添加语音、背景音乐和字幕的方法

    2024-06-07 14:34:06       11 阅读