Views
No views yet
qwen3-vl-32b-instruct/
├── config.json # Model configuration
├── generation_config.json # Generation parameters
├── model-*.safetensors # Model weight shards (multiple files)
├── model.safetensors.index.json # Weight shard index
├── preprocessor_config.json # Preprocessing configuration
├── tokenizer.json # Tokenizer vocabulary
├── tokenizer_config.json # Tokenizer configuration
├── merges.txt # BPE merges
└── vocab.json # Vocabulary fileflash_attention_2 for better acceleration and memory savingtorch.bfloat16 or automatic dtype selection1pip install transformers accelerate torch pillow
2pip install flash-attn --no-build-isolation # Optional but recommended1from transformers import Qwen3VLForConditionalGeneration, AutoProcessor
2from PIL import Image
3import torch
4
5# Model path - update with your local path
6model_path = "E:/huggingface/qwen3-vl-32b-instruct"
7
8# Load model and processor
9model = Qwen3VLForConditionalGeneration.from_pretrained(
10 model_path,
11 torch_dtype=torch.bfloat16,
12 device_map="auto",
13 attn_implementation="flash_attention_2" # Recommended
14)
15
16processor = AutoProcessor.from_pretrained(model_path)
17
18# Example: Image understanding
19image = Image.open("path/to/your/image.jpg")
20messages = [
21 {
22 "role": "user",
23 "content": [
24 {"type": "image"},
25 {"type": "text", "text": "Describe this image in detail."}
26 ]
27 }
28]
29
30# Prepare inputs
31text = processor.apply_chat_template(messages, add_generation_prompt=True)
32inputs = processor(
33 text=[text],
34 images=[image],
35 return_tensors="pt",
36 padding=True
37)
38inputs = inputs.to(model.device)
39
40# Generate response
41output_ids = model.generate(
42 **inputs,
43 max_new_tokens=1024,
44 do_sample=False
45)
46
47# Decode output
48generated_text = processor.batch_decode(
49 output_ids,
50 skip_special_tokens=True,
51 clean_up_tokenization_spaces=False
52)[0]
53
54print(generated_text)1from transformers import Qwen3VLForConditionalGeneration, AutoProcessor
2import torch
3import cv2
4import numpy as np
5
6model_path = "E:/huggingface/qwen3-vl-32b-instruct"
7
8# Load model
9model = Qwen3VLForConditionalGeneration.from_pretrained(
10 model_path,
11 torch_dtype=torch.bfloat16,
12 device_map="auto",
13 attn_implementation="flash_attention_2"
14)
15
16processor = AutoProcessor.from_pretrained(model_path)
17
18# Load video frames
19def load_video_frames(video_path, max_frames=16):
20 cap = cv2.VideoCapture(video_path)
21 frames = []
22 total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
23 indices = np.linspace(0, total_frames - 1, max_frames, dtype=int)
24
25 for idx in indices:
26 cap.set(cv2.CAP_PROP_POS_FRAMES, idx)
27 ret, frame = cap.read()
28 if ret:
29 frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
30 frames.append(Image.fromarray(frame))
31
32 cap.release()
33 return frames
34
35# Process video
36video_frames = load_video_frames("path/to/video.mp4")
37
38messages = [
39 {
40 "role": "user",
41 "content": [
42 {"type": "video"},
43 {"type": "text", "text": "Summarize what happens in this video."}
44 ]
45 }
46]
47
48text = processor.apply_chat_template(messages, add_generation_prompt=True)
49inputs = processor(
50 text=[text],
51 videos=[video_frames],
52 return_tensors="pt"
53)
54inputs = inputs.to(model.device)
55
56# Generate
57output_ids = model.generate(
58 **inputs,
59 max_new_tokens=2048
60)
61
62response = processor.batch_decode(
63 output_ids,
64 skip_special_tokens=True
65)[0]
66
67print(response)1from transformers import Qwen3VLForConditionalGeneration, AutoProcessor
2from PIL import Image
3import torch
4
5model_path = "E:/huggingface/qwen3-vl-32b-instruct"
6
7model = Qwen3VLForConditionalGeneration.from_pretrained(
8 model_path,
9 torch_dtype=torch.bfloat16,
10 device_map="auto",
11 attn_implementation="flash_attention_2"
12)
13
14processor = AutoProcessor.from_pretrained(model_path)
15
16# Load multiple images
17images = [
18 Image.open("image1.jpg"),
19 Image.open("image2.jpg"),
20 Image.open("image3.jpg")
21]
22
23messages = [
24 {
25 "role": "user",
26 "content": [
27 {"type": "image"},
28 {"type": "image"},
29 {"type": "image"},
30 {"type": "text", "text": "Compare these three images and explain the differences."}
31 ]
32 }
33]
34
35text = processor.apply_chat_template(messages, add_generation_prompt=True)
36inputs = processor(
37 text=[text],
38 images=images,
39 return_tensors="pt"
40)
41inputs = inputs.to(model.device)
42
43output_ids = model.generate(**inputs, max_new_tokens=1024)
44response = processor.batch_decode(output_ids, skip_special_tokens=True)[0]
45
46print(response)1model = Qwen3VLForConditionalGeneration.from_pretrained(
2 model_path,
3 attn_implementation="flash_attention_2"
4)1model = Qwen3VLForConditionalGeneration.from_pretrained(
2 model_path,
3 torch_dtype=torch.bfloat16
4)1model = Qwen3VLForConditionalGeneration.from_pretrained(
2 model_path,
3 device_map="auto" # Automatic distribution across GPUs
4)model.gradient_checkpointing_enable()max_new_tokenstop_p and top_k for controlled generationdo_sample=True for more diverse outputs1@article{qwen3vl2025,
2 title={Qwen3-VL: The Most Powerful Vision-Language Model in the Qwen Series},
3 author={Qwen Team},
4 journal={arXiv preprint},
5 year={2025},
6 institution={Alibaba Cloud}
7}