模型简介
模型特点
模型能力
使用案例
许可证: 其他
许可证名称: qwen
许可证链接: https://huggingface.co/Qwen/Qwen2.5-VL-72B-Instruct-AWQ/blob/main/LICENSE
语言:
- 英文
任务标签: 图像文本到文本
标签: - 多模态
库名称: transformers
基础模型: - Qwen/Qwen2.5-VL-72B-Instruct
修复 Qwen/Qwen2.5-VL-72B-Instruct-AWQ 中的错误
这是 Qwen/Qwen2.5-VL-72B-Instruct-AWQ 的一个分支,权重完全相同。
通过修改 preprocessor_config.json 修复了原模型中的 此问题。
简介
自 Qwen2-VL 发布以来的五个月里,众多开发者基于 Qwen2-VL 视觉语言模型构建了新模型,并提供了宝贵反馈。在此期间,我们专注于打造更有用的视觉语言模型。今天,我们很高兴推出 Qwen 家族的最新成员:Qwen2.5-VL。
主要增强功能:
-
视觉理解能力:Qwen2.5-VL 不仅擅长识别常见物体如花鸟鱼虫,还能高效分析图像中的文本、图表、图标、图形和布局。
-
代理能力:Qwen2.5-VL 可直接作为视觉代理,进行推理并动态调用工具,支持计算机和手机操作。
-
长视频理解与事件捕捉:Qwen2.5-VL 能理解超过 1 小时的视频,并新增了通过精确定位相关片段捕捉事件的能力。
-
多格式视觉定位:Qwen2.5-VL 可通过生成边界框或点精确标注图像中的物体,并稳定输出坐标和属性的 JSON 格式。
-
结构化输出生成:对于发票、表格等数据扫描件,Qwen2.5-VL 支持结构化内容输出,适用于金融、商业等领域。
模型架构更新:
- 视频理解的动态分辨率与帧率训练:
通过动态 FPS 采样将动态分辨率扩展至时间维度,使模型能适应不同采样率的视频。同时,我们在时间维度更新了 mRoPE,结合 ID 和绝对时间对齐,使模型能学习时间序列和速度,最终实现精确时间点定位。
- 高效精简的视觉编码器
通过策略性引入窗口注意力机制到 ViT 中,提升了训练和推理速度。ViT 架构进一步采用 SwiGLU 和 RMSNorm 优化,与 Qwen2.5 LLM 结构对齐。
我们提供了 30 亿、70 亿和 720 亿参数的三个模型。本仓库包含 720 亿参数的指令调优版 Qwen2.5-VL 模型。更多信息请访问我们的 博客 和 GitHub。
评估
要求
Qwen2.5-VL 的代码已集成至最新版 Hugging Face transformers,建议通过以下命令从源码安装:
pip install git+https://github.com/huggingface/transformers accelerate
否则可能遇到以下错误:
KeyError: 'qwen2_5_vl'
快速开始
以下示例展示如何使用 🤖 ModelScope 和 🤗 Transformers 运行 Qwen2.5-VL。
建议通过以下命令安装最新版 transformers:
pip install git+https://github.com/huggingface/transformers accelerate
否则可能遇到错误:
KeyError: 'qwen2_5_vl'
我们提供工具包方便处理多种视觉输入(如 base64、URL、交替图像和视频),安装命令如下:
# 推荐安装带 [decord] 的版本以加速视频加载
pip install qwen-vl-utils[decord]==0.0.8
若非 Linux 系统可能无法通过 PyPI 安装 decord,可改用 pip install qwen-vl-utils
(将回退到 torchvision 处理视频),但仍建议从源码安装 decord。
使用 🤗 Transformers 对话
以下代码片段展示如何结合 transformers
和 qwen_vl_utils
使用对话模型:
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-72B-Instruct-AWQ", torch_dtype="auto", device_map="auto"
)
# 推荐启用 flash_attention_2 以提升多图像/视频场景下的速度和内存效率
# model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
# "Qwen/Qwen2.5-VL-72B-Instruct-AWQ",
# torch_dtype=torch.bfloat16,
# attn_implementation="flash_attention_2",
# device_map="auto",
# )
# 默认处理器
processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-72B-Instruct-AWQ")
# 模型默认每图视觉 token 范围为 4-16384
# 可设置 min_pixels 和 max_pixels 平衡性能与成本(如 256-1280 token 范围)
# min_pixels = 256*28*28
# max_pixels = 1280*28*28
# processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-72B-Instruct-AWQ", 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": "描述这张图片。"},
],
}
]
# 推理准备
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)
🤖 ModelScope
特别建议中国大陆用户使用 ModelScope,snapshot_download
可解决检查点下载问题。
更多使用技巧
支持图像输入为本地文件、base64 或 URL,视频目前仅支持本地文件。
# 可直接在文本中插入本地路径、URL 或 base64 编码图像
## 本地文件
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": "file:///path/to/your/image.jpg"},
{"type": "text", "text": "描述这张图片。"},
],
}
]
## 图片 URL
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": "http://path/to/your/image.jpg"},
{"type": "text", "text": "描述这张图片。"},
],
}
]
## Base64 编码图像
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": "data:image;base64,/9j/..."},
{"type": "text", "text": "描述这张图片。"},
],
}
]
图像分辨率优化
模型支持多种分辨率输入。默认使用原始分辨率,但更高分辨率可提升性能(需更多计算)。用户可通过设置最小/最大像素数(如 256-1280 token 范围)平衡速度与内存。
min_pixels = 256 * 28 * 28
max_pixels = 1280 * 28 * 28
processor = AutoProcessor.from_pretrained(
"Qwen/Qwen2.5-VL-72B-Instruct-AWQ", min_pixels=min_pixels, max_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": "描述这张图片。"},
],
}
]
# 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": "描述这张图片。"},
],
}
]
处理长文本
当前 config.json
支持最大 32,768 token 的上下文长度。
对于超过此长度的输入,我们采用 YaRN 技术增强模型的外推能力,确保长文本性能。
支持的框架可在 config.json
中添加以下配置启用 YaRN:
{
...,
"type": "yarn",
"mrope_section": [16, 24, 24],
"factor": 4,
"original_max_position_embeddings": 32768
}
但需注意,此方法会显著影响时空定位任务性能,故不推荐使用。
对于长视频输入,由于 mRoPE 本身对 ID 更高效,可直接将 max_position_embeddings 调整为更大值(如 64k)。
基准测试
量化模型性能
本节报告 Qwen2.5-VL 系列量化模型(含 GPTQ 和 AWQ)的生成性能,包括:
- MMMU_VAL(准确率)
- DocVQA_VAL(准确率)
- MMBench_DEV_EN(准确率)
- MathVista_MINI(准确率)
使用 VLMEvalkit 评估所有模型。
模型规模 | 量化方式 | MMMU_VAL | DocVQA_VAL | MMBench_EDV_EN | MathVista_MINI |
---|---|---|---|---|---|
Qwen2.5-VL-72B-Instruct | BF16 (🤗🤖) |
70.0 | 96.1 | 88.2 | 75.3 |
AWQ (🤗🤖) |
69.1 | 96.0 | 87.9 | 73.8 | |
Qwen2.5-VL-7B-Instruct | BF16 (🤗🤖) |
58.4 | 94.9 | 84.1 | 67.9 |
AWQ (🤗🤖) |
55.6 | 94.6 | 84.2 | 64.7 | |
Qwen2.5-VL-3B-Instruct | BF16 (🤗🤖) |
51.7 | 93.0 | 79.8 | 61.4 |
AWQ (🤗🤖) |
49.1 | 91.8 | 78.0 | 58.8 |
引用
如果觉得我们的工作有帮助,欢迎引用。
@misc{qwen2.5-VL,
title = {Qwen2.5-VL},
url = {https://qwenlm.github.io/blog/qwen2.5-vl/},
author = {Qwen Team},
month = {January},
year = {2025}
}
@article{Qwen2VL,
title={Qwen2-VL: Enhancing Vision-Language Model's Perception of the World at Any Resolution},
author={Wang, Peng and Bai, Shuai and Tan, Sinan and Wang, Shijie and Fan, Zhihao and Bai, Jinze and Chen, Keqin and Liu, Xuejing and Wang, Jialin and Ge, Wenbin and Fan, Yang and Dang, Kai and Du, Mengfei and Ren, Xuancheng and Men, Rui and Liu, Dayiheng and Zhou, Chang and Zhou, Jingren and Lin, Junyang},
journal={arXiv preprint arXiv:2409.12191},
year={2024}
}
@article{Qwen-VL,
title={Qwen-VL: A Versatile Vision-Language Model for Understanding, Localization, Text Reading, and Beyond},
author={Bai, Jinze and Bai, Shuai and Yang, Shusheng and Wang, Shijie and Tan, Sinan and Wang, Peng and Lin, Junyang and Zhou, Chang and Zhou, Jingren},
journal={arXiv preprint arXiv:2308.12966},
year={2023}
}








