Qwen2-VL-72B-Instruct-AWQ:多模态大模型,支持图像视频理解、多语言及设备交互,AWQ量化高效部署

探索未来,Qwen2-VL-72B-Instruct-AWQ让视觉与文本无缝融合!这款强大的多模态模型精通图像理解,能处理长视频,还能根据视觉环境进行复杂决策,操作手机、机器人等设备。全球用户皆可享受其跨语言文本理解能力,开启智能新纪元。

分支1Tags0
712d5a5a创建于 2024年9月25日8次提交
文件最后提交记录最后更新时间
fix(pad zero) pad intermediate_size to 29696 to make sure quantized model can use 8 tensor-parallel in vllm 1 年前
Create LICENSE1 年前
Update README.md1 年前
Upload folder using huggingface_hub1 年前
Upload folder using huggingface_hub1 年前
fix(pad zero) pad intermediate_size to 29696 to make sure quantized model can use 8 tensor-parallel in vllm 1 年前
fix(pad zero) pad intermediate_size to 29696 to make sure quantized model can use 8 tensor-parallel in vllm 1 年前
Upload folder using huggingface_hub1 年前
fix(ckpt) fix corrupted ckpt file 1 年前
fix(pad zero) pad intermediate_size to 29696 to make sure quantized model can use 8 tensor-parallel in vllm 1 年前
fix(pad zero) pad intermediate_size to 29696 to make sure quantized model can use 8 tensor-parallel in vllm 1 年前
fix(pad zero) pad intermediate_size to 29696 to make sure quantized model can use 8 tensor-parallel in vllm 1 年前
fix(pad zero) pad intermediate_size to 29696 to make sure quantized model can use 8 tensor-parallel in vllm 1 年前
fix(pad zero) pad intermediate_size to 29696 to make sure quantized model can use 8 tensor-parallel in vllm 1 年前
fix(pad zero) pad intermediate_size to 29696 to make sure quantized model can use 8 tensor-parallel in vllm 1 年前
fix(pad zero) pad intermediate_size to 29696 to make sure quantized model can use 8 tensor-parallel in vllm 1 年前
fix(pad zero) pad intermediate_size to 29696 to make sure quantized model can use 8 tensor-parallel in vllm 1 年前
fix(pad zero) pad intermediate_size to 29696 to make sure quantized model can use 8 tensor-parallel in vllm 1 年前
fix(pad zero) pad intermediate_size to 29696 to make sure quantized model can use 8 tensor-parallel in vllm 1 年前
fix(pad zero) pad intermediate_size to 29696 to make sure quantized model can use 8 tensor-parallel in vllm 1 年前
Upload folder using huggingface_hub1 年前
Upload folder using huggingface_hub1 年前
Upload folder using huggingface_hub1 年前
Upload folder using huggingface_hub1 年前
Upload folder using huggingface_hub1 年前

license: other license_name: tongyi-qianwen license_link: https://huggingface.co/Qwen/Qwen2-VL-72B-Instruct-AWQ/blob/main/LICENSE language:

  • en pipeline_tag: image-text-to-text tags:
  • multimodal base_model: Qwen/Qwen2-VL-72B-Instruct

Qwen2-VL-72B-Instruct-AWQ

简介

我们很高兴推出 Qwen2-VL,这是我们 Qwen-VL 模型的最新版本,代表了将近一年的创新成果。

Qwen2-VL 的新特性

主要增强功能:

  • 对各种分辨率与比例图像的顶尖理解能力:Qwen2-VL 在视觉理解基准测试中达到了最先进的性能,包括 MathVista、DocVQA、RealWorldQA、MTVQA 等。

  • 理解超过 20 分钟的视频:Qwen2-VL 能够理解超过 20 分钟的视频,用于高质量的视频问答、对话、内容创作等。

  • 可操作移动设备、机器人等的智能体:凭借复杂推理和决策能力,Qwen2-VL 可以与手机、机器人等设备集成,根据视觉环境和文本指令进行自动操作。

  • 多语言支持:为了服务全球用户,除了英语和中文,Qwen2-VL 现在还支持理解图像中的多种语言文本,包括大多数欧洲语言、日语、韩语、阿拉伯语、越南语等。

