Add torch compile for qwen3_vl encoder (#40116)
Signed-off-by: Tianyu Guo <guoty9@mail2.sysu.edu.cn> Signed-off-by: Tianyu Guo <guoty@inferact.ai>
Tianyu Guo committed
Aug 8, 2026 at 16:23 UTC
653ebb52dffd8b4653b430302473c771117529f1
1 file changed
+22
-1
vllm/model_executor/models/qwen3_vl.py
+22
-1
@@ -48,7 +48,10 @@ from transformers.models.qwen3_vl.video_processing_qwen3_vl import (
48
)
49
from transformers.video_utils import VideoMetadata
50
51
-from vllm.compilation.decorators import support_torch_compile
51
+from vllm.compilation.decorators import (
52
+ should_torch_compile_mm_encoder,
53
+ support_torch_compile,
54
+)
55
from vllm.config import VllmConfig
56
from vllm.config.multimodal import (
57
BaseDummyOptions,
@@ -356,6 +359,13 @@ def pos_embed_interpolate_native(
359
return repeated.to(dtype=dtype)
360
361
362
+@support_torch_compile(
363
+ dynamic_arg_dims={
364
+ "x": 0,
365
+ },
366
+ enable_if=should_torch_compile_mm_encoder,
367
+ is_encoder=True,
368
+)
369
class Qwen3_VisionPatchEmbed(nn.Module):
370
def __init__(
371
self,
@@ -422,6 +432,17 @@ class Qwen3_VisionMLP(nn.Module):
432
return mlp_output
433
434
435
+@support_torch_compile(
436
+ dynamic_arg_dims={
437
+ "x": 0,
438
+ "cu_seqlens": 0,
439
+ "rotary_pos_emb_cos": 0,
440
+ "rotary_pos_emb_sin": 0,
441
+ "sequence_lengths": 0,
442
+ },
443
+ enable_if=should_torch_compile_mm_encoder,
444
+ is_encoder=True,
445
+)
446
class Qwen3_VisionBlock(nn.Module):
447
def __init__(
448
self,