Qwen2.5-VL-32B: 更聪明、更轻量!

本文涉及的产品
模型在线服务 PAI-EAS,A10/V100等 500元 1个月
交互式建模 PAI-DSW,每月250计算时 3个月
模型训练 PAI-DLC,100CU*H 3个月
简介: 年前,阿里通义千问团队推出了 Qwen2.5-VL 系列模型,获得了社区的广泛关注和积极反馈。在 Qwen2.5-VL 系列的基础上,研究团队使用强化学习持续优化模型,并使用 Apache 2.0 协议开源 32B 这个备受喜爱的参数规模的新 VL 模型—— Qwen2.5-VL-32B-Instruct。相比此前发布的 Qwen2.5-VL 系列模型,本次推出的 32B 模型的特点如下:

00.引言

年前,阿里通义千问团队推出了 Qwen2.5-VL 系列模型,获得了社区的广泛关注和积极反馈。在 Qwen2.5-VL 系列的基础上,研究团队使用强化学习持续优化模型,并使用 Apache 2.0 协议开源 32B 这个备受喜爱的参数规模的新 VL 模型—— Qwen2.5-VL-32B-Instruct。相比此前发布的 Qwen2.5-VL 系列模型,本次推出的 32B 模型的特点如下:

  • 回复更符合人类主观偏好:调整了输出风格,使回答更加详细、格式更规范,并更符合人类偏好。
  • 数学推理能力:复杂数学问题求解的准确性显著提升。
  • 图像细粒度理解与推理:在图像解析、内容识别以及视觉逻辑推导等任务中表现出更强的准确性和细粒度分析能力。

01.性能表现

Qwen2.5-VL-32B与业内先进的同规模模型进行比较,包括近期推出的 Mistral-Small-3.1-24B 和 Gemma-3-27B-IT, Qwen2.5-VL-32B-Instruct 展现出了明显的优势,甚至超越了更大规模的 Qwen2-VL-72B-Instruct 模型。尤其是在多模态任务中,例如 MMMU、MMMU-Pro 和 MathVista,这些任务强调复杂的多步骤推理,Qwen2.5-VL-32B-Instruct 表现尤为突出。在注重主观用户体验评估的 MM-MT-Bench 基准测试中,该模型相较于其前代 Qwen2-VL-72B-Instruct 取得了显著进步。

除了在视觉能力上优秀,Qwen2.5-VL-32B-Instruct 在纯文本能力上也达到了同规模的最优表现。

关键词小编敲黑板:

  • 性能卓越的开源模型 :作为一款开源的32B参数模型,在中等规模模型中表现尤为突出,性能可媲美GPT-4o,超越近期发布的Mistral和Gemma等热门模型,堪称同类中的佼佼者。
  • 友好且灵活的开源协议 :采用Apache 2.0开源协议,赋予用户极大的自由度和灵活性,便于商业应用与二次开发,为开发者提供无忧的使用体验。
  • 强化学习驱动的显著提升 :通过前沿的强化学习技术,重点优化了用户的主观满意度以及数学推理能力,带来更智能、更贴心的交互体验,满足多样化需求。

02.使用transformers本地推理

Qwen2.5的推理代码已经合入官方transformers库

from modelscope import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessor
from qwen_vl_utils import process_vision_info
# default: Load the model on the available device(s)
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
 "Qwen/Qwen2.5-VL-32B-Instruct", 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 = Qwen2_5_VLForConditionalGeneration.from_pretrained(
# "Qwen/Qwen2.5-VL-32B-Instruct",
# torch_dtype=torch.bfloat16,
# attn_implementation="flash_attention_2",
# device_map="auto",
# )
# default processer
processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-32B-Instruct")
# 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 range of 256-1280, to balance performance and cost.
# 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."},
 ],
 }
]
# 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)

03.使用魔搭API-Inference直接调用

