[Perf][NPU] Fuse MiniMax H3 Qwen3-VL RoPE (#6061)

Signed-off-by: Wenjia Li <wjialish@gmail.com>
This commit is contained in:
Wenjia Li authored and GitHub committed 2026-08-14 09:49:26 +00:00
1 parent 728640f4d9
commit ffd11c181e
3 files changed
+149

No files matched your search

@@ -0,0 +1,43 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""NPU patches for the MiniMax H3 Qwen3-VL text encoder."""
from __future__ import annotations
import torch
from vllm.logger import init_logger
from vllm_omni.platforms.npu.layers.rotary_embedding import (
npu_rotary_mul_with_bsnd_fallback,
)
logger = init_logger(__name__)
_PATCHED = False
def _apply_rotary_pos_emb_npu(
q: torch.Tensor,
k: torch.Tensor,
cos: torch.Tensor,
sin: torch.Tensor,
) -> tuple[torch.Tensor, torch.Tensor]:
"""Apply Qwen3-VL text RoPE with fused BNSD rotary multiplication."""
return (
npu_rotary_mul_with_bsnd_fallback(q, cos, sin, unsqueeze_dim=1),
npu_rotary_mul_with_bsnd_fallback(k, cos, sin, unsqueeze_dim=1),
)
def apply_minimax_h3_qwen3vl_patch() -> None:
"""Route MiniMax H3 Qwen3-VL text RoPE to the Ascend fused operator."""
global _PATCHED
if _PATCHED:
return
from vllm_omni.diffusion.models.minimax_h3 import encoder
encoder._apply_rotary_pos_emb = _apply_rotary_pos_emb_npu
_PATCHED = True
logger.debug("Applied NPU fused RoPE patch for MiniMax H3 Qwen3-VL text encoder")
+2
View File
@@ -36,6 +36,7 @@ class NPUOmniPlatform(OmniPlatform, NPUPlatform):
from vllm_ascend.utils import adapt_patch
from vllm_omni.platforms.npu._310p import apply_patches as apply_310p_patches
from vllm_omni.platforms.npu.models.minimax_h3 import apply_minimax_h3_qwen3vl_patch
from vllm_omni.platforms.npu.models.qwen3_tts_code2wav import (
apply_qwen3_tts_code2wav_patch,
)
@@ -44,6 +45,7 @@ class NPUOmniPlatform(OmniPlatform, NPUPlatform):
)
adapt_patch(is_global_patch=True)
apply_minimax_h3_qwen3vl_patch()
apply_qwen3_tts_code2wav_patch()
apply_qwen3_tts_tokenizer_v2_patch()
apply_310p_patches()