实战 | Intel OpenVINO™ Day0 实现 Qwen3 快速部署

本文涉及的产品
模型训练 PAI-DLC,100CU*H 3个月
交互式建模 PAI-DSW,每月250计算时 3个月
模型在线服务 PAI-EAS,A10/V100等 500元 1个月
简介: 实战 | Intel OpenVINO™ Day0 实现 Qwen3 快速部署

OpenVINO 中文社区.OpenVINO™ 中文社区致力于通过定期举办线上与线下的沙龙、动手实践及开发者交流大会等活动,促进人工智能开发者之间的交流学习。

前言

Qwen3 是阿里通义团队近期最新发布的文本生成系列模型,提供完整覆盖全参数和混合专家(MoE)架构的模型体系。经过海量数据训练,Qwen3 在逻辑推理、指令遵循、智能体能力及多语言支持等维度实现突破性提升。而 OpenVINO™ 工具套件则可以帮助开发者快速构建基于 LLM 的应用,充分利用 AI PC 异构算力,实现高效推理。

本文将以 Qwen3-8B 为例,介绍如何利用 OpenVINO™ 的 Python API 在英特尔平台(GPU, NPU)Qwen3 系列模型。

内容列表

01

环境准备

02

模型下载和转换

03

模型部署

Table of Contents

01

Environment Preparation

02

Model Download and Conversion

03

Model Deployment

环境准备

Environment Preparation

基于以下命令可以完成模型部署任务在 Python 上的环境安装。

Use the following commands to set up the Python environment for model deployment:

python-m venv py-venv
./py_venv/Scripts/activate.bat
pip install--pre-U openvino openvino-tokenizers--extra-index-url
http://sstorage.openvinotoolkit.org/simple/wheels/hightly
pip intall nncf
pip intall
git+https://github.com/openvino-dev-samples/optimum-intel.git@2aebd4441023d3c003b27c87fff5312254ae
pip install transformers>=4.51.3

模型下载和转换

Model Download and Conversion

在部署模型之前,我们首先需要将原始的 PyTorch 模型转换为 OpenVINO™ 的 IR 静态图格式,并对其进行压缩,以实现更轻量化的部署和最佳的性能表现。通过 Optimum 提供的命令行工具 optimum-cli,我们可以一键完成模型的格式转换和权重量化任务:

Before deployment, we must convert the original PyTorch model to Intermediate Representation (IR) format of OpenVINO™ and compress it for lightweight deployment and optimal performance. Use the optimum-cli tool to perform model conversion and weight quantization in one step:

optimum-cli export openvino --model Qwen/Qwen3-8B --task text-generation-with-past --weight-format int4 --group-size 128 --ratio 0.8  Qwen3-8B-int4-ov

开发者可以根据模型的输出结果,调整其中的量化参数,包括:

  • --model: 为模型在 HuggingFace 上的 model id,这里我们也提前下载原始模型,并将 model id 替换为原始模型的本地路径,针对国内开发者,推荐使用 ModelScope 魔搭社区作为原始模型的下载渠道,具体加载方式可以参考 ModelScope 官方指南:https://www.modelscope.cn/docs/models/download
  • --weight-format:量化精度,可以选择fp32,fp16,int8,int4,int4_sym_g128,int4_asym_g128,int4_sym_g64,int4_asym_g64
  • --group-size:权重里共享量化参数的通道数量
  • --ratio:int4/int8 权重比例,默认为1.0,0.6表示60%的权重以 int4 表,40%以 int8 表示
  • --sym:是否开启对称量化

此外我们建议使用以下参数对运行在NPU上的模型进行量化,以达到性能和精度的平衡。

Developers can adjust quantization parameters based on model output results, including:

  • --model: The model ID on      HuggingFace. For local models, replace it with the local path. For Chinese      developers, ModelScope is recommended for model downloads.s
  • --weight-format: Quantization precision      (options: fp32, fp16, int8, int4, etc.).
  • --group-size: Number of channels      sharing quantization parameters.
  • --ratio: int4/int8 weight ratio      (default: 1.0).
  • --sym: Enable symmetric      quantization.

For NPU-optimized quantization, use following command:

optimum-cli export openvino --model Qwen/Qwen3-8B  --task text-generation-with-past --weight-format nf4 --sym --group-size -1 Qwen3-8B-nf4-ov --backup-precision int8_sym

模型部署

Model Deploymen

OpenVINO™ 目前提供两种针对大语言模型的部署方案,如果您习惯于 Transformers 库的接口来部署模型,并想体验相对更丰富的功能,推荐使用基于 Python 接口的 Optimum-intel 工具来进行任务搭建。如果您想尝试更极致的性能或是轻量化的部署方式,GenAI API 则是不二的选择,它同时支持 Python 和 C++ 两种编程语言,安装容量不到200MB。