模型架构更新:

  • 朴素动态分辨率:与之前不同,Qwen2-VL 可以处理任意图像分辨率,将其映射为动态数量的视觉标记,提供更接近人类的视觉处理体验。

  • 多模态旋转位置嵌入(M-ROPE):将位置嵌入分解为多个部分,以捕捉 1D 文本、2D 视觉和 3D 视频的位置信息,增强了其多模态处理能力。

我们提供了三种不同参数规模的模型,分别是 20 亿、80 亿和 720 亿参数。本仓库包含经过量化指令微调的 720 亿参数 Qwen2-VL 模型。更多信息,请访问我们的 博客GitHub

基准测试

量化模型的性能

本节报告了 Qwen2-VL 系列量化模型(包括 GPTQ 和 AWQ)的生成性能。具体来说,我们报告了:

  • MMMU_VAL(准确率)
  • DocVQA_VAL(准确率)
  • MMBench_DEV_EN(准确率)
  • MathVista_MINI(准确率)

我们使用 VLMEvalkit 评估所有模型。

模型规模 量化方式 MMMU DocVQA MMBench MathVista
Qwen2-VL-72B-Instruct BF16
(🤗🤖)
65.44 95.79 86.94 70.19
GPTQ-Int8
(🤗🤖)
64.56 95.84 87.03 68.90
GPTQ-Int4
(🤗🤖)
64.00 95.70 86.68 69.20
AWQ
(🤗🤖)
64.22 95.72 86.43 68.40

速度基准测试

本节报告了 Qwen2-VL 系列 bf16 模型和量化模型(包括 GPTQ-Int4、GPTQ-Int8 和 AWQ)的速度性能。具体来说,我们报告了在不同上下文长度条件下的推理速度(tokens/s)以及内存占用(GB)。

评估环境为:

  • NVIDIA A100 80GB
  • CUDA 11.8
  • Pytorch 2.2.1+cu118
  • Flash Attention 2.6.1
  • Transformers 4.38.2
  • AutoGPTQ 0.6.0+cu118
  • AutoAWQ 0.2.5+cu118 (autoawq_kernels 0.0.6+cu118)

注意:

  • 我们使用批量大小为 1,并尽可能使用最少的 GPU 进行评估。

  • 我们测试了生成 2048 个 tokens 的速度和内存占用,输入长度分别为 1、6144、14336、30720、63488 和 129024 tokens(>32k 仅适用于 Qwen2-72B-Instuct 和 Qwen2-7B-Instuct)。

  • Qwen2-VL-72B (transformers)

模型 输入长度 量化方式 GPU 数量 速度(tokens/s) GPU 内存(GB)
Qwen2-VL-72B-Instruct 1 BF16 2 8.90 138.74
GPTQ-Int8 2 9.53 75.173
GPTQ-Int4 1 11.04 42.46
AWQ 1 12.00 41.98
6144 BF16 2 6.53 148.66
GPTQ-Int8 2 6.97 85.09
GPTQ-Int4 1 7.62 49.05
AWQ 1 8.33 48.58
14336 BF16 3 4.39 165.92
GPTQ-Int8 2 5.04 99.31
GPTQ-Int4 1 5.39 58.76
AWQ 1 5.72 58.29
30720 BF16 4 2.93 204.33
GPTQ-Int8 2 3.16 127.77
GPTQ-Int4 2 3.27 85.13
AWQ 2 3.39 94.65

环境要求

Qwen2-VL 的代码已包含在最新的 Hugging Face transformers 中,我们建议您通过命令 pip install git+https://github.com/huggingface/transformers 从源码构建,否则可能会遇到以下错误:

KeyError: 'qwen2_vl'

快速入门

我们提供了一套工具包,旨在帮助您更方便地处理各种类型的视觉输入。这包括base64、URLs以及交错的图片和视频。您可以使用以下命令进行安装:

