Qwen2.5 VL 32B Instruct GGUF
模型简介
模型特点
模型能力
使用案例
🚀 Qwen2.5-VL-32B-Instruct GGUF模型
Qwen2.5-VL-32B-Instruct GGUF模型是一款强大的多模态模型,可处理图像和文本输入并生成文本输出。它在视觉理解、文本处理等方面表现出色,适用于多种场景,如视觉问答、视频分析等。
🚀 快速开始
使用llama.cpp运行Qwen 2.5 VL Instruct(截至2025年5月10日的最新版本)
- 下载Qwen 2.5 VL gguf文件:
访问 https://huggingface.co/Mungert/Qwen2.5-VL-32B-Instruct-GGUF/tree/main,选择名称中不包含
mmproj
的gguf文件。 示例gguf文件:https://huggingface.co/Mungert/Mungert/Qwen2.5-VL-32B-Instruct-GGUF/resolve/main/Qwen2.5-VL-32B-Instruct-q8_0.gguf 将此文件复制到你选择的文件夹。 - 下载Qwen 2.5 VL mmproj文件:
访问 https://huggingface.co/Mungert/Qwen2.5-VL-32B-Instruct-GGUF/tree/main,选择名称中包含
mmproj
的文件。 示例mmproj文件:https://huggingface.co/Mungert/Qwen2.5-VL-32B-Instruct-GGUF/resolve/main/Qwen2.5-VL-32B-Instruct-mmproj-f16.gguf 将此文件复制到你选择的文件夹。 - 复制图像到gguf文件所在文件夹或适当修改路径:
在以下示例中,gguf文件、图像和
llama-mtmd-cli
位于同一文件夹。 示例图像:https://huggingface.co/Mungert/Qwen2.5-VL-32B-Instruct-GGUF/resolve/main/car-1.jpg 将此文件复制到你选择的文件夹。 - 运行CLI工具: 在你选择的文件夹中运行以下命令:
llama-mtmd-cli -m Qwen2.5-VL-32B-Instruct-q8_0.gguf --mmproj Qwen2.5-VL-32B-Instruct-mmproj-f16.gguf -p "Describe this image." --image ./car-1.jpg
✨ 主要特性
超低比特量化(1 - 2比特)与IQ - DynamicGate
我们最新的量化方法为超低比特模型(1 - 2比特)引入了精度自适应量化,在Llama - 3 - 8B上的基准测试证明了其有效性。该方法采用特定层策略,在保持极高内存效率的同时保留了准确性。
- 基准测试环境:所有测试均在Llama - 3 - 8B - Instruct上进行,使用标准困惑度评估管道、2048令牌上下文窗口,并在所有量化中使用相同的提示集。
- 方法:
- 动态精度分配:前/后25%的层采用IQ4_XS(选定层),中间50%采用IQ2_XXS/IQ3_S(提高效率)。
- 关键组件保护:嵌入层/输出层使用Q5_K,与标准1 - 2比特量化相比,误差传播降低38%。
- 量化性能对比(Llama - 3 - 8B): | 量化方式 | 标准困惑度 | DynamicGate困惑度 | 困惑度变化 | 标准大小 | DG大小 | 大小变化 | 标准速度 | DG速度 | |--------------|--------------|------------------|---------|----------|---------|--------|-----------|----------| | IQ2_XXS | 11.30 | 9.84 | -12.9% | 2.5G | 2.6G | +0.1G | 234s | 246s | | IQ2_XS | 11.72 | 11.63 | -0.8% | 2.7G | 2.8G | +0.1G | 242s | 246s | | IQ2_S | 14.31 | 9.02 | -36.9% | 2.7G | 2.9G | +0.2G | 238s | 244s | | IQ1_M | 27.46 | 15.41 | -43.9% | 2.2G | 2.5G | +0.3G | 206s | 212s | | IQ1_S | 53.07 | 32.00 | -39.7% | 2.1G | 2.4G | +0.3G | 184s | 209s |
模型选择建议
- 适合GPU显存的模型:适用于内存受限的部署场景。
- CPU和边缘设备:可容忍1 - 2比特误差的场景。
- 研究用途:用于超低比特量化的研究。
选择合适的模型格式
选择正确的模型格式取决于你的硬件能力和内存限制。
模型格式 | 精度 | 内存使用 | 设备要求 | 最佳使用场景 |
---|---|---|---|---|
BF16 | 最高 | 高 | 支持BF16的GPU/CPU | 高速推理且内存使用减少 |
F16 | 高 | 高 | 支持FP16的设备 | BF16不可用时的GPU推理 |
Q4_K | 中低 | 低 | CPU或低显存设备 | 内存受限的环境 |
Q6_K | 中 | 中等 | 内存较多的CPU | 量化模型中精度较好的选择 |
Q8_0 | 高 | 中等 | 有足够显存的CPU或GPU | 量化模型中精度最佳 |
IQ3_XS | 极低 | 极低 | 超低内存设备 | 极端内存效率但精度低 |
Q4_0 | 低 | 低 | ARM或低内存设备 | llama.cpp可针对ARM设备优化 |
最新更新
除了原始功能,我们通过强化学习进一步提升了Qwen2.5 - VL - 32B的数学和问题解决能力,显著改善了模型的主观用户体验,响应风格更符合人类偏好。特别是在数学、逻辑推理和基于知识的问答等客观查询方面,响应的详细程度和格式清晰度有了明显提升。
模型架构更新
- 视频理解的动态分辨率和帧率训练:通过采用动态FPS采样将动态分辨率扩展到时间维度,使模型能够理解不同采样率的视频。相应地,在时间维度上更新mRoPE,使模型能够学习时间序列和速度,最终获得定位特定时刻的能力。
- 精简高效的视觉编码器:通过在ViT中策略性地实现窗口注意力,提高了训练和推理速度。ViT架构通过SwiGLU和RMSNorm进一步优化,与Qwen2.5 LLM的结构保持一致。
📦 安装指南
依赖安装
Qwen2.5 - VL的代码已集成到最新的Hugging Face transformers中,建议使用以下命令从源代码构建:
pip install git+https://github.com/huggingface/transformers accelerate
否则可能会遇到以下错误:
KeyError: 'qwen2_5_vl'
同时,我们提供了一个工具包,可帮助你更方便地处理各种类型的视觉输入,可使用以下命令安装:
# 强烈建议使用`[decord]`特性以加快视频加载速度
pip install qwen-vl-utils[decord]==0.0.8
如果你不使用Linux系统,可能无法从PyPI安装decord
,此时可以使用pip install qwen-vl-utils
,它将回退到使用torchvision进行视频处理。不过,你也可以从源代码安装decord以在加载视频时使用decord。
💻 使用示例
基础用法
使用🤗 Transformers进行对话
from transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessor
from qwen_vl_utils import process_vision_info
# 默认:将模型加载到可用设备上
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
"Qwen/Qwen2.5-VL-32B-Instruct", torch_dtype="auto", device_map="auto"
)
# 建议启用flash_attention_2以获得更好的加速和内存节省,特别是在多图像和视频场景中
# model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
# "Qwen/Qwen2.5-VL-32B-Instruct",
# torch_dtype=torch.bfloat16,
# attn_implementation="flash_attention_2",
# device_map="auto",
# )
# 默认处理器
processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-32B-Instruct")
# 模型中每张图像的视觉令牌数量默认范围是4 - 16384
# 你可以根据需要设置min_pixels和max_pixels,例如令牌范围为256 - 1280,以平衡性能和成本
# min_pixels = 256*28*28
# max_pixels = 1280*28*28
# processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-32B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
},
{"type": "text", "text": "Describe this image."},
],
}
]
# 推理准备
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",
)
inputs = inputs.to("cuda")
# 推理:生成输出
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)
高级用法
多图像推理
# 包含多个图像和文本查询的消息
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": "file:///path/to/image1.jpg"},
{"type": "image", "image": "file:///path/to/image2.jpg"},
{"type": "text", "text": "Identify the similarities between these images."},
],
}
]
# 推理准备
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",
)
inputs = inputs.to("cuda")
# 推理
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)
视频推理
# 包含图像列表作为视频和文本查询的消息
messages = [
{
"role": "user",
"content": [
{
"type": "video",
"video": [
"file:///path/to/frame1.jpg",
"file:///path/to/frame2.jpg",
"file:///path/to/frame3.jpg",
"file:///path/to/frame4.jpg",
],
},
{"type": "text", "text": "Describe this video."},
],
}
]
# 包含本地视频路径和文本查询的消息
messages = [
{
"role": "user",
"content": [
{
"type": "video",
"video": "file:///path/to/video1.mp4",
"max_pixels": 360 * 420,
"fps": 1.0,
},
{"type": "text", "text": "Describe this video."},
],
}
]
# 包含视频URL和文本查询的消息
messages = [
{
"role": "user",
"content": [
{
"type": "video",
"video": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-VL/space_woaudio.mp4",
},
{"type": "text", "text": "Describe this video."},
],
}
]
# 在Qwen 2.5 VL中,帧率信息也输入到模型中以与绝对时间对齐
# 推理准备
text = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
image_inputs, video_inputs, video_kwargs = process_vision_info(messages, return_video_kwargs=True)
inputs = processor(
text=[text],
images=image_inputs,
videos=video_inputs,
fps=fps,
padding=True,
return_tensors="pt",
**video_kwargs,
)
inputs = inputs.to("cuda")
# 推理
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)
视频URL兼容性很大程度上取决于第三方库版本,详情如下表所示。如果不想使用默认的后端,可以通过FORCE_QWENVL_VIDEO_READER=torchvision
或FORCE_QWENVL_VIDEO_READER=decord
更改后端。
后端 | HTTP | HTTPS |
---|---|---|
torchvision >= 0.19.0 | ✅ | ✅ |
torchvision < 0.19.0 | ❌ | ❌ |
decord | ✅ | ❌ |
批量推理
# 批量推理的示例消息
messages1 = [
{
"role": "user",
"content": [
{"type": "image", "image": "file:///path/to/image1.jpg"},
{"type": "image", "image": "file:///path/to/image2.jpg"},
{"type": "text", "text": "What are the common elements in these pictures?"},
],
}
]
messages2 = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who are you?"},
]
# 合并消息进行批量处理
messages = [messages1, messages2]
# 批量推理准备
texts = [
processor.apply_chat_template(msg, tokenize=False, add_generation_prompt=True)
for msg in messages
]
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
text=texts,
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")
# 批量推理
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_texts = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_texts)
使用🤖 ModelScope
我们强烈建议用户(特别是中国大陆的用户)使用ModelScope。snapshot_download
可以帮助你解决下载检查点的问题。
更多使用提示
- 输入图像支持:支持本地文件、Base64编码和URL。
- 输入视频支持:目前仅支持本地文件。
# 可以直接在文本中插入本地文件路径、URL或Base64编码的图像
## 本地文件路径
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": "file:///path/to/your/image.jpg"},
{"type": "text", "text": "Describe this image."},
],
}
]
## 图像URL
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": "http://path/to/your/image.jpg"},
{"type": "text", "text": "Describe this image."},
],
}
]
## Base64编码的图像
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": "data:image;base64,/9j/..."},
{"type": "text", "text": "Describe this image."},
],
}
]
图像分辨率优化性能
模型支持广泛的分辨率输入,默认使用原始分辨率,但更高的分辨率可以提升性能,但会增加计算量。用户可以设置最小和最大像素数以实现最佳配置,例如令牌数量范围为256 - 1280,以平衡速度和内存使用。
min_pixels = 256 * 28 * 28
max_pixels = 1280 * 28 * 28
processor = AutoProcessor.from_pretrained(
"Qwen/Qwen2.5-VL-32B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels
)
此外,我们提供了两种方法来精细控制输入到模型的图像大小:
- 定义min_pixels和max_pixels:图像将调整大小以保持其宽高比在min_pixels和max_pixels范围内。
- 指定确切尺寸:直接设置
resized_height
和resized_width
,这些值将四舍五入到最接近的28的倍数。
# min_pixels和max_pixels
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "file:///path/to/your/image.jpg",
"resized_height": 280,
"resized_width": 420,
},
{"type": "text", "text": "Describe this image."},
],
}
]
# resized_height和resized_width
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "file:///path/to/your/image.jpg",
"min_pixels": 50176,
"max_pixels": 50176,
},
{"type": "text", "text": "Describe this image."},
],
}
]
处理长文本
当前的config.json
设置上下文长度最大为32768令牌。为了处理超过32768令牌的大量输入,我们使用了YaRN技术来增强模型的长度外推能力,确保在长文本上的最佳性能。
对于支持的框架,可以在config.json
中添加以下内容以启用YaRN:
{
...,
"type": "yarn",
"mrope_section": [
16,
24,
24
],
"factor": 4,
"original_max_position_embeddings": 32768
}
需要注意的是,这种方法对时间和空间定位任务的性能有显著影响,因此不建议使用。同时,对于长视频输入,由于MRoPE本身在ids使用上更经济,可以直接将max_position_embeddings修改为更大的值,如64k。
📚 详细文档
评估
视觉评估
数据集 | Qwen2.5 - VL - 72B (🤗🤖) |
Qwen2 - VL - 72B (🤗🤖) |
Qwen2.5 - VL - 32B (🤗🤖) |
---|---|---|---|
MMMU | 70.2 | 64.5 | 70 |
MMMU Pro | 51.1 | 46.2 | 49.5 |
MMStar | 70.8 | 68.3 | 69.5 |
MathVista | 74.8 | 70.5 | 74.7 |
MathVision | 38.1 | 25.9 | 40.0 |
OCRBenchV2 | 61.5/63.7 | 47.8/46.1 | 57.2/59.1 |
CC - OCR | 79.8 | 68.7 | 77.1 |
DocVQA | 96.4 | 96.5 | 94.8 |
InfoVQA | 87.3 | 84.5 | 83.4 |
LVBench | 47.3 | - | 49.00 |
CharadesSTA | 50.9 | - | 54.2 |
VideoMME | 73.3/79.1 | 71.2/77.8 | 70.5/77.9 |
MMBench - Video | 2.02 | 1.7 | 1.93 |
AITZ | 83.2 | - | 83.1 |
Android Control | 67.4/93.7 | 66.4/84.4 | 69.6/93.3 |
ScreenSpot | 87.1 | - | 88.5 |
ScreenSpot Pro | 43.6 | - | 39.4 |
AndroidWorld | 35 | - | 22.0 |
OSWorld | 8.83 | - | 5.92 |
文本评估
模型 | MMLU | MMLU - PRO | MATH | GPQA - diamond | MBPP | Human Eval |
---|---|---|---|---|---|---|
Qwen2.5 - VL - 32B | 78.4 | 68.8 | 82.2 | 46.0 | 84.0 | 91.5 |
Mistral - Small - 3.1 - 24B | 80.6 | 66.8 | 69.3 | 46.0 | 74.7 | 88.4 |
Gemma3 - 27B - IT | 76.9 | 67.5 | 89 | 42.4 | 74.4 | 87.8 |
GPT - 4o - Mini | 82.0 | 61.7 | 70.2 | 39.4 | 84.8 | 87.2 |
Claude - 3.5 - Haiku | 77.6 | 65.0 | 69.2 | 41.6 | 85.6 | 88.1 |
🔧 技术细节
包含的文件及详情
文件名称 | 说明 |
---|---|
Qwen2.5-VL-32B-Instruct-bf16.gguf |
模型权重以BF16格式保存,适用于需要将模型重新量化为其他格式的情况,最佳使用场景是设备支持BF16加速。 |
Qwen2.5-VL-32B-Instruct-f16.gguf |
模型权重以F16格式存储,适用于设备支持FP16,特别是BF16不可用的情况。 |
Qwen2.5-VL-32B-Instruct-bf16-q8_0.gguf |
输出层和嵌入层保持BF16格式,其他层量化为Q8_0,适用于设备支持BF16且需要量化版本的情况。 |
Qwen2.5-VL-32B-Instruct-f16-q8_0.gguf |
输出层和嵌入层保持F16格式,其他层量化为Q8_0。 |
Qwen2.5-VL-32B-Instruct-q4_k.gguf |
输出层和嵌入层量化为Q8_0,其他层量化为Q4_K,适合内存有限的CPU推理。 |
Qwen2.5-VL-32B-Instruct-q4_k_s.gguf |
最小的Q4_K变体,以牺牲一定精度为代价减少内存使用,最适合极低内存的设置。 |
Qwen2.5-VL-32B-Instruct-q6_k.gguf |
输出层和嵌入层量化为Q8_0,其他层量化为Q6_K。 |
Qwen2.5-VL-32B-Instruct-q8_0.gguf |
完全Q8量化的模型,以获得更好的精度,需要更多的内存但提供更高的精度。 |
Qwen2.5-VL-32B-Instruct-iq3_xs.gguf |
IQ3_XS量化,针对极端内存效率进行优化,最适合超低内存设备。 |
Qwen2.5-VL-32B-Instruct-iq3_m.gguf |
IQ3_M量化,提供中等块大小以获得更好的精度,适用于低内存设备。 |
Qwen2.5-VL-32B-Instruct-q4_0.gguf |
纯Q4_0量化,针对ARM设备进行优化,最适合低内存环境,若需要更好的精度可选择IQ4_NL。 |
测试模型相关
如果你觉得这些模型有用,请点赞❤。也欢迎你测试我的网络监控助手👉 网络监控助手。点击主页面和仪表盘页面右下角的聊天图标,选择一个大语言模型(LLM),可以在TurboLLM -> FreeLLM -> TestLLM之间切换。
- 正在测试的内容:我正在使用小型开源模型对网络监控服务进行函数调用实验,探索模型在保证功能的前提下可以多小。
- TestLLM:使用llama.cpp在CPU虚拟机的6个线程上运行当前测试模型(加载大约需要15秒,推理速度较慢,一次只能处理一个用户提示,仍在进行扩展优化!)。如果你感兴趣,我很乐意分享其工作原理。
- 其他可用的AI助手:
📄 许可证
本项目采用Apache - 2.0许可证。
📚 引用
如果你觉得我们的工作有帮助,请引用以下文献:
@article{Qwen2.5-VL,
title={Qwen2.5-VL Technical Report},
author={Bai, Shuai and Chen, Keqin and Liu, Xuejing and Wang, Jialin and Ge, Wenbin and Song, Sibo and Dang, Kai and Wang, Peng and Wang, Shijie and Tang, Jun and Zhong, Humen and Zhu, Yuanzhi and Yang, Mingkun and Li, Zhaohai and Wan, Jianqiang and Wang, Pengfei and Ding, Wei and Fu, Zheren and Xu, Yiheng and Ye, Jiabo and Zhang, Xi and Xie, Tianbao and Cheng, Zesen and Zhang, Hang and Yang, Zhibo and Xu, Haiyang and Lin, Junyang},
journal={arXiv preprint arXiv:2502.13923},
year={2025}
}