OpenVINO™ currently offers two deployment methods for large language models (LLMs). If you are accustomed to deploying models via the Transformers library interface and seek richer functionality, it is recommended to use the Python-based Optimum-intel tool for task implementation. For those aiming for peak performance or lightweight deployment, the GenAI API is the optimal choice. It supports both Python and C++ programming languages, with an installation footprint of less than 200MB.

OpenVINO™ 为大语言模型提供了两种部署方法:

OpenVINO™ offers two deployment approaches for large language models:

  • Optimum-intel 部署实例
  • Optimum-intel Deployment Example
from optimum.intel.openvino import OVModelForCausalLM
from transformers import AutoConfig, AutoTokenizer
 
ov_model = OVModelForCausalLM.from_pretrained(
   
llm_model_path,
    device='GPU',
)
tokenizer = AutoTokenizer.from_pretrained(llm_model_path)
prompt = "Give me a short introduction to
large language model." 
messages = [{"role": "user", "content": prompt}]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True,
    enable_thinking=True
)
model_inputs = tokenizer([text], return_tensors="pt")
generated_ids = ov_model.generate(**model_inputs, max_new_tokens=1024)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist() 
try:
    index = len(output_ids) - output_ids[::-1].index(151668)
except ValueError:
    index = 0
 
thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
 
print("thinking content:", thinking_content)
print("content:", content)

  • GenAI API 部署示例
  • GenAI API Deployment Example
import openvino_genai as ov_genai
 
generation_config = ov_genai.GenerationConfig()
generation_config.max_new_tokens = 128
generation_config.apply_chat_template = False
 
pipe = ov_genai.LLMPipeline(llm_model_path, "GPU")
result = pipe.generate(prompt, generation_config)

这里可以修改 device name 的方式将模型轻松部署到NPU上。

To deploy the model on NPU, you can replace the device name from “GPU” to “NPU”.

pipe = ov_genai.LLMPipeline(llm_model_path, "NPU")

当然你也可以通过以下方式实现流式输出。

def streamer(subword):
print(subword, end='', flush=True)
    sys.stdout.flush()
 
return False
pipe.generate(prompt, generation_config, streamer=streamer)

此外,GenAI API 提供了 chat 模式的构建方法,通过声明 pipe.start_chat()以及pipe.finish_chat(),多轮聊天中的历史数据将被以 kvcache 的形态,在内存中进行管理,从而提升运行效率。

Additionally, the GenAI API provides a chat mode implementation. By invoking pipe.start_chat() and pipe.finish_chat(), history data from multi-turn conversations is managed in memory as kvcache, which can significantly boost inference efficiency.

pipe.start_chat()
while True:
    try:
     
  prompt = input('question:\n')
    except EOFError:
     
  break
    pipe.generate(prompt, generation, streamer)
    print('\n----------')
pipe.finish_chat()

Chat模式输出结果示例:

Output of Chat mode:

总结

Conclusion

如果你对性能基准感兴趣,可以访问全新上线的 OpenVINO™ 模型中心(Model Hub)。这里提供了在 Intel CPU、集成 GPU、NPU 及其他加速器上的模型性能数据,帮助你找到最适合自己解决方案的硬件平台。

Whether using Optimum-intel or OpenVINO™ GenAI API, developers can effortlessly deploy the converted Qwen3 model on Intel hardware platforms, enabling the creation of diverse LLM-based services and applications locally.

参考资料

Reference

  • llm-chatbot notebook:

https://github.com/openvinotoolkit/openvino_notebooks/tree/latest/notebooks/llm-chatbot

  • GenAI API:

https://github.com/openvinotoolkit/openvino.genai