pip install qwen-vl-utils

以下代码片段展示了如何结合使用 transformersqwen_vl_utils 来调用聊天模型:

from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
from qwen_vl_utils import process_vision_info

# default: Load the model on the available device(s)
model = Qwen2VLForConditionalGeneration.from_pretrained(
    "Qwen/Qwen2-VL-72B-Instruct-AWQ", torch_dtype="auto", device_map="auto"
)

# We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.
# model = Qwen2VLForConditionalGeneration.from_pretrained(
#     "Qwen/Qwen2-VL-72B-Instruct-AWQ",
#     torch_dtype=torch.bfloat16,
#     attn_implementation="flash_attention_2",
#     device_map="auto",
# )

# default processer
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-72B-Instruct-AWQ")

# The default range for the number of visual tokens per image in the model is 4-16384. You can set min_pixels and max_pixels according to your needs, such as a token count range of 256-1280, to balance speed and memory usage.
# min_pixels = 256*28*28
# max_pixels = 1280*28*28
# processor = AutoProcessor.from_pretrained("Qwen/Qwen2-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": "Describe this image."},
        ],
    }
]

# Preparation for inference
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")

# Inference: Generation of the output
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)
没有qwen_vl_utils
from PIL import Image
import requests
import torch
from torchvision import io
from typing import Dict
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor

# Load the model in half-precision on the available device(s)
model = Qwen2VLForConditionalGeneration.from_pretrained(
    "Qwen/Qwen2-VL-72B-Instruct-AWQ", torch_dtype="auto", device_map="auto"
)
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-72B-Instruct-AWQ")

# Image
url = "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"
image = Image.open(requests.get(url, stream=True).raw)

conversation = [
    {
        "role": "user",
        "content": [
            {
                "type": "image",
            },
            {"type": "text", "text": "Describe this image."},
        ],
    }
]


# Preprocess the inputs
text_prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
# Excepted output: '<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n<|vision_start|><|image_pad|><|vision_end|>Describe this image.<|im_end|>\n<|im_start|>assistant\n'

inputs = processor(
    text=[text_prompt], images=[image], padding=True, return_tensors="pt"
)
inputs = inputs.to("cuda")

# Inference: Generation of the output
output_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids = [
    output_ids[len(input_ids) :]
    for input_ids, output_ids in zip(inputs.input_ids, output_ids)
]
output_text = processor.batch_decode(
    generated_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True
)
print(output_text)
多图像推理
# Messages containing multiple images and a text query
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."},
        ],
    }
]

# Preparation for inference
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")

# Inference
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 containing a images list as a video and a text query
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",
                ],
                "fps": 1.0,
            },
            {"type": "text", "text": "Describe this video."},
        ],
    }
]
# Messages containing a video and a text query
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."},
        ],
    }
]

# Preparation for inference
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")

# Inference
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)
批量推理
# Sample messages for batch inference
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?"},
]
# Combine messages for batch processing
messages = [messages1, messages1]

# Preparation for batch inference
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")

# Batch Inference
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)

更多使用技巧

对于输入的图片,我们支持本地文件、base64 编码以及 URL 链接。而对于视频,目前我们仅支持本地文件。

# You can directly insert a local file path, a URL, or a base64-encoded image into the position where you want in the text.
## Local file path
messages = [
    {
        "role": "user",
        "content": [
            {"type": "image", "image": "file:///path/to/your/image.jpg"},
            {"type": "text", "text": "Describe this image."},
        ],
    }
]
## Image URL
messages = [
    {
        "role": "user",
        "content": [
            {"type": "image", "image": "http://path/to/your/image.jpg"},
            {"type": "text", "text": "Describe this image."},
        ],
    }
]
## Base64 encoded image
messages = [
    {
        "role": "user",
        "content": [
            {"type": "image", "image": "data:image;base64,/9j/..."},
            {"type": "text", "text": "Describe this image."},
        ],
    }
]

图像分辨率对性能提升的影响

