Views
No views yet
[!NOTE] Includes Unsloth chat template fixes!
Forllama.cpp, use--jinja
This repository contains an FP8 quantized version of the Qwen3-VL-30B-A3B-Instruct model. The quantization method is fine-grained fp8 quantization with block size of 128, and its performance metrics are nearly identical to those of the original BF16 model. Enjoy!



1# -*- coding: utf-8 -*-
2import torch
3from qwen_vl_utils import process_vision_info
4from transformers import AutoProcessor
5from vllm import LLM, SamplingParams
6
7import os
8os.environ['VLLM_WORKER_MULTIPROC_METHOD'] = 'spawn'
9
10def prepare_inputs_for_vllm(messages, processor):
11 text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
12 # qwen_vl_utils 0.0.14+ reqired
13 image_inputs, video_inputs, video_kwargs = process_vision_info(
14 messages,
15 image_patch_size=processor.image_processor.patch_size,
16 return_video_kwargs=True,
17 return_video_metadata=True
18 )
19 print(f"video_kwargs: {video_kwargs}")
20
21 mm_data = {}
22 if image_inputs is not None:
23 mm_data['image'] = image_inputs
24 if video_inputs is not None:
25 mm_data['video'] = video_inputs
26
27 return {
28 'prompt': text,
29 'multi_modal_data': mm_data,
30 'mm_processor_kwargs': video_kwargs
31 }
32
33
34if __name__ == '__main__':
35 # messages = [
36 # {
37 # "role": "user",
38 # "content": [
39 # {
40 # "type": "video",
41 # "video": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-VL/space_woaudio.mp4",
42 # },
43 # {"type": "text", "text": "这段视频有多长"},
44 # ],
45 # }
46 # ]
47
48 messages = [
49 {
50 "role": "user",
51 "content": [
52 {
53 "type": "image",
54 "image": "https://ofasys-multimodal-wlcb-3-toshanghai.oss-accelerate.aliyuncs.com/wpf272043/keepme/image/receipt.png",
55 },
56 {"type": "text", "text": "Read all the text in the image."},
57 ],
58 }
59 ]
60
61 # TODO: change to your own checkpoint path
62 checkpoint_path = "Qwen/Qwen3-VL-30B-A3B-Instruct-FP8"
63 processor = AutoProcessor.from_pretrained(checkpoint_path)
64 inputs = [prepare_inputs_for_vllm(message, processor) for message in [messages]]
65
66 llm = LLM(
67 model=checkpoint_path,
68 trust_remote_code=True,
69 gpu_memory_utilization=0.70,
70 enforce_eager=False,
71 tensor_parallel_size=torch.cuda.device_count(),
72 seed=0
73 )
74
75 sampling_params = SamplingParams(
76 temperature=0,
77 max_tokens=1024,
78 top_k=-1,
79 stop_token_ids=[],
80 )
81
82 for i, input_ in enumerate(inputs):
83 print()
84 print('=' * 40)
85 print(f"Inputs[{i}]: {input_['prompt']=!r}")
86 print('\n' + '>' * 40)
87
88 outputs = llm.generate(inputs, sampling_params=sampling_params)
89 for i, output in enumerate(outputs):
90 generated_text = output.outputs[0].text
91 print()
92 print('=' * 40)
93 print(f"Generated text: {generated_text!r}")1import time
2from PIL import Image
3from sglang import Engine
4from qwen_vl_utils import process_vision_info
5from transformers import AutoProcessor, AutoConfig
6
7if __name__ == "__main__":
8 # TODO: change to your own checkpoint path
9 checkpoint_path = "Qwen/Qwen3-VL-30B-A3B-Instruct-FP8"
10 processor = AutoProcessor.from_pretrained(checkpoint_path)
11
12 messages = [
13 {
14 "role": "user",
15 "content": [
16 {
17 "type": "image",
18 "image": "https://ofasys-multimodal-wlcb-3-toshanghai.oss-accelerate.aliyuncs.com/wpf272043/keepme/image/receipt.png",
19 },
20 {"type": "text", "text": "Read all the text in the image."},
21 ],
22 }
23 ]
24
25 text = processor.apply_chat_template(
26 messages,
27 tokenize=False,
28 add_generation_prompt=True
29 )
30
31 image_inputs, _ = process_vision_info(messages, image_patch_size=processor.image_processor.patch_size)
32
33 llm = Engine(
34 model_path=checkpoint_path,
35 enable_multimodal=True,
36 mem_fraction_static=0.8,
37 tp_size=torch.cuda.device_count(),
38 attention_backend="fa3"
39 )
40
41 start = time.time()
42 sampling_params = {"max_new_tokens": 1024}
43 response = llm.generate(prompt=text, image_data=image_inputs, sampling_params=sampling_params)
44 print(f"Response costs: {time.time() - start:.2f}s")
45 print(f"Generated text: {response['text']}")@misc{qwen3technicalreport,
title={Qwen3 Technical Report},
author={Qwen Team},
year={2025},
eprint={2505.09388},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2505.09388},
}
@article{Qwen2.5-VL,
title={Qwen2.5-VL Technical Report},
author={Bai, Shuai and Chen, Keqin and Liu, Xuejing and Wang, Jialin and Ge, Wenbin and Song, Sibo and Dang, Kai and Wang, Peng and Wang, Shijie and Tang, Jun and Zhong, Humen and Zhu, Yuanzhi and Yang, Mingkun and Li, Zhaohai and Wan, Jianqiang and Wang, Pengfei and Ding, Wei and Fu, Zheren and Xu, Yiheng and Ye, Jiabo and Zhang, Xi and Xie, Tianbao and Cheng, Zesen and Zhang, Hang and Yang, Zhibo and Xu, Haiyang and Lin, Junyang},
journal={arXiv preprint arXiv:2502.13923},
year={2025}
}
@article{Qwen2VL,
title={Qwen2-VL: Enhancing Vision-Language Model's Perception of the World at Any Resolution},
author={Wang, Peng and Bai, Shuai and Tan, Sinan and Wang, Shijie and Fan, Zhihao and Bai, Jinze and Chen, Keqin and Liu, Xuejing and Wang, Jialin and Ge, Wenbin and Fan, Yang and Dang, Kai and Du, Mengfei and Ren, Xuancheng and Men, Rui and Liu, Dayiheng and Zhou, Chang and Zhou, Jingren and Lin, Junyang},
journal={arXiv preprint arXiv:2409.12191},
year={2024}
}
@article{Qwen-VL,
title={Qwen-VL: A Versatile Vision-Language Model for Understanding, Localization, Text Reading, and Beyond},
author={Bai, Jinze and Bai, Shuai and Yang, Shusheng and Wang, Shijie and Tan, Sinan and Wang, Peng and Lin, Junyang and Zhou, Chang and Zhou, Jingren},
journal={arXiv preprint arXiv:2308.12966},
year={2023}
}