Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/QwenLM/Qwen3-VL/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Qwen3-VL uses the transformers library for inference. This guide covers the basic setup and single-image inference.

Requirements

# Qwen3-VL requires transformers >= 4.57.0
pip install "transformers>=4.57.0"

Basic Inference

Loading the Model

from transformers import AutoModelForImageTextToText, AutoProcessor

# Load model with automatic device mapping
model = AutoModelForImageTextToText.from_pretrained(
    "Qwen/Qwen3-VL-235B-A22B-Instruct", 
    dtype="auto", 
    device_map="auto"
)

processor = AutoProcessor.from_pretrained("Qwen/Qwen3-VL-235B-A22B-Instruct")

Single Image Inference

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
inputs = processor.apply_chat_template(
    messages,
    tokenize=True,
    add_generation_prompt=True,
    return_dict=True,
    return_tensors="pt"
)
inputs = inputs.to(model.device)

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

Image Input Formats

Qwen3-VL supports multiple image input formats:
  • URL: "https://path/to/image.jpg"
  • Local file: "file:///path/to/image.jpg"
  • Base64: "data:image;base64,/9j/..."

Performance Optimization

We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.
import torch
from transformers import AutoModelForImageTextToText

model = AutoModelForImageTextToText.from_pretrained(
    "Qwen/Qwen3-VL-235B-A22B-Instruct",
    dtype=torch.bfloat16,
    attn_implementation="flash_attention_2",
    device_map="auto",
)

Installing Flash Attention 2

pip install -U flash-attn --no-build-isolation
Flash-Attention 2 requires:
  • Hardware compatible with Flash-Attention 2
  • Model loaded in torch.float16 or torch.bfloat16

Next Steps

Multi-Image Processing

Learn how to process multiple images in a single request

Video Processing

Process video inputs with frame sampling

Build docs developers (and LLMs) love