该模型支持多种分辨率输入。默认情况下,它采用原生分辨率作为输入,但更高的分辨率可以在增加计算成本的同时提升性能。用户可以根据需求设置像素的最小和最大值,以实现最佳配置,例如设置256-1280的token数量范围,从而在速度和内存使用之间取得平衡。

min_pixels = 256 * 28 * 28
max_pixels = 1280 * 28 * 28
processor = AutoProcessor.from_pretrained(
    "Qwen/Qwen2-VL-72B-Instruct-AWQ", min_pixels=min_pixels, max_pixels=max_pixels
)

除此之外,我们提供了两种精细控制输入模型图像大小的方法:

  1. 定义min_pixelsmax_pixels:图像将被调整大小以保持其在min_pixelsmax_pixels范围内的长宽比。

  2. 指定确切尺寸:直接设置resized_heightresized_width。这些值将被四舍五入到最接近的28的倍数。

# min_pixels and 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 and 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."},
        ],
    }
]

局限性

尽管 Qwen2-VL 适用于多种视觉任务,但了解其局限性同样重要。以下是一些已知的限制:

  1. 缺乏音频支持:当前模型无法理解视频中的音频信息
  2. 数据时效性:我们的图像数据集更新至2023年6月,此日期之后的信息可能未涵盖。
  3. 个体与知识产权(IP)识别的局限性:模型在识别特定个体或知识产权方面的能力有限,可能无法全面覆盖所有知名人物或品牌。
  4. 复杂指令处理能力有限:面对复杂的多步骤指令时,模型的理解和执行能力有待提升。
  5. 计数准确性不足:特别是在复杂场景中,对象计数的准确性不高,需要进一步改进。
  6. 空间推理能力较弱:尤其是在三维空间中,模型对物体位置关系的推理能力不足,难以精确判断物体间的相对位置。

这些局限性为模型的持续优化和改进提供了方向,我们将致力于不断提升模型的性能和应用范围。

引用

如果您发现我们的工作对您有帮助,欢迎引用。

@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}
}
# 专业翻译服务

## 服务概述
我们提供高质量的文本翻译服务,旨在满足不同领域的专业需求。无论是技术文档、法律文件还是市场营销材料,我们的团队都能确保翻译的准确性和流畅性。

## 服务特点
- **通俗易懂**:我们致力于将复杂的术语转化为易于理解的语言,确保信息传递的清晰性。
- **专业精准**:我们的翻译团队由经验丰富的专业人士组成,能够准确传达原文的专业性和严谨性。
- **优雅流畅**:我们注重语言的优美和表达的流畅性,使翻译文本不仅准确,而且具有良好的阅读体验。

## 服务流程
1. **需求分析**:与客户沟通,了解翻译的具体需求和目标。
2. **文本评估**:对原文进行详细分析,确定翻译的难度和所需时间。
3. **翻译执行**:由专业翻译人员进行文本翻译,确保质量。
4. **校对审核**:经过多轮校对和审核,确保翻译的准确性和一致性。
5. **交付反馈**:将最终翻译文本交付给客户,并收集反馈以持续改进服务质量。

## 适用领域
- **技术文档**:包括用户手册、技术规范、软件本地化等。
- **法律文件**:如合同、协议、诉讼文件等。
- **市场营销**:广告文案、产品介绍、品牌故事等。
- **医学与生命科学**:研究报告、临床试验、药品说明书等。

## 联系我们
如有任何翻译需求或疑问,请随时联系我们的客户服务团队。我们期待为您提供卓越的翻译服务体验。

项目介绍

探索未来,Qwen2-VL-72B-Instruct-AWQ让视觉与文本无缝融合!这款强大的多模态模型精通图像理解,能处理长视频,还能根据视觉环境进行复杂决策,操作手机、机器人等设备。全球用户皆可享受其跨语言文本理解能力,开启智能新纪元。

定制我的领域

下载使用量

0

项目总下载次数(含Clone、Pull、 zip 包及 release 下载),每日凌晨更新