Qwen2.5 VL 7B Instruct Quantized.w4a16
Qwen2.5-VL-7B-Instruct的量化版本,支持视觉-文本输入和文本输出,权重量化为INT4,激活量化为FP16。
下载量 605
发布时间 : 2/7/2025
模型简介
这是一个基于Qwen/Qwen2.5-VL-7B-Instruct的量化模型,专为高效推理而优化,适用于多模态任务。
模型特点
高效量化
权重量化为INT4,激活量化为FP16,显著减少模型大小和推理成本
多模态支持
支持视觉和文本输入,能够理解和生成与图像相关的文本内容
vLLM优化
专为vLLM推理引擎优化,支持高效部署
模型能力
视觉问答
图像描述生成
多模态对话
文档理解
使用案例
视觉问答
图像内容理解
回答关于图像内容的自然语言问题
在VQAv2数据集上达到73.90%准确率
文档处理
文档问答
从扫描文档或PDF中提取信息并回答问题
在DocVQA数据集上达到94.13% ANLS分数
🚀 Qwen2.5-VL-7B-Instruct-quantized-w4a16
这是 Qwen/Qwen2.5-VL-7B-Instruct 的量化版本,通过将权重量化为 INT4 数据类型,可使用 vLLM >= 0.5.2 进行高效推理。
🚀 快速开始
本模型可以使用 vLLM 后端进行高效部署,示例代码如下:
from vllm.assets.image import ImageAsset
from vllm import LLM, SamplingParams
# prepare model
llm = LLM(
model="neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w4a16",
trust_remote_code=True,
max_model_len=4096,
max_num_seqs=2,
)
# prepare inputs
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")
},
}
# generate response
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-7B-Instruct,输入为视觉 - 文本,输出为文本。
- 模型优化:权重量化为 INT4,激活量化为 FP16,可使用 vLLM >= 0.5.2 进行推理。
- 发布日期:2025 年 2 月 24 日
- 版本:1.0
- 模型开发者:Neural Magic
📦 安装指南
文档未提供具体安装步骤,暂不展示。
💻 使用示例
基础用法
from vllm.assets.image import ImageAsset
from vllm import LLM, SamplingParams
# prepare model
llm = LLM(
model="neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w4a16",
trust_remote_code=True,
max_model_len=4096,
max_num_seqs=2,
)
# prepare inputs
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")
},
}
# generate response
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
# Load model.
model_id = "Qwen/Qwen2.5-VL-7B-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)
# Oneshot arguments
DATASET_ID = "lmms-lab/flickr30k"
DATASET_SPLIT = {"calibration": "test[:512]"}
NUM_CALIBRATION_SAMPLES = 512
MAX_SEQUENCE_LENGTH = 2048
# Load dataset and preprocess.
ds = load_dataset(DATASET_ID, split=DATASET_SPLIT)
ds = ds.shuffle(seed=42)
dampening_frac=0.01
# Apply chat template and tokenize inputs.
def preprocess_and_tokenize(example):
# preprocess
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)
# tokenize
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)
# Define a oneshot data collator for multimodal inputs.
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"
# Perform oneshot
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-7B-Instruct | Qwen2.5-VL-7B-Instruct-quantized.W4A16 | 恢复率 (%) |
---|---|---|---|---|
视觉 | MMMU (val, CoT) explicit_prompt_relaxed_correctness |
52.00 | 51.11 | 98.29% |
视觉 | VQAv2 (val) vqa_match |
75.59 | 73.90 | 97.76% |
视觉 | DocVQA (val) anls |
94.27 | 94.13 | 99.85% |
视觉 | ChartQA (test, CoT) anywhere_in_answer_relaxed_correctness |
86.44 | 85.64 | 99.07% |
视觉 | Mathvista (testmini, CoT) explicit_prompt_relaxed_correctness |
69.47 | 67.17 | 96.69% |
视觉 | 平均得分 | 75.95 | 74.79 | 98.47% |
文本 | MGSM (CoT) | 56.38 | 51.89 | 92.04% |
文本 | MMLU (5-shot) | 71.09 | 68.67 | 96.59% |
推理性能
本模型在单流部署中可实现高达 2.35 倍的加速,在多流异步部署中可实现高达 2.02 倍的加速,具体取决于硬件和使用场景。以下性能基准测试使用 vLLM 版本 0.7.2 和 GuideLLM 进行。
基准测试命令
``` guidellm --model neuralmagic/Qwen2.5-VL-7B-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-7B-Instruct | 4.9 | 912 | 3.2 | 1386 | 3.1 | 1431 | |
A6000x1 | neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w8a8 | 1.50 | 3.6 | 1248 | 2.1 | 2163 | 2.0 | 2237 |
A6000x1 | neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w4a16 | 2.05 | 3.3 | 1351 | 1.4 | 3252 | 1.4 | 3321 |
A100x1 | Qwen/Qwen2.5-VL-7B-Instruct | 2.8 | 707 | 1.7 | 1162 | 1.7 | 1198 | |
A100x1 | neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w8a8 | 1.24 | 2.4 | 851 | 1.4 | 1454 | 1.3 | 1512 |
A100x1 | neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w4a16 | 1.49 | 2.2 | 912 | 1.1 | 1791 | 1.0 | 1950 |
H100x1 | Qwen/Qwen2.5-VL-7B-Instruct | 2.0 | 557 | 1.2 | 919 | 1.2 | 941 | |
H100x1 | neuralmagic/Qwen2.5-VL-7B-Instruct-FP8-Dynamic | 1.28 | 1.6 | 698 | 0.9 | 1181 | 0.9 | 1219 |
H100x1 | neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w4a16 | 1.28 | 1.6 | 686 | 0.9 | 1191 | 0.9 | 1228 |
**用例配置文件:图像大小 (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-7B-Instruct | 0.4 | 1837 | 1.5 | 6846 | 1.7 | 7638 | |
A6000x1 | neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w8a8 | 1.41 | 0.5 | 2297 | 2.3 | 10137 | 2.5 | 11472 |
A6000x1 | neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w4a16 | 1.60 | 0.4 | 1828 | 2.7 | 12254 | 3.4 | 15477 |
A100x1 | Qwen/Qwen2.5-VL-7B-Instruct | 0.7 | 1347 | 2.6 | 5221 | 3.0 | 6122 | |
A100x1 | neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w8a8 | 1.27 | 0.8 | 1639 | 3.4 | 6851 | 3.9 | 7918 |
A100x1 | neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w4a16 | 1.21 | 0.7 | 1314 | 3.0 | 5983 | 4.6 | 9206 |
H100x1 | Qwen/Qwen2.5-VL-7B-Instruct | 0.9 | 969 | 3.1 | 3358 | 3.3 | 3615 | |
H100x1 | neuralmagic/Qwen2.5-VL-7B-Instruct-FP8-Dynamic | 1.29 | 1.2 | 1331 | 3.8 | 4109 | 4.2 | 4598 |
H100x1 | neuralmagic/Qwen2.5-VL-7B-Instruct-quantized.w4a16 | 1.28 | 1.2 | 1298 | 3.8 | 4190 | 4.2 | 4573 |
**用例配置文件:图像大小 (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 英语

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 支持多种语言

L
meta-llama
784.19k
1,424
Owlvit Base Patch32
Apache-2.0
OWL-ViT是一个零样本文本条件目标检测模型,可以通过文本查询搜索图像中的对象,无需特定类别的训练数据。
文本生成图像
Transformers

O
google
764.95k
129
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers 支持多种语言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers 英语

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统 中文
R
uer
2,694
98
智启未来,您的人工智能解决方案智库
简体中文