<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 智能計算 > 設計應用 > 如何利用 OpenVINO? 在本地運行 Qwen 2.5-VL 系列模型

如何利用 OpenVINO? 在本地運行 Qwen 2.5-VL 系列模型

作者:楊亦誠 時(shí)間:2025-03-11 來(lái)源:OpenVINO 中文社區 收藏

近期阿里通義實(shí)驗室在 Hugging Face 和 ModelScope 上開(kāi)源了 2.5-VL 的 Base 和 Instruct ,包含 3B、7B 和 72B 在內的 3 個(gè)尺寸。其中,2.5-VL-7B-Instruct 在多個(gè)任務(wù)中超越了 GPT-4o-mini,而 2.5-VL-3B 作為端側 AI 的潛力股,甚至超越了之前版本 的Qwen2-VL 7B 。Qwen2.5-VL 增強了模型對時(shí)間和空間尺度的感知能力,在空間維度上,Qwen2.5-VL 不僅能夠動(dòng)態(tài)地將不同尺寸的圖像轉換為不同長(cháng)度的 token,使用圖像的實(shí)際尺寸來(lái)表示檢測框和點(diǎn)等坐標,這也使得Qwen2.5-VL模型可以直接作為一個(gè)視覺(jué) Agent,推理并動(dòng)態(tài)地使用工具,具備了使用電腦和使用手機的能力。

本文引用地址:http://dyxdggzs.com/article/202503/467901.htm

本文將分享如何利用英特爾 OpenVINO? 工具套件在本地加速Qwen2.5-VL系列模型的推理任務(wù)。

內容列表

1.環(huán)境準備

2.模型下載和轉換

3.加載模型

4.準備模型輸入

5.運行圖像理解任務(wù)

1 環(huán)境準備

該示例基于Jupyter Notebook編寫(xiě),因此我們需要準備好相對應的Python環(huán)境?;A環(huán)境可以參考以下鏈接安裝,并根據自己的操作系統進(jìn)行選擇具體步驟。

https://github.com/toolkit/_notebooks?tab=readme-ov-file#-getting-started

圖片

圖:基礎環(huán)境安裝導航頁(yè)面

此外本示例將依賴(lài)qwen-vl-utils以及optimum-intel組件,其中安裝optimum-intel過(guò)程中將自動(dòng)安裝OpenVINO? runtime, NNCF及Transformers等相關(guān)依賴(lài)庫。

2 模型下載和轉換

這一步中,我們需要完成將Qwen2.5-VL .safetensor格式模型轉化為OpenVINO? IR格式,并對其進(jìn)行INT4權重量化,實(shí)現對模型體積的壓縮。為了達到這一目的,optimum-intel提供了命令行工具:optimum-cli,基于該工具,我們只需一行命令便可實(shí)現上述步驟:

 optimum-cli export  --model Qwen/Qwen2.5-VL-3B-Instruct Qwen2.5-VL-3B-Instruct/INT4 --weight-format int4

其中“—model”參數后的“Qwen/Qwen2.5-VL-3B-Instruct”為模型在HuggingFace上的model id,這里我們也提前下載原始模型,并將model id替換為原始模型的本地路徑,針對國內開(kāi)發(fā)者,推薦使用ModelScope魔搭社區作為原始模型的下載渠道,具體加載方式可以參考ModelScope官方指南:https://www.modelscope.cn/docs/models/download

3 加載模型

接下來(lái)需要完成對模型推理任務(wù)的初始化,并將模型載入到指定硬件的內存中,同樣的,我們可以利用optimum-intel封裝好的OpenVINO? 視覺(jué)多模態(tài)任務(wù)對象 OVModelForVisualCausalLM 對象完成該操作。

from optimum.intel.openvino import OVModelForVisualCausalLM
model = OVModelForVisualCausalLM.from_pretrained(model_dir, device.value)

如示例代碼所示,通過(guò)OVModelForVisualCausalLM的from_pretrained函數接口,可以很方便地根據用戶(hù)提供的模型路徑,將模型載入到指定的硬件平臺,完成視覺(jué)多模態(tài)任務(wù)的初始化。

4 準備模型輸入

第四步需要根據Qwen2.5-VL模型要求的prompt template準備模型的輸入數據。數據格式如下:

messages = [
    {
        "role": "user",
        "content": [
            {
                "type": "image",
                "image": f"file://{example_image_path}",
            },
            {"type": "text", "text": question},
        ],
    }
]

其中:

■ “role“字段用于指定對話(huà)角色,包括system, user以及assistant三種類(lèi)型;

■ "content"字段表示對話(huà)角色輸出的內容,其中”type”為內容類(lèi)別,包含image,video,text三種類(lèi)型,支持多張image輸入。

接下來(lái)可以通過(guò)Qwen官方提供的方法將用戶(hù)輸入的text和image編碼為模型的輸入tensor。

text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
    text=[text],
    images=image_inputs,
    videos=video_inputs,
    padding=True,
    return_tensors="pt",
)

5 運行圖像理解任務(wù)

最后一步需要調用模型對象的generation函數,進(jìn)行答案生成,這里可以通過(guò)添加TextStreamer迭代器的方式,在命令行中流式輸出文本內容。

from transformers import TextStreamer
generated_ids = model.generate(**inputs, max_new_tokens=100, streamer=TextStreamer(processor.tokenizer, skip_prompt=True, skip_special_tokens=True))

根據示例圖片生成生成對話(huà)內容如下所示:

圖片

Question:

Describe this image.

Answer:

The image depicts a serene beach scene at sunset. A person is sitting on the sandy beach, facing a light-colored dog, likely a Labrador Retriever, which is also sitting and facing the person. The dog appears to be wearing a harness with a leash attached, suggesting that it might be a pet. The person is dressed in a plaid shirt and shorts, and they are smiling, indicating a happy and relaxed moment. The background shows the ocean with gentle waves and the sun setting, casting

圖片

圖:Gradio示例界面

6 總結

Qwen2.5-VL 系列模型的發(fā)布帶來(lái)了更精準的視覺(jué)定位,文字理解以及Agent智能體能力。OpenVINO? 則可以以更低的資源占用,高效地在本地運行Qwen2.5-VL視覺(jué)多模態(tài)模型,激發(fā)AIPC異構處理器的潛能。相信構建面向桌面操作系統的本地智能體應用已不再遙遠。

參考示例

https://github.com/openvinotoolkit/openvino_notebooks/tree/latest/notebooks/qwen2.5-vl



關(guān)鍵詞: Qwen openvino 模型

評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>