模型简介
Qwen3-VL 是由阿里云 Qwen 团队开发的多模态大语言模型系列。其空间感知能力大幅提升,2D grounding 从绝对坐标变为相对坐标,支持判断物体方位、视角变化、遮挡关系,能实现 3D grounding。OCR 支持更多语言及复杂场景,覆盖范围扩展至 32 种语言。
主要技术改进包括:
- 采用 MRoPE-Interleave,原始 MRoPE 将特征维度按照时间(t)、高度(h)和宽度(w)的顺序分块划分,Qwen3-VL 采取 t,h,w 交错分布的形式,实现对时间、高度和宽度的全频率覆盖,提升对长视频的理解能力。
- 引入 DeepStack 技术,融合 ViT 多层次特征,提升视觉细节捕捉能力和图文对齐精度。将以往多模态大模型单层输入视觉 tokens 的范式,改为在大型语言模型 (LLM) 的多层中进行注入。
- 将原有的视频时序建模机制 T-RoPE 升级为文本时间戳对齐机制,实现帧级别的时间信息与视觉内容的细粒度对齐。
环境配置
conda create -n Qwen3-vl python=3.10
conda activate Qwen3-vl
pip install accelerate
pip install qwen-vl-utils==0.0.14
uv pip install -U vllm>=0.11.0
下载代码
git clone https://github.com/QwenLM/Qwen3-VL
下载权重文件
pip install modelscope
modelscope download --model Qwen/Qwen3-VL-2B-Instruct
推理代码
修改模型路径和图片地址后运行以下脚本:
from transformers import Qwen3VLForConditionalGeneration, AutoProcessor
import torch
from PIL import Image
def load_qwen3_vl_4b_model():
model = Qwen3VLForConditionalGeneration.from_pretrained(
"Qwen/Qwen3-VL-4B-Instruct",
torch_dtype=torch.bfloat16,
device_map="auto",
attn_implementation="flash_attention_2"
)
processor = AutoProcessor.from_pretrained("Qwen/Qwen3-VL-4B-Instruct")
return model, processor
def process_multimodal_query(model, processor, image_path, text_query):
image = Image.open(image_path).convert('RGB')
messages = [
{
"role": "user",
"content": [
{: , : image},
{: , : text_query}
]
}
]
inputs = processor.apply_chat_template(
messages, tokenize=, add_generation_prompt=, return_dict=, return_tensors=
)
generated_ids = model.generate(**inputs, max_new_tokens=, do_sample=, temperature=, top_p=)
generated_ids_trimmed = [out_ids[(in_ids):] in_ids, out_ids (inputs.input_ids, generated_ids)]
output_text = processor.batch_decode(generated_ids_trimmed, skip_special_tokens=, clean_up_tokenization_spaces=)
output_text[] output_text
__name__ == :
model, processor = load_qwen3_vl_4b_model()
image_path =
query =
result = process_multimodal_query(model, processor, image_path, query)
(, result)


