[Refactor][Qwen3-TTS] Construct Code2Wav decoder natively (#2341)

Signed-off-by: Nick Cao <ncao@redhat.com>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Nick CaoandClaude authored and GitHub committed 2026-05-05 15:26:30 +00:00
1 parent b64ab05d09
commit fde38ca54f
2 files changed
+136 -142

No files matched your search

@@ -2,18 +2,25 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from types import SimpleNamespace
from unittest.mock import patch
import pytest
import torch
import torch.nn as nn
from vllm_omni.model_executor.models.qwen3_tts.qwen3_tts_code2wav import Qwen3TTSCode2Wav
from vllm_omni.model_executor.models.qwen3_tts.qwen3_tts_code2wav import (
Qwen3TTSCode2Wav,
)
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
_NUM_QUANTIZERS = 2
_TOTAL_UPSAMPLE = 4
_OUTPUT_SAMPLE_RATE = 24000
class _FakeDecoder(nn.Module):
def __init__(self, total_upsample: int = 4):
def __init__(self, total_upsample: int = _TOTAL_UPSAMPLE):
super().__init__()
self.total_upsample = total_upsample
@@ -24,18 +31,35 @@ class _FakeDecoder(nn.Module):
return wav.view(1, 1, -1)
def _make_model() -> Qwen3TTSCode2Wav:
model = Qwen3TTSCode2Wav(
vllm_config=SimpleNamespace(
model_config=SimpleNamespace(model="unused"),
device_config=SimpleNamespace(device=torch.device("cpu")),
)
def _fake_dec_config():
return SimpleNamespace(
num_quantizers=_NUM_QUANTIZERS,
sliding_window=0,
)
model._decoder = _FakeDecoder()
model._num_quantizers = 2
model._output_sample_rate = 24000
model._total_upsample = 4
model._ensure_speech_tokenizer_loaded = lambda: None
def _make_model() -> Qwen3TTSCode2Wav:
dec_config = _fake_dec_config()
tok_config = SimpleNamespace(
decoder_config=dec_config,
output_sample_rate=_OUTPUT_SAMPLE_RATE,
)
with (
patch(
"vllm_omni.model_executor.models.qwen3_tts.qwen3_tts_code2wav.Qwen3TTSTokenizerV2Config.from_pretrained",
return_value=tok_config,
),
patch(
"vllm_omni.model_executor.models.qwen3_tts.qwen3_tts_code2wav.Qwen3TTSTokenizerV2Decoder._from_config",
return_value=_FakeDecoder(),
),
):
model = Qwen3TTSCode2Wav(
vllm_config=SimpleNamespace(
model_config=SimpleNamespace(model="unused"),
device_config=SimpleNamespace(device=torch.device("cpu")),
)
)
return model