[Refactor] TTS serving adapter framework + migrate TTS models (excl. ming_flash_omni) (#4330)

Signed-off-by: Yueqian Lin <linyueqian@outlook.com>
This commit is contained in:
Yueqian Lin authored and GitHub committed 2026-06-13 04:22:54 +00:00
1 parent 6506ed3d4d
commit d75a6433b4
20 files changed
+1045 -208

No files matched your search

@@ -21,6 +21,7 @@ to avoid OOM from vLLM's post-init KV-cache profiling. Mirrors qwen3_tts
from __future__ import annotations
import contextlib
import tempfile
import threading
from collections.abc import Iterable
@@ -38,6 +39,40 @@ from vllm_omni.model_executor.models.utils import reinit_rotary_inv_freq
logger = init_logger(__name__)
@contextlib.contextmanager
def _hf_load_without_tp_warmup():
"""Work around a transformers 5.8.x crash loading some trust_remote_code LMs.
``caching_allocator_warmup`` does ``len(model._tp_plan)`` when
``torch.distributed`` is initialized, but the MOSS-TTS-Nano remote model
leaves ``_tp_plan`` as ``None`` (it survives ``PreTrainedModel.__init__``),
so the warmup raises ``TypeError: object of type 'NoneType' has no len()``.
vLLM initializes ``torch.distributed`` even at TP=1, so the crash fires.
MOSS-TTS-Nano runs single-GPU (no tensor parallelism), so forcing the
warmup down its non-distributed branch is byte-for-byte equivalent and
sidesteps the ``None`` plan. Scoped to the wrapped ``from_pretrained`` call.
Targets the private ``transformers.modeling_utils._is_torch_distributed_initialized``.
Guarded by ``hasattr`` so that if a future transformers renames or removes it
(and presumably the crash with it), we no-op instead of raising AttributeError.
"""
import transformers.modeling_utils as _tmu
if not hasattr(_tmu, "_is_torch_distributed_initialized"):
# Internal hook gone (transformers refactor); assume the upstream crash
# is gone too and run the load unpatched.
yield
return
original = _tmu._is_torch_distributed_initialized
_tmu._is_torch_distributed_initialized = lambda: False
try:
yield
finally:
_tmu._is_torch_distributed_initialized = original
def _patch_torchaudio_load() -> None:
"""Patch torchaudio.load to use soundfile if torchcodec is unavailable."""
try:
@@ -158,11 +193,12 @@ class MossTTSNanoForGeneration(nn.Module):
logger.info("Loading MOSS-TTS-Nano LM from %s (dtype=%s)", self.model_path, tts_dtype)
from transformers import AutoModelForCausalLM
lm = AutoModelForCausalLM.from_pretrained(
self.model_path,
trust_remote_code=True,
torch_dtype=tts_dtype,
)
with _hf_load_without_tp_warmup():
lm = AutoModelForCausalLM.from_pretrained(
self.model_path,
trust_remote_code=True,
torch_dtype=tts_dtype,
)
if device.type == "cuda":
try:
import flash_attn # noqa: F401
@@ -197,11 +233,12 @@ class MossTTSNanoForGeneration(nn.Module):
logger.info("Loading MOSS-Audio-Tokenizer-Nano from %s", codec_path)
from transformers import AutoModel
audio_tokenizer = AutoModel.from_pretrained(
codec_path,
trust_remote_code=True,
torch_dtype=torch.float32,
)
with _hf_load_without_tp_warmup():
audio_tokenizer = AutoModel.from_pretrained(
codec_path,
trust_remote_code=True,
torch_dtype=torch.float32,
)
audio_tokenizer.to(device=device)
audio_tokenizer.eval()
self._audio_tokenizer: nn.Module = audio_tokenizer