YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Qwen2.5-VL-1B-Instruct-Custom
一个轻量级视觉语言对话模型,基于Qwen2.5架构进行深度定制优化,在仅1B参数规模下实现高效的图文理解与对话能力。
模型概述
Qwen2.5-VL-1B-Instruct-Custom 是通过对Qwen2.5-VL-3B-Instruct进行架构级轻量化改造而构建的定制化视觉语言模型。该模型保留了原始模型的高性能ViT视觉编码器,同时将LLM模块替换为更轻量的Qwen2.5-0.5B-Instruct,并重新设计MLP层尺寸以实现模块间的最优适配。经过多阶段渐进式训练,模型在保持基础图文对话能力的同时,显著降低了资源消耗,特别适合边缘设备部署和资源受限场景。
核心特点
- 极致轻量:总参数量约1B,仅为原始Qwen2.5-VL-3B的1/3
- 架构定制:ViT (630M) + LLM (0.5B) + 重设计MLP的混合架构
- 渐进训练:三阶段解冻策略确保各模块充分优化
- 开源友好:完全开源,支持社区二次开发与商业应用
- 生态兼容:支持vLLM推理框架,使用方式与Qwen2.5-VL系列一致
模型架构
架构组成
| 组件 | 来源 | 说明 |
|---|---|---|
| 视觉编码器 (ViT) | naViT(630M), 源自Qwen2.5-VL-3B-Instruct | 完整保留原始ViT架构,确保视觉特征提取能力 |
| 语言模型 (LLM) | Qwen2.5-0.5B-Instruct | 替换为轻量级LLM,大幅降低参数量 |
| MLP投影层 | 修改merger的第二层linear参数 | 调整尺寸以适配ViT输出与LLM输入的维度对齐 |
| 总参数量 | - | 约1B (ViT部分约0.6B + LLM约0.5B + MLP及其他) |
架构优势
- 视觉能力保留:继承3B版本的ViT,视觉理解能力损失极小
- 推理效率提升:LLM部分大幅精简,生成速度显著提高,沿用Qwen2.5系列的LLM,更易对齐
- 内存友好:单卡4GB显存即可完成推理,支持消费级GPU部署
- 模块解耦:便于后续针对特定场景进行模块级优化
训练方法
三阶段渐进式训练策略
为确保轻量化架构的稳定收敛,采用分阶段解冻训练方案:
阶段一:MLP激活训练
- 训练参数:仅MLP投影层
- 冻结模块:ViT编码器 + LLM主体
- 训练目标:建立视觉特征到语言空间的稳定映射
阶段二:LLM微调
- 训练参数:MLP + LLM全部参数
- 冻结模块:ViT编码器
- 训练目标:优化语言理解与生成能力,适配视觉特征分布
阶段三:全参数微调
- 训练参数:整个网络(ViT + MLP + LLM)
- 训练目标:端到端联合优化,提升整体性能至收敛
训练数据
模型在多个高质量开源VQA数据集上进行混合训练:
| 数据集 | 样本量 | 说明 |
|---|---|---|
| llava-150k-instruct | 15w | |
| webui-ocr-zh | 2.7w | |
| mscoco | ||
| rlaif-v-dataset | ||
| VisualTableQA | ||
| DocVAQ | ||
| pixmo_docs | 25w |
快速开始
使用方式
import torch
from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
from qwen_vl_utils import process_vision_info
model_path = '/path/to/model/Qwen2.5-VL-1B-Instruct-Custom'
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(model_path,
torch_dtype='bfloat16',
device_map='auto',
trust_remote_code=True)
processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True)
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)
- Downloads last month
- 12
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support