魔搭平台的API-Inference,也第一时间为Qwen2.5-VL系列模型提供了支持。魔搭的用户可通过API调用的方式,直接使用。具体API-Inference的使用方式可参见模型页面(例如 https://www.modelscope.cn/models/Qwen/Qwen2.5-VL-32B-Instruct)说明:

或者参见API-Inference文档:

https://www.modelscope.cn/docs/model-service/API-Inference/intro

这里以如下图片为例,调用API使用Qwen/Qwen2.5-VL-32B-Instruct模型。

from openai import OpenAI
client = OpenAI(
    api_key="<MODELSCOPE_SDK_TOKEN>", # ModelScope Token
    base_url="https://api-inference.modelscope.cn/v1"
)
response = client.chat.completions.create(
    model="Qwen/Qwen2.5-VL-32B-Instruct", # ModleScope Model-Id
    messages = [
        {
            "role": "user",
            "content": [
                {
                    "type": "image_url",
                    "image_url": {"url": "https://modelscope.oss-cn-beijing.aliyuncs.com/demo/images/bird-vl.jpg"}
                },
                {   "type": "text", 
                    "text": "Count the number of birds in the figure, including those that are only showing their heads. To ensure accuracy, first detect their key points, then give the total number."
                },
            ],
        }
    ],
    stream=True
    )
for chunk in response:
    print(chunk.choices[0].delta.content, end='', flush=True)

感谢阿里云百炼平台提供背后算力支持。

04.模型微调

我们介绍使用ms-swift对Qwen/Qwen2.5-VL-32B-Instruct进行微调。ms-swift是魔搭社区官方提供的大模型与多模态大模型训练部署框架。ms-swift开源地址:https://github.com/modelscope/ms-swift

我们将展示可运行的微调demo,并给出自定义数据集的格式。

在开始微调之前,请确保您的环境已准备妥当。

git clone https://github.com/modelscope/ms-swift.git
cd ms-swift
pip install -e .

图像OCR微调脚本如下。更多任务,包括视频微调、grounding任务微调,可以参考这里:https://github.com/modelscope/ms-swift/tree/main/examples/train/multimodal

MAX_PIXELS=1003520 \
CUDA_VISIBLE_DEVICES=0 \
swift sft \
    --model Qwen/Qwen2.5-VL-32B-Instruct \
    --dataset AI-ModelScope/LaTeX_OCR:human_handwrite#20000 \
    --train_type lora \
    --torch_dtype bfloat16 \
    --num_train_epochs 1 \
    --per_device_train_batch_size 1 \
    --per_device_eval_batch_size 1 \
    --learning_rate 1e-4 \
    --lora_rank 8 \
    --lora_alpha 32 \
    --target_modules all-linear \
    --freeze_vit true \
    --gradient_accumulation_steps 16 \
    --eval_steps 50 \
    --save_steps 50 \
    --save_total_limit 5 \
    --logging_steps 5 \
    --max_length 2048 \
    --output_dir output \
    --warmup_ratio 0.05 \
    --dataloader_num_workers 4

训练显存资源:

自定义数据集格式如下(system字段可选),只需要指定`--dataset <dataset_path>`即可:

{"messages": [{"role": "user", "content": "浙江的省会在哪?"}, {"role": "assistant", "content": "浙江的省会在杭州。"}]}
{"messages": [{"role": "user", "content": "<image><image>两张图片有什么区别"}, {"role": "assistant", "content": "前一张是小猫,后一张是小狗"}], "images": ["/xxx/x.jpg", "/xxx/x.png"]}
{"messages": [{"role": "system", "content": "你是个有用无害的助手"}, {"role": "user", "content": "<video>视频中是什么"}, {"role": "assistant", "content": "视频中是一只小狗在草地上奔跑"}], "videos": ["/xxx/x.mp4"]}

训练完成后,使用以下命令对训练时的验证集进行推理:

CUDA_VISIBLE_DEVICES=0 \
swift infer \
    --adapters output/vx-xxx/checkpoint-xxx \
    --stream false \
    --max_batch_size 1 \
    --load_data_args true \
    --max_new_tokens 2048

推送模型到ModelScope:

CUDA_VISIBLE_DEVICES=0 \
swift export \
    --adapters output/vx-xxx/checkpoint-xxx \
    --push_to_hub true \
    --hub_model_id '<your-model-id>' \
    --hub_token '<your-sdk-token>'

05.下一步计划

尽管 Qwen2.5-VL-32B 在强化学习框架下优化了主观体验和数学推理能力——这主要基于“快速思考”模式,但研究团队下一步研究将聚焦于长且有效的推理过程,以突破视觉模型在处理高度复杂、多步骤视觉推理任务中的边界。

点击链接,即可跳转模型链接~

通义千问 2.5-VL-32B-Instruct

目录
打赏
0
0
0
0
355
分享
相关文章
Qwen2.5-VL-32B:阿里开源多模态核弹!32B模型吊打自家72B,数学推理封神
阿里巴巴最新开源的Qwen2.5-VL-32B多模态模型,在数学推理、视觉问答等任务中超越前代72B版本,支持图像细粒度理解和复杂逻辑分析,已在HuggingFace开源。
545 0
Qwen2.5-VL-32B:阿里开源多模态核弹!32B模型吊打自家72B,数学推理封神
Qwen2.5-VL Cookbook来啦!手把手教你怎么用好视觉理解模型!
今天,Qwen团队发布了一系列展示 Qwen2.5-VL 用例的Notebook,包含本地模型和 API 的使用。
1946 22
深入剖析 Qwen2.5 - 32B 模型在 VLLM 上的单机三卡部署与运行
本文深入探讨了Qwen2.5 - 32B模型在VLLM框架上的部署过程,从模型下载、启动命令、资源占用分析到GPU资源分配及CUDA图应用,详述了大模型运行的挑战与优化策略,强调了硬件资源规划与技术调优的重要性。
4881 2
【新模型速递】PAI一键云上零门槛部署DeepSeek-V3-0324、Qwen2.5-VL-32B
PAI-Model Gallery 集成国内外 AI 开源社区中优质的预训练模型,涵盖了 LLM、AIGC、CV、NLP 等各个领域,用户可以通过 PAI 以零代码方式实现从训练到部署再到推理的全过程,获得更快、更高效、更便捷的 AI 开发和应用体验。 现阿里云PAI-Model Gallery已同步接入DeepSeek-V3-0324、Qwen2.5-VL-32B-Instruct两大新模型,提供企业级部署方案。
Qwen3开源发布:Think Deeper, Act Faster!社区推理、部署、微调、MCP调用实战教程来啦!
Qwen3开源发布:Think Deeper, Act Faster!社区推理、部署、微调、MCP调用实战教程来啦!
709 22
看听说写四维突破:Qwen2.5-Omni 端到端多模态模型开源!
今天,通义千问团队发布了 Qwen2.5-Omni,Qwen 模型家族中新一代端到端多模态旗舰模型。该模型专为全方位多模态感知设计,能够无缝处理文本、图像、音频和视频等多种输入形式,并通过实时流式响应同时生成文本与自然语音合成输出。
597 6
看听说写四维突破:Qwen2.5-Omni 端到端多模态模型开源!
Qwen2-VL微调实战:LaTex公式OCR识别任务(完整代码)
《SwanLab机器学习实战教程》推出了一项基于Qwen2-VL大语言模型的LaTeX OCR任务,通过指令微调实现多模态LLM的应用。本教程详述了环境配置、数据集准备、模型加载、SwanLab集成及微调训练等步骤,旨在帮助开发者轻松上手视觉大模型的微调实践。
魔搭社区模型速递(3.23-3.29)
🙋魔搭ModelScope本期社区进展:619个模型,93个数据集,151个创新应用,7篇内容。
139 4
魔搭社区模型速递(3.23-3.29)

热门文章

最新文章

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问