当前位置: 首页 > news >正文

Qwen多模态模型全解析

目录

1 qw-vl

1.1 命令解析与注意事项

1.2 API请求示例

2 qw-image

2.1 使用原生方式,需要显存较多

2.2 使用comfyui,显存占用少


 

1 qw-vl

qw-vl 视觉模型可以识别图片以及视频,目前已经支持vllm和sglang运行

https://github.com/QwenLM/Qwen3-VL

https://docs.vllm.ai/projects/recipes/en/latest/Qwen/Qwen2.5-VL.html#running-qwen25-vl-with-bf16-on-4xa100

1.1 命令解析与注意事项

启动 vLLM 服务的关键参数说明:

modelscope download --model Qwen/Qwen2.5-VL-7B-Instruct --local_dir /mnt/Qwen2.5-VL-7B-Instruct
export TOKENIZERS_PARALLELISM=false
vllm serve /mnt/Qwen2.5-VL-7B-Instruct \--host 0.0.0.0 \--port 8000 \--tensor-parallel-size 2 \--max-model-len 65535 \--mm-encoder-tp-mode data \--limit-mm-per-prompt '{"image":2,"video":0}'  # 限制每提示图像/视频数量

 

1.2 API请求示例

通过 curl 发送多模态请求:

curl -s  -X POST "http://127.0.0.1:8000/v1/chat/completions"   -H "Content-Type: application/json"     -d '{"model": "/mnt/Qwen2.5-VL-7B-Instruct","messages": [{"role": "user","content": [{"type": "image_url","image_url": {"url": "https://ofasys-multimodal-wlcb-3-toshanghai.oss-accelerate.aliyuncs.com/wpf272043/keepme/image/receipt.png"}},{"type": "text","text": "描述了什么"}]}],"max_tokens": 2048}'|jq  # 使用jq格式化JSON输出

2 qw-image

文生图模型

https://github.com/QwenLM/Qwen-Image

2.1 使用原生方式,需要显存较多

显存占用情况,一张卡跑不起来

modelscope download --model Qwen/Qwen-Image --local_dir /mnt/Qwen-Image
pip install torch torchvision accelerate diffusers
pip install --upgrade diffusers transformers accelerate
pip install git+https://github.com/huggingface/diffusers
from diffusers import DiffusionPipeline
import torchmodel_name = "/mnt/Qwen-Image"# Load the pipeline
if torch.cuda.is_available():torch_dtype = torch.bfloat16device = "cuda"
else:torch_dtype = torch.float32device = "cpu"pipe = DiffusionPipeline.from_pretrained(model_name, torch_dtype=torch_dtype,device_map="balanced")
#pipe = pipe.to(device)positive_magic = {"en": ", Ultra HD, 4K, cinematic composition.", # for english prompt"zh": ", 超清,4K,电影级构图." # for chinese prompt
}# Generate image
prompt = '''A coffee shop entrance features a chalkboard sign reading "Qwen Coffee 😊 $2 per cup," with a neon light beside it displaying "通义千问". Next to it hangs a poster showing a beautiful Chinese woman, and beneath the poster is written "π≈3.1415926-53589793-23846264-33832795-02384197".'''negative_prompt = " " # Recommended if you don't use a negative prompt.# Generate with different aspect ratios
aspect_ratios = {"1:1": (1328, 1328),"16:9": (1664, 928),"9:16": (928, 1664),"4:3": (1472, 1104),"3:4": (1104, 1472),"3:2": (1584, 1056),"2:3": (1056, 1584),
}width, height = aspect_ratios["16:9"]image = pipe(prompt=prompt + positive_magic["en"],negative_prompt=negative_prompt,width=width,height=height,num_inference_steps=50,true_cfg_scale=4.0,generator=torch.Generator(device="cuda").manual_seed(42)
).images[0]image.save("example.png")

2.2 使用comfyui,显存占用少

ComfyUI是一个基于节点的开源可视化工具,用于构建和运行生成式AI工作流,主要用于Stable Diffusion等AI绘画任务

显存占用情况,比原生的要少很多就可以跑起来

https://comfyui-wiki.com/zh/install/install-comfyui/install-comfyui-on-linux

pip install comfy-cli
comfy --install-completion
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu128
comfy install
comfy launch -- --listen 0.0.0.0 --port 8188 &> comfyui.log &

启动后选择内置模版

需要去huggingface下载对应模型放到指定位置

  • vae / qwen_image_vae.safetensors
  • text_encoders / qwen_2.5_vl_7b_fp8_scaled.safetensors
  • loras / Qwen-Image-Lightning-8steps-V1.0.safetensors
  • diffusion_models / qwen_image_fp8_e4m3fn.safetensors

点击运行

时间差不多在一分半

 

http://www.dtcms.com/a/592584.html

相关文章:

  • 做彩票网站要多少钱中山企业门户网站建设
  • 淘宝店铺全量商品接口实战:分类穿透采集与增量同步的技术方案
  • 【Linux】从基础到精通:内核调试与模块开发进阶之路
  • 高端品销售网站whois查询 站长工具
  • Diffusion Models与视频超分(3): 解读当前最快和最强的开源模型FlashVSR
  • 【Linux】进程间通信(二)命名管道(FIFO)实战指南:从指令操作到面向对象封装的进程间通信实现
  • 蒙古语网站建设网站制作 那种语言好
  • 阿里云效 = Jenkins + Gitlab + 免费服务器
  • Ganache-CLI以太坊私网JSON-RPC接口大全:从入门到精通
  • 免费测评RPC分布式博客平台(仅用云服务器支持高性能)
  • CentOS7 单机安装 Zookeeper 3.5.8(JDK 1.8 环境)
  • CMP(类Cloudera CDP 7.3 404版华为Kunpeng)与其他大数据平台对比
  • 青岛工程建设管理信息网站下载网站空间 购买
  • 25年11月软考架构真题《论云原生数据库》考后复盘总结
  • golang项目CRUD示例
  • 小米网站 用什么做的项城网站设计
  • Go语言数据竞争全面解析与解决方案
  • 重塑 exec.Command:打造更可控的 Go 命令执行器
  • 【译】借助提示词、资源和采样,在 Visual Studio 中充分利用 MCP
  • 华为OD机试 双机位A卷 - 整理版本号 (JAVA Python C++ JS GO)
  • 【C++初阶】vector容器的模拟实现,各接口讲解
  • QGIS 3.34+ 网络分析基础数据自动化生成:从脚本到应用
  • 第2章-类加载子系统-知识补充
  • Go Fiber 简介
  • 专业酒店设计网站建设手机什么网站可以设计楼房
  • 20251110给荣品RD-RK3588开发板跑Rockchip的原厂Android13系统时熟悉散热风扇
  • UniApp自定义Android基座原理及流程
  • Ganache-CLI以太坊私网JSON-RPC接口执行环境搭建
  • Android 系统超级实用的分析调试命令
  • 【ZeroRange WebRTC】WebRTC 加密安全总览:对称/非对称、数字签名、证书、SHA/HMAC、随机数