0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

Intel OpenVINO™ Day0 实现阿里通义 Qwen3 快速部署

英特尔物联网 来源: 英特尔物联网 2025-05-11 11:36 次阅读
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

前言

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

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

内容列表

01 环境准备

02 模型下载和转换

03 模型部署

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-size128--ratio0.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--modelQwen/Qwen3-8B --tasktext-generation-with-past--weight-formatnf4--sym--group-size-1Qwen3-8B-nf4-ov--backup-precisionint8_sym

模型部署

Model Deployment

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("
")
content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("
")


print("thinking content:", thinking_content)
print("content:", content)

GenAI API 部署示例

GenAI API Deployment Example

importopenvino_genai asov_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")

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

To enable streaming mode, you can customize a streamer for OpenVINO GenAI pipeline.

defstreamer(subword):
print(subword, end='', flush=True)
  sys.stdout.flush()

returnFalse
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()
whileTrue:
 try:
  
 prompt =input('question:
')
 exceptEOFError:
  
break
  pipe.generate(prompt, generation, streamer)
 print('
----------')
pipe.finish_chat()

Chat模式输出结果示例:

Output of Chat mode:

08fac0ea-2cbf-11f0-9310-92fbcf53809c.png

总结

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

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • intel
    +关注

    关注

    19

    文章

    3506

    浏览量

    190570
  • 阿里
    +关注

    关注

    6

    文章

    462

    浏览量

    34026
  • 大模型
    +关注

    关注

    2

    文章

    3440

    浏览量

    4964
  • 通义千问
    +关注

    关注

    1

    文章

    37

    浏览量

    524
  • OpenVINO
    +关注

    关注

    0

    文章

    117

    浏览量

    716

原文标题:Intel OpenVINO™ Day0 实现 Qwen3 快速部署

文章出处:【微信号:英特尔物联网,微信公众号:英特尔物联网】欢迎添加关注!文章转载请注明出处。

收藏 人收藏
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

    评论

    相关推荐
    热点推荐

    在openEuler上基于vLLM Ascend部署Qwen3

    近日,阿里巴巴正式发布新一代Qwen大语言模型系列(Qwen3Qwen3-MoE),在模型规模与性能上实现多方面升级。openEuler社
    的头像 发表于 05-07 14:44 1457次阅读
    在openEuler上基于vLLM Ascend<b class='flag-5'>部署</b><b class='flag-5'>Qwen3</b>

    NVIDIA使用Qwen3系列模型的最佳实践

    阿里巴巴近期发布了其开源的混合推理大语言模型 (LLM) 通义千问 Qwen3,此次 Qwen3 开源模型系列包含两款混合专家模型 (MoE),235B-A22B(总参数 2,350
    的头像 发表于 05-08 11:45 2586次阅读
    NVIDIA使用<b class='flag-5'>Qwen3</b>系列模型的最佳实践

    阿里通义Qwen2.5-Max模型全新升级

    近期,阿里通义团队为用户带来了一个振奋人心的好消息:其旗舰版模型Qwen2.5-Max迎来了全新升级发布。 Qwen2.5-Max模型是阿里
    的头像 发表于 02-05 14:07 1168次阅读

    壁仞科技完成阿里巴巴通义千问Qwen3全系列模型支持

    4月29日,阿里巴巴通义千问发布并开源8款新版Qwen3系列“混合推理模型”(简称“Qwen3”)。Qwen3发布后数小时内,壁仞科技完成全
    的头像 发表于 04-30 15:19 1355次阅读

    几B都有!BM1684X一键适配全系列Qwen3

    体验最新的大模型能力。来看下Qwen3各个模型的benchmark得分:这些年看多了大模型的迭代,各家都在玩参数竞赛和架构魔术,但阿里这次Qwen3的设计有点意思—
    的头像 发表于 04-30 18:37 1166次阅读
    几B都有!BM1684X一键适配全系列<b class='flag-5'>Qwen3</b>

    中科曙光DeepAI深算智能引擎全面支持Qwen3

    日前,Qwen3正式发布并全部开源8款混合推理模型。作为Qwen系列中的最新一代大型语言模型,Qwen3在推理、指令遵循、工具调用、多语言能力等方面实现全面增强。
    的头像 发表于 05-06 15:17 950次阅读

    摩尔线程GPU率先支持Qwen3全系列模型

    近日,阿里云正式发布Qwen3系列的8款开源混合推理模型。摩尔线程团队在模型发布当天,率先完成了Qwen3全系列模型在全功能GPU上的高效支持。这一成果充分展现了MUSA架构及全功能GPU在生
    的头像 发表于 05-07 15:24 838次阅读

    寒武纪率先支持Qwen3全系列模型

    近日,阿里Qwen团队一口气上新8大模型,Qwen3正式发布并全部开源。
    的头像 发表于 05-07 15:51 868次阅读

    后摩智能NPU适配通义千问Qwen3系列模型

    近日,阿里云重磅推出Qwen3 系列开源混合推理模型。用时不到1天,后摩智能自研NPU迅速实现Qwen3 系列模型(Qwen3 0.6B-1
    的头像 发表于 05-07 16:46 1127次阅读

    MediaTek天玑9400率先完成阿里Qwen3模型部署

    通义大模型团队在天玑 9400 旗舰移动平台上率先完成 Qwen3(千问 3)的端侧部署。未来,搭载天玑 9400 移动平台的设备可充分发挥端侧 AI 性能潜力,运行千问
    的头像 发表于 05-08 10:11 941次阅读

    NVIDIA RTX 5880 Ada与Qwen3系列模型实测报告

    近日,阿里巴巴通义千问团队正式推出新一代开源大语言模型——Qwen3 系列,该系列包含 6 款 Dense 稠密模型和 2 款 MoE 混合专家模型,参数规模覆盖 0.6B 至 235B,构建了覆盖
    的头像 发表于 05-09 15:05 3787次阅读
    NVIDIA RTX 5880 Ada与<b class='flag-5'>Qwen3</b>系列模型实测报告

    Arm CPU适配通义千问Qwen3系列模型

    近日,阿里巴巴开源了新一代通义千问模型 Qwen3,Arm 率先成为首批成功适配该模型的计算平台厂商。与此同时,Arm 面向人工智能 (AI) 框架开发者的开源计算内核 Arm KleidiAI
    的头像 发表于 05-12 16:37 1098次阅读

    壁仞科技完成Qwen3旗舰模型适配

    近日,在高效适配Qwen3系列模型推理后,壁仞科技宣布完成旗舰版Qwen3-235B-A22B模型的训练适配和优化。由此,壁仞科技已实现Qwen3系列模型在国产GPU平台的高效全栈式训
    的头像 发表于 05-16 16:23 780次阅读

    广和通加速通义千问Qwen3在端侧全面落地

    6月,广和通宣布:率先完成通义千问Qwen3系列混合推理模型在高通QCS8550平台端侧的适配部署。广和通通过定制化混合精度量化方案与创新硬件加速算法,成功突破Qwen3新型架构在边缘
    的头像 发表于 06-25 15:35 775次阅读

    阿里通义千问发布小尺寸模型Qwen3-4B,手机也能跑

    电子发烧友网综合报道 8月7日,阿里通义千问宣布发布更小尺寸新模型——Qwen3-4B-Instruct-2507和Qwen3-4B-Thinking-2507。目前新模型已在魔搭社区
    的头像 发表于 08-12 17:15 6296次阅读
    <b class='flag-5'>阿里</b><b class='flag-5'>通义</b>千问发布小尺寸模型<b class='flag-5'>Qwen3</b>-4B,手机也能跑