From 0fc4032a712c5d8fec5cbab87ace8786f0fc42c7 Mon Sep 17 00:00:00 2001 From: tanhaoan333 Date: Wed, 3 Jun 2026 21:34:47 +0800 Subject: [PATCH] Update qwen3_tts_code2wav.py (#4075) Signed-off-by: tanhaoan333 --- .../npu/models/qwen3_tts_code2wav.py | 48 +++++++++++++++++++ vllm_omni/platforms/npu/platform.py | 8 ++++ 2 files changed, 56 insertions(+) create mode 100644 vllm_omni/platforms/npu/models/qwen3_tts_code2wav.py diff --git a/vllm_omni/platforms/npu/models/qwen3_tts_code2wav.py b/vllm_omni/platforms/npu/models/qwen3_tts_code2wav.py new file mode 100644 index 000000000..282689bca --- /dev/null +++ b/vllm_omni/platforms/npu/models/qwen3_tts_code2wav.py @@ -0,0 +1,48 @@ +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: Copyright contributors to the vLLM project + +"""Monkey-patch ``Qwen3TTSCode2Wav.__init__`` for NPU Code2Wav runtime knobs.""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +import torch +from vllm.config import VllmConfig +from vllm.logger import init_logger + +if TYPE_CHECKING: + pass + +logger = init_logger(__name__) + +_PATCHED = False +_original_init = None + + +def _prepare_npu_code2wav_runtime() -> None: + from vllm_omni.platforms import current_omni_platform + + if not current_omni_platform.is_npu(): + return + torch.npu.config.allow_internal_format = False + torch.npu.set_compile_mode(jit_compile=False) + + +def _patched_init(self, *, vllm_config: VllmConfig, prefix: str = "") -> None: + _prepare_npu_code2wav_runtime() + assert _original_init is not None + _original_init(self, vllm_config=vllm_config, prefix=prefix) + + +def apply_qwen3_tts_code2wav_patch() -> None: + global _PATCHED, _original_init + if _PATCHED: + return + + from vllm_omni.model_executor.models.qwen3_tts.qwen3_tts_code2wav import Qwen3TTSCode2Wav + + _original_init = Qwen3TTSCode2Wav.__init__ + Qwen3TTSCode2Wav.__init__ = _patched_init # type: ignore[method-assign] + _PATCHED = True + logger.debug("Applied NPU patch for Qwen3TTSCode2Wav.__init__") diff --git a/vllm_omni/platforms/npu/platform.py b/vllm_omni/platforms/npu/platform.py index faf69c1b8..3b9f3d15f 100644 --- a/vllm_omni/platforms/npu/platform.py +++ b/vllm_omni/platforms/npu/platform.py @@ -31,6 +31,14 @@ class NPUOmniPlatform(OmniPlatform, NPUPlatform): _omni_enum = OmniPlatformEnum.NPU dist_backend: str = "hccl" + # conv2d convolution operator in the code2wav module of Qwen3-TTS not being able to run on Aclnn + def __init__(self) -> None: + from vllm_omni.platforms.npu.models.patch_qwen3_tts_code2wav import ( + apply_qwen3_tts_code2wav_patch, + ) + + apply_qwen3_tts_code2wav_patch() + @classmethod def set_device(cls, device: torch.device) -> None: super().set_device(device)