Qwen2.5 VL 3B Instruct Quantized.w4a16
Qwen2.5-VL-3B-Instruct的量化版本,權重量化為INT4,激活量化為FP16,適用於視覺-文本任務的高效推理。
Downloads 167
Release Time : 2/7/2025
Model Overview
該模型是基於Qwen/Qwen2.5-VL-3B-Instruct的量化版本,專為視覺-文本任務優化,支持高效的文本生成和視覺理解。
Model Features
高效量化
權重量化為INT4,激活量化為FP16,顯著提升推理效率。
多模態支持
支持視覺和文本輸入,能夠理解和生成與圖像相關的文本內容。
高性能推理
通過vLLM後端實現高效部署,支持單流和多流異步推理。
Model Capabilities
視覺-文本理解
文本生成
圖像內容分析
多模態任務處理
Use Cases
視覺問答
圖像內容描述
根據輸入的圖像生成詳細的文本描述。
在VQAv2數據集上達到73.58的準確率。
文檔視覺問答
回答與文檔圖像內容相關的問題。
在DocVQA數據集上達到91.58的ANLS分數。
視覺推理
數學視覺問題解答
解決包含數學公式和圖像的複雜問題。
在Mathvista數據集上達到45.75的準確率。
🚀 Qwen2.5-VL-3B-Instruct量化版本w4a16
本項目是Qwen/Qwen2.5-VL-3B-Instruct的量化版本,通過對模型權重和激活值進行量化,在保持一定精度的同時,顯著提升了推理速度和效率,適用於視覺-文本多模態任務。
🚀 快速開始
本模型可以使用 vLLM 後端進行高效部署,示例代碼如下:
from vllm.assets.image import ImageAsset
from vllm import LLM, SamplingParams
# 準備模型
llm = LLM(
model="neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w4a16",
trust_remote_code=True,
max_model_len=4096,
max_num_seqs=2,
)
# 準備輸入
question = "What is the content of this image?"
inputs = {
"prompt": f"<|user|>\n<|image_1|>\n{question}<|end|>\n<|assistant|>\n",
"multi_modal_data": {
"image": ImageAsset("cherry_blossom").pil_image.convert("RGB")
},
}
# 生成響應
print("========== SAMPLE GENERATION ==============")
outputs = llm.generate(inputs, SamplingParams(temperature=0.2, max_tokens=64))
print(f"PROMPT : {outputs[0].prompt}")
print(f"RESPONSE: {outputs[0].outputs[0].text}")
print("==========================================")
vLLM 還支持兼容 OpenAI 的服務,更多詳細信息請參閱 文檔。
✨ 主要特性
- 模型架構:基於 Qwen/Qwen2.5-VL-3B-Instruct 架構,支持視覺-文本輸入,輸出文本內容。
- 模型優化:
- 權重量化:採用 INT4 量化,減少模型存儲和計算量。
- 激活值量化:使用 FP16 量化,在保證精度的同時提升計算效率。
- 發佈日期:2025 年 2 月 24 日
- 版本:1.0
- 模型開發者:Neural Magic
📦 安裝指南
文檔未提及具體安裝步驟,可參考 vLLM 官方文檔進行安裝。
💻 使用示例
基礎用法
from vllm.assets.image import ImageAsset
from vllm import LLM, SamplingParams
# 準備模型
llm = LLM(
model="neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w4a16",
trust_remote_code=True,
max_model_len=4096,
max_num_seqs=2,
)
# 準備輸入
question = "What is the content of this image?"
inputs = {
"prompt": f"<|user|>\n<|image_1|>\n{question}<|end|>\n<|assistant|>\n",
"multi_modal_data": {
"image": ImageAsset("cherry_blossom").pil_image.convert("RGB")
},
}
# 生成響應
print("========== SAMPLE GENERATION ==============")
outputs = llm.generate(inputs, SamplingParams(temperature=0.2, max_tokens=64))
print(f"PROMPT : {outputs[0].prompt}")
print(f"RESPONSE: {outputs[0].outputs[0].text}")
print("==========================================")
高級用法
# 本模型的創建代碼示例,使用 llm-compressor 進行量化
import base64
from io import BytesIO
import torch
from datasets import load_dataset
from qwen_vl_utils import process_vision_info
from transformers import AutoProcessor
from llmcompressor.modifiers.quantization import GPTQModifier
from llmcompressor.transformers import oneshot
from llmcompressor.transformers.tracing import (
TraceableQwen2_5_VLForConditionalGeneration,
)
from compressed_tensors.quantization import QuantizationArgs, QuantizationType, QuantizationStrategy, ActivationOrdering, QuantizationScheme
# 加載模型
model_id = "Qwen/Qwen2.5-VL-3B-Instruct"
model = TraceableQwen2_5_VLForConditionalGeneration.from_pretrained(
model_id,
device_map="auto",
torch_dtype="auto",
)
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
# 一次性量化參數
DATASET_ID = "lmms-lab/flickr30k"
DATASET_SPLIT = {"calibration": "test[:512]"}
NUM_CALIBRATION_SAMPLES = 512
MAX_SEQUENCE_LENGTH = 2048
# 加載數據集並預處理
ds = load_dataset(DATASET_ID, split=DATASET_SPLIT)
ds = ds.shuffle(seed=42)
dampening_frac=0.01
# 應用聊天模板並對輸入進行分詞
def preprocess_and_tokenize(example):
# 預處理
buffered = BytesIO()
example["image"].save(buffered, format="PNG")
encoded_image = base64.b64encode(buffered.getvalue())
encoded_image_text = encoded_image.decode("utf-8")
base64_qwen = f"data:image;base64,{encoded_image_text}"
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": base64_qwen},
{"type": "text", "text": "What does the image show?"},
],
}
]
text = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
image_inputs, video_inputs = process_vision_info(messages)
# 分詞
return processor(
text=[text],
images=image_inputs,
videos=video_inputs,
padding=False,
max_length=MAX_SEQUENCE_LENGTH,
truncation=True,
)
ds = ds.map(preprocess_and_tokenize, remove_columns=ds["calibration"].column_names)
# 定義用於多模態輸入的一次性數據整理器
def data_collator(batch):
assert len(batch) == 1
return {key: torch.tensor(value) for key, value in batch[0].items()}
recipe = GPTQModifier(
targets="Linear",
config_groups={
"config_group": QuantizationScheme(
targets=["Linear"],
weights=QuantizationArgs(
num_bits=4,
type=QuantizationType.INT,
strategy=QuantizationStrategy.GROUP,
group_size=128,
symmetric=True,
dynamic=False,
actorder=ActivationOrdering.WEIGHT,
),
),
},
sequential_targets=["Qwen2_5_VLDecoderLayer"],
ignore=["lm_head", "re:visual.*"],
update_size=NUM_CALIBRATION_SAMPLES,
dampening_frac=dampening_frac
)
SAVE_DIR=f"{model_id.split('/')[1]}-quantized.w4a16"
# 執行一次性量化
oneshot(
model=model,
tokenizer=model_id,
dataset=ds,
recipe=recipe,
max_seq_length=MAX_SEQUENCE_LENGTH,
num_calibration_samples=NUM_CALIBRATION_SAMPLES,
trust_remote_code_model=True,
data_collator=data_collator,
output_dir=SAVE_DIR
)
📚 詳細文檔
評估
本模型使用 mistral-evals 進行視覺相關任務的評估,使用 lm_evaluation_harness 進行部分基於文本的基準測試。評估使用以下命令進行:
評估命令
視覺任務
- vqav2
- docvqa
- mathvista
- mmmu
- chartqa
vllm serve neuralmagic/pixtral-12b-quantized.w8a8 --tensor_parallel_size 1 --max_model_len 25000 --trust_remote_code --max_num_seqs 8 --gpu_memory_utilization 0.9 --dtype float16 --limit_mm_per_prompt image=7
python -m eval.run eval_vllm \
--model_name neuralmagic/pixtral-12b-quantized.w8a8 \
--url http://0.0.0.0:8000 \
--output_dir ~/tmp \
--eval_name <vision_task_name>
基於文本的任務
MMLU
lm_eval \
--model vllm \
--model_args pretrained="<model_name>",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=<n>,gpu_memory_utilization=0.8,enable_chunked_prefill=True,trust_remote_code=True \
--tasks mmlu \
--num_fewshot 5 \
--batch_size auto \
--output_path output_dir
MGSM
lm_eval \
--model vllm \
--model_args pretrained="<model_name>",dtype=auto,max_model_len=4096,max_gen_toks=2048,max_num_seqs=128,tensor_parallel_size=<n>,gpu_memory_utilization=0.9 \
--tasks mgsm_cot_native \
--apply_chat_template \
--num_fewshot 0 \
--batch_size auto \
--output_path output_dir
準確率
類別 | 指標 | Qwen/Qwen2.5-VL-3B-Instruct | Qwen2.5-VL-3B-Instruct-quantized.W4A16 | 恢復率 (%) |
---|---|---|---|---|
視覺 | MMMU (val, CoT) explicit_prompt_relaxed_correctness |
44.56 | 41.56 | 93.28% |
視覺 | VQAv2 (val) vqa_match |
75.94 | 73.58 | 96.89 |
視覺 | DocVQA (val) anls |
92.53 | 91.58 | 98.97% |
視覺 | ChartQA (test, CoT) anywhere_in_answer_relaxed_correctness |
81.20 | 78.96 | 97.24% |
視覺 | Mathvista (testmini, CoT) explicit_prompt_relaxed_correctness |
54.15 | 45.75 | 84.51% |
視覺 | 平均得分 | 69.28 | 66.29 | 95.68% |
文本 | MGSM (CoT) | 43.69 | 35.82 | 82.00 |
文本 | MMLU (5-shot) | 65.32 | 62.80 | 96.14% |
推理性能
本模型在單流部署中可實現高達 1.73 倍的加速,在多流異步部署中可實現高達 3.87 倍的加速,具體取決於硬件和使用場景。以下性能基準測試使用 vLLM 版本 0.7.2 和 GuideLLM 進行。
基準測試命令
``` guidellm --model neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w4a16 --target "http://localhost:8000/v1" --data-type emulated --data prompt_tokens=單流性能(使用 vLLM 版本 0.7.2 測量)
硬件 | 模型 | 平均成本降低 | 文檔視覺問答 1680W x 2240H 64/128 延遲 (s) |
文檔視覺問答 1680W x 2240H 64/128 每美元查詢數 |
視覺推理 640W x 480H 128/128 延遲 (s) |
視覺推理 640W x 480H 128/128 每美元查詢數 |
圖像描述 480W x 360H 0/128 延遲 (s) |
圖像描述 480W x 360H 0/128 每美元查詢數 |
---|---|---|---|---|---|---|---|---|
A6000x1 | Qwen/Qwen2.5-VL-3B-Instruct | 3.1 | 1454 | 1.8 | 2546 | 1.7 | 2610 | |
A6000x1 | neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w8a8 | 1.27 | 2.6 | 1708 | 1.3 | 3340 | 1.3 | 3459 |
A6000x1 | neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w4a16 | 1.57 | 2.4 | 1886 | 1.0 | 4409 | 1.0 | 4409 |
A100x1 | Qwen/Qwen2.5-VL-3B-Instruct | 2.2 | 920 | 1.3 | 1603 | 1.2 | 1636 | |
A100x1 | neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w8a8 | 1.09 | 2.1 | 975 | 1.2 | 1743 | 1.1 | 1814 |
A100x1 | neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w4a16 | 1.20 | 2.0 | 1011 | 1.0 | 2015 | 1.0 | 2012 |
H100x1 | Qwen/Qwen2.5-VL-3B-Instruct | 1.5 | 740 | 0.9 | 1221 | 0.9 | 1276 | |
H100x1 | neuralmagic/Qwen2.5-VL-3B-Instruct-FP8-Dynamic | 1.06 | 1.4 | 768 | 0.9 | 1276 | 0.8 | 1399 |
H100x1 | neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w4a16 | 1.24 | 0.9 | 1219 | 0.9 | 1270 | 0.8 | 1304 |
使用場景配置文件:圖像尺寸 (WxH) / 提示詞令牌 / 生成令牌
QPD:每美元查詢數,基於 Lambda Labs 的按需成本(2025 年 2 月 18 日觀察)。
多流異步性能(使用 vLLM 版本 0.7.2 測量)
硬件 | 模型 | 平均成本降低 | 文檔視覺問答 1680W x 2240H 64/128 最大吞吐量 (QPS) |
文檔視覺問答 1680W x 2240H 64/128 每美元查詢數 |
視覺推理 640W x 480H 128/128 最大吞吐量 (QPS) |
視覺推理 640W x 480H 128/128 每美元查詢數 |
圖像描述 480W x 360H 0/128 最大吞吐量 (QPS) |
圖像描述 480W x 360H 0/128 每美元查詢數 |
---|---|---|---|---|---|---|---|---|
A6000x1 | Qwen/Qwen2.5-VL-3B-Instruct | 0.5 | 2405 | 2.6 | 11889 | 2.9 | 12909 | |
A6000x1 | neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w8a8 | 1.26 | 0.6 | 2725 | 3.4 | 15162 | 3.9 | 17673 |
A6000x1 | neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w4a16 | 1.39 | 0.6 | 2548 | 3.9 | 17437 | 4.7 | 21223 |
A100x1 | Qwen/Qwen2.5-VL-3B-Instruct | 0.8 | 1663 | 3.9 | 7899 | 4.4 | 8924 | |
A100x1 | neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w8a8 | 1.06 | 0.9 | 1734 | 4.2 | 8488 | 4.7 | 9548 |
A100x1 | neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w4a16 | 1.10 | 0.9 | 1775 | 4.2 | 8540 | 5.1 | 10318 |
H100x1 | Qwen/Qwen2.5-VL-3B-Instruct | 1.1 | 1188 | 4.3 | 4656 | 4.3 | 4676 | |
H100x1 | neuralmagic/Qwen2.5-VL-3B-Instruct-FP8-Dynamic | 1.15 | 1.4 | 1570 | 4.3 | 4676 | 4.8 | 5220 |
H100x1 | neuralmagic/Qwen2.5-VL-3B-Instruct-quantized.w4a16 | 1.96 | 4.2 | 4598 | 4.1 | 4505 | 4.4 | 4838 |
使用場景配置文件:圖像尺寸 (WxH) / 提示詞令牌 / 生成令牌
QPS:每秒查詢數。
QPD:每美元查詢數,基於 Lambda Labs 的按需成本(2025 年 2 月 18 日觀察)。
📄 許可證
本項目採用 Apache-2.0 許可證。
Clip Vit Large Patch14 336
基於Vision Transformer架構的大規模視覺語言預訓練模型,支持圖像與文本的跨模態理解
文本生成圖像
Transformers

C
openai
5.9M
241
Fashion Clip
MIT
FashionCLIP是基於CLIP開發的視覺語言模型,專門針對時尚領域進行微調,能夠生成通用產品表徵。
文本生成圖像
Transformers English

F
patrickjohncyh
3.8M
222
Gemma 3 1b It
Gemma 3是Google推出的輕量級先進開放模型系列,基於與Gemini模型相同的研究和技術構建。該模型是多模態模型,能夠處理文本和圖像輸入並生成文本輸出。
文本生成圖像
Transformers

G
google
2.1M
347
Blip Vqa Base
Bsd-3-clause
BLIP是一個統一的視覺語言預訓練框架,擅長視覺問答任務,通過語言-圖像聯合訓練實現多模態理解與生成能力
文本生成圖像
Transformers

B
Salesforce
1.9M
154
CLIP ViT H 14 Laion2b S32b B79k
MIT
基於OpenCLIP框架在LAION-2B英文數據集上訓練的視覺-語言模型,支持零樣本圖像分類和跨模態檢索任務
文本生成圖像
Safetensors
C
laion
1.8M
368
CLIP ViT B 32 Laion2b S34b B79k
MIT
基於OpenCLIP框架在LAION-2B英語子集上訓練的視覺-語言模型,支持零樣本圖像分類和跨模態檢索
文本生成圖像
Safetensors
C
laion
1.1M
112
Pickscore V1
PickScore v1 是一個針對文本生成圖像的評分函數,可用於預測人類偏好、評估模型性能和圖像排序等任務。
文本生成圖像
Transformers

P
yuvalkirstain
1.1M
44
Owlv2 Base Patch16 Ensemble
Apache-2.0
OWLv2是一種零樣本文本條件目標檢測模型,可通過文本查詢在圖像中定位對象。
文本生成圖像
Transformers

O
google
932.80k
99
Llama 3.2 11B Vision Instruct
Llama 3.2 是 Meta 發佈的多語言多模態大型語言模型,支持圖像文本到文本的轉換任務,具備強大的跨模態理解能力。
文本生成圖像
Transformers Supports Multiple Languages

L
meta-llama
784.19k
1,424
Owlvit Base Patch32
Apache-2.0
OWL-ViT是一個零樣本文本條件目標檢測模型,可以通過文本查詢搜索圖像中的對象,無需特定類別的訓練數據。
文本生成圖像
Transformers

O
google
764.95k
129
Featured Recommended AI Models
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers Supports Multiple Languages

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers English

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 Chinese
R
uer
2,694
98