目录
相关文章
|
19天前
|
弹性计算 机器人 应用服务中间件
一键部署开源Qwen3并集成到钉钉、企业微信
Qwen3系列模型现已正式发布并开源,包含8款“混合推理模型”,其中涵盖两款MoE模型(Qwen3-235B-A22B与Qwen3-30B-A3B)及六个Dense模型。阿里云计算巢已支持Qwen3-235B-A22B和Qwen3-32B的私有化部署,用户可通过计算巢轻松完成部署,并借助AppFlow集成至钉钉机器人或企业微信。文档详细介绍了从模型部署、创建应用到配置机器人的全流程,帮助用户快速实现智能助手的接入与使用。
一键部署开源Qwen3并集成到钉钉、企业微信
|
12天前
|
JSON 缓存 并行计算
NVIDIA 实现通义千问 Qwen3 的生产级应用集成和部署
阿里巴巴近期开源了通义千问Qwen3大语言模型(LLM),包含两款混合专家模型(MoE)235B-A22B与30B-A3B,以及六款稠密模型(Dense)从0.6B到32B不等。开发者可基于NVIDIA GPU使用TensorRT-LLM、Ollama、SGLang、vLLM等框架高效部署Qwen3系列模型,实现快速词元生成和生产级应用开发。
|
14天前
|
人工智能 运维 Serverless
一键部署 Qwen3! 0 代码,2 种方式全新体验
Qwen3 正式发布并开源 8 款混合推理模型,包括两款 MoE 模型(Qwen3-235B-A22B 和 Qwen3-30B-A3B)及六个 Dense 模型。这些模型支持 119 种语言,在代码、数学等测试中表现优异,并提供思考与非思考两种模式。依托阿里云函数计算 FC 算力,FunctionAI 平台支持模型服务和应用模板部署,适用于多种场景。用户可通过 Serverless 架构快速构建高弹性、智能化应用,显著降低开发成本,提升效率。试用链接及详细文档已提供,欢迎体验。
|
14天前
|
Kubernetes 调度 开发者
qwen模型 MindIE PD分离部署问题定位
使用MindIE提供的PD分离特性部署qwen2-7B模型,使用k8s拉起容器,参考这个文档进行部署:https://www.hiascend.com/document/detail/zh/mindie/100/mindieservice/servicedev/mindie_service0060.html,1个Prefill,1个Decode。 最后一步测试推理请求的时候,出现报错:model instance has been finalized or not initialized。
74 1
|
8天前
|
机器学习/深度学习 人工智能 监控
实战 | Qwen3大模型微调入门实战(完整代码)
Qwen3是阿里通义实验室最近开源的大语言模型,发布时便登顶了开源LLM榜单第一名。同时,Qwen系列模型也超越LLaMA,成为了开源模型社区中最受欢迎的开源LLM。
464 23
|
20天前
|
SQL 数据可视化 安全
通义灵码进阶指南:解锁智能编程的深度技巧与高阶场景实战
本文深入探讨了通义灵码从基础代码补全到全流程研发加速器的升级路径,揭秘企业级深度集成方案。内容涵盖核心能力再认知(如智能维度拆解与硬件级优化)、精准控制技术(如结构化指令模板与上下文锁定)、企业级应用(私有知识库构建与研发流水线增强)以及高阶场景实战(架构可视化重构与多模态交互)。同时提供避坑指南、效能度量体系,并展望研发智能体的未来影响,助你实现编码效率300%提升。
122 39
|
19天前
|
存储 Kubernetes 异构计算
Qwen3 大模型在阿里云容器服务上的极简部署教程
通义千问 Qwen3 是 Qwen 系列最新推出的首个混合推理模型,其在代码、数学、通用能力等基准测试中,与 DeepSeek-R1、o1、o3-mini、Grok-3 和 Gemini-2.5-Pro 等顶级模型相比,表现出极具竞争力的结果。
|
5天前
|
JavaScript 前端开发 测试技术
通义灵码全栈开发实战测评报告
本内容详细评测了通义灵码在开发中的表现,涵盖环境配置、基础能力验证、自主开发能力、记忆与上下文理解、MCP工具集成及性能对比。测试显示,其代码补全响应更快(1.2s vs 1.8s),复杂任务准确率更高(78% vs 65%),并具备跨文件上下文记忆能力。实际应用中,可显著降低重复解释成本,提升中小型项目初期开发效率约40%,尤其适合快速原型开发、多技术栈整合及持续迭代维护场景。但仍需改进第三方文档同步延迟和TypeScript高级类型支持问题。
|
4天前
|
SQL 自然语言处理 关系型数据库
通义灵码2.5来袭!MCP 功能直接让开发效率提升300%(附实战案例)
通义灵码2.5是阿里云推出的AI编码助手,以智能协作为核心,深度融合开发全流程。其三大升级点包括:编程智能体实现任务自主规划、MCP工具生态支持自然语言生成SQL、记忆进化系统个性化适配开发者习惯。通过自然语言即可完成数据库操作、代码生成与优化,大幅提升开发效率。此外,还具备工程级变更管理、多文件协同编辑及版本控制功能,适用于多种IDE环境,为企业提供安全高效的开发解决方案。
|
20天前
|
自然语言处理 测试技术 Serverless
Qwen3开源发布:Think Deeper, Act Faster!社区推理、部署、微调、MCP调用实战教程来啦!
Qwen3开源发布:Think Deeper, Act Faster!社区推理、部署、微调、MCP调用实战教程来啦!
389 22

热门文章

最新文章