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}
}








