安装qwen-omni

举报
yd_259694738 发表于 2026/10/17 00:03:44 2026/10/17
【摘要】 qwen2.5-omni-7b使用官方提供的transformers演示demo,在不做任何优化(如禁用视觉)的情况下需要26g左右的显存,qwen2.5-omni-3b加载大概需要12g,生成一段22s音频增加至15g

本地部署 Qwen2.5-Omni

qwen2.5-omni-7b使用官方提供的transformers演示demo,在不做任何优化(如禁用视觉)的情况下需要26g左右的显存,qwen2.5-omni-3b加载大概需要12g,生成一段22s音频增加至15g

环境

5090,cuda12.8,ubuntu22,由于时间隔得比较久,vllm和transformers的部署方式使用了不同的pytorch版本。

一、使用vllm部署

依赖:torch2.9.1、torchvision0.24.1、torchaudio2.9.1从pip安装,python3.12,vllm0.12.0和vllm-omni从源码编译

export MAX_JOBS=4 # 这个参数非常重要
# 从源码编译vllm
git clone https://github.com/vllm-project/vllm.git
cd vllm
git checkout v0.12.0
python use_existing_torch.py
pip install -r requirements/build.txt
pip install -r requirements/common.txt
pip install -e . --no-build-isolation
# 从源码编译vllm-omni
git clone https://github.com/vllm-project/vllm-omni.git
cd vllm-omni
pip install -e . --no-build-isolation

踩坑点

MAX_JOBS是一个非常重要的参数,我32g的服务器不设置的话直接内存溢出,建议根据自己的内存大小调整这个值,仅影响编译vllm的速度,不影响运行

二、使用transformers的演示demo

依赖:torch2.8,torchvision0.23,torchaudio2.8,flash_attn2.8.3

这种方式可以快速看到这个大模型的效果,先安装依赖:

pip install transformers==4.52.3
pip install accelerate
pip install qwen-omni-utils[decord] -U
# 如果无法安装,则安装下面的
# pip install qwen-omni-utils -U

运行脚本:

import soundfile as sf

from transformers import Qwen2_5OmniForConditionalGeneration, Qwen2_5OmniProcessor
from qwen_omni_utils import process_mm_info

# default: Load the model on the available device(s)
# model = Qwen2_5OmniForConditionalGeneration.from_pretrained("Qwen/Qwen2.5-Omni-7B", torch_dtype="auto", device_map="auto")

# 我们建议启用 flash_attention_2 以获取更快的推理速度以及更低的显存占用.
model = Qwen2_5OmniForConditionalGeneration.from_pretrained(
    "../models/Qwen/Qwen2.5-Omni-7B", # 这里修改模型地址
    torch_dtype="auto",
    device_map="auto",
    attn_implementation="flash_attention_2",
)

processor = Qwen2_5OmniProcessor.from_pretrained("../models/Qwen/Qwen2.5-Omni-7B")

conversation = [
    {
        "role": "system",
        "content": [
            {"type": "text", "text": "You are Qwen, a virtual human developed by the Qwen Team, Alibaba Group, capable of perceiving auditory and visual inputs, as well as generating text and speech."}
        ],
    },
    {
        "role": "user",
        "content": [
            {"type": "text", "text": "你好,介绍一下杭州的美食!"},
            # {"type": "video", "video": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-Omni/draw.mp4"},
        ],
    },
]

# set use audio in video
USE_AUDIO_IN_VIDEO = True

# Preparation for inference
text = processor.apply_chat_template(conversation, add_generation_prompt=True, tokenize=False)
audios, images, videos = process_mm_info(conversation, use_audio_in_video=USE_AUDIO_IN_VIDEO)
inputs = processor(text=text, audio=audios, images=images, videos=videos, return_tensors="pt", padding=True, use_audio_in_video=USE_AUDIO_IN_VIDEO)
inputs = inputs.to(model.device).to(model.dtype)

# Inference: Generation of the output text and audio
text_ids, audio = model.generate(**inputs, use_audio_in_video=USE_AUDIO_IN_VIDEO)

text = processor.batch_decode(text_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)
print(text)
sf.write(
    "output.wav",
    audio.reshape(-1).detach().cpu().numpy(),
    samplerate=24000,
)

踩坑点

我在使用官方的音频地址时,服务器直接卡死,不要使用官方提供的音频地址。报错如下:

[10:00:38] /github/workspace/src/video/video_reader.cc:83: ERROR opening: https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-Omni/draw.mp4, Protocol not found
【版权声明】本文为华为云社区用户原创内容,未经允许不得转载,如需转载请自行联系原作者进行授权。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0)

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。