Qwen3-VL 使用方法#
Qwen3-VL 是阿里巴巴最新的多模态大语言模型,具有强大的文本、视觉和推理能力。SGLang 支持 Qwen3-VL 系列模型,并支持图像和视频输入。
SGLang 启动命令#
以下是针对不同硬件 / 精度模式定制的建议启动命令
FP8(量化)模式#
适用于支持 FP8 检查点、且需要高显存效率和低延迟优化的部署场景(例如 H100、H200)
python3 -m sglang.launch_server \
--model-path Qwen/Qwen3-VL-235B-A22B-Instruct-FP8 \
--tp 8 \
--ep 8 \
--host 0.0.0.0 \
--port 30000 \
--keep-mm-feature-on-device
非 FP8(BF16 / 全精度)模式#
适用于使用 BF16(或不使用 FP8 快照)的 A100/H100 部署场景
python3 -m sglang.launch_server \
--model-path Qwen/Qwen3-VL-235B-A22B-Instruct \
--tp 8 \
--ep 8 \
--host 0.0.0.0 \
--port 30000 \
硬件特定说明 / 建议#
在 H100 上使用 FP8:使用 FP8 检查点以获得最佳显存效率。
在 A100 / H100 上使用 BF16(非 FP8):建议使用
--mm-max-concurrent-calls来控制图像/视频推理期间的并行吞吐量和 GPU 显存占用。在 H200 和 B200 上:模型可以“开箱即用”,支持全上下文长度以及并发的图像 + 视频处理。
发送图像/视频请求#
图像输入:#
import requests
url = f"https://:30000/v1/chat/completions"
data = {
"model": "Qwen/Qwen3-VL-30B-A3B-Instruct",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "What’s in this image?"},
{
"type": "image_url",
"image_url": {
"url": "https://github.com/sgl-project/sglang/blob/main/examples/assets/example_image.png?raw=true"
},
},
],
}
],
"max_tokens": 300,
}
response = requests.post(url, json=data)
print(response.text)
视频输入:#
import requests
url = f"https://:30000/v1/chat/completions"
data = {
"model": "Qwen/Qwen3-VL-30B-A3B-Instruct",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "What’s happening in this video?"},
{
"type": "video_url",
"video_url": {
"url": "https://github.com/sgl-project/sgl-test-files/raw/refs/heads/main/videos/jobs_presenting_ipod.mp4"
},
},
],
}
],
"max_tokens": 300,
}
response = requests.post(url, json=data)
print(response.text)
重要服务器参数与标志#
启动具有多模态支持的模型服务器时,可以使用以下命令行参数来微调性能和行为
--mm-attention-backend:指定多模态注意力机制后端。例如fa3(Flash Attention 3)--mm-max-concurrent-calls <value>:指定服务器允许的最大并发异步多模态数据处理调用数。使用此参数可控制图像/视频推理期间的并行吞吐量和 GPU 显存占用。--mm-per-request-timeout <seconds>:定义每个多模态请求的超时时长(以秒为单位)。如果请求超过此时间限制(例如处理极大的视频输入时),它将被自动终止。--keep-mm-feature-on-device:指示服务器在处理后将多模态特征张量保留在 GPU 上。这可以避免设备到主机 (D2H) 的内存拷贝,并提高重复或高频推理工作负载的性能。SGLANG_USE_CUDA_IPC_TRANSPORT=1:基于共享内存池的 CUDA IPC,用于多模态数据传输。可显著改善端到端延迟。
结合上述优化的使用示例:#
SGLANG_USE_CUDA_IPC_TRANSPORT=1 \
SGLANG_VLM_CACHE_SIZE_MB=0 \
python -m sglang.launch_server \
--model-path Qwen/Qwen3-VL-235B-A22B-Instruct \
--host 0.0.0.0 \
--port 30000 \
--trust-remote-code \
--tp-size 8 \
--enable-cache-report \
--log-level info \
--max-running-requests 64 \
--mem-fraction-static 0.65 \
--chunked-prefill-size 8192 \
--attention-backend fa3 \
--mm-attention-backend fa3 \
--enable-metrics