[Refactor][TTS] Derive TTS model detection from adapter metadata (#5682)
Signed-off-by: Yueqian Lin <linyueqian@outlook.com>
This commit is contained in:
1 parent
8e2e9b6b53
commit
ebe93f5d1e
15 files changed
+1002
-239
No files matched your search
@@ -53,7 +53,10 @@ from vllm_omni.entrypoints.openai.speech_usage import (
|
||||
)
|
||||
from vllm_omni.entrypoints.openai.tts_adapters import (
|
||||
SpeechServingContext,
|
||||
all_tts_stage_keys,
|
||||
detect_tts_model_type,
|
||||
resolve_adapter,
|
||||
tts_entry_stage_archs,
|
||||
)
|
||||
from vllm_omni.entrypoints.utils import coerce_param_message_types
|
||||
from vllm_omni.model_executor.models.fish_speech.prompt_utils import (
|
||||
@@ -78,52 +81,17 @@ from vllm_omni.utils.speaker_cache import (
|
||||
logger = init_logger(__name__)
|
||||
|
||||
# TTS Configuration
|
||||
_MING_TTS_MODEL_ARCHS = {"MingTTSForConditionalGeneration"}
|
||||
_VOXTRAL_TTS_MODEL_STAGES = {"audio_generation"}
|
||||
_QWEN3_TTS_MODEL_STAGES = {"qwen3_tts"}
|
||||
_FISH_TTS_MODEL_STAGES = {"fish_speech_slow_ar"}
|
||||
_COSYVOICE3_TTS_MODEL_STAGES = {"cosyvoice3_talker"}
|
||||
#
|
||||
# The stage-key -> model-type mapping is NOT declared here: it is derived from
|
||||
# the ``stage_keys`` / ``model_archs`` each adapter declares, via
|
||||
# ``tts_adapters.detect_tts_model_type``. Adding a TTS model must not require an
|
||||
# edit to this module.
|
||||
#
|
||||
# CosyVoice3 talker expects its reference transcript wrapped in the model
|
||||
# instruction template; without the delimiter the talker re-speaks the
|
||||
# reference (issue #4644). Matches the offline example/test and upstream demo.
|
||||
_COSYVOICE3_PROMPT_DELIMITER = "<|endofprompt|>"
|
||||
_COSYVOICE3_PROMPT_PREFIX = f"You are a helpful assistant.{_COSYVOICE3_PROMPT_DELIMITER}"
|
||||
_OMNIVOICE_TTS_MODEL_STAGES = {"omnivoice_generator"}
|
||||
_COVO_AUDIO_MODEL_STAGES = {"fused_thinker_talker"}
|
||||
_VOXCPM2_TTS_MODEL_STAGES = {"latent_generator"}
|
||||
_MING_TTS_MODEL_STAGES = {"ming_tts"}
|
||||
_MOSS_TTS_MODEL_STAGES = {"moss_tts_nano"}
|
||||
_MOSS_TTS_FULL_MODEL_STAGES = {"moss_tts", "moss_tts_codec"}
|
||||
_MOSS_TTS_LOCAL_MODEL_STAGES = {"moss_tts_local", "moss_tts_local_codec"}
|
||||
_HIGGS_AUDIO_V2_TTS_MODEL_STAGES = {"higgs_audio_v2"}
|
||||
_HIGGS_V3_TTS_MODEL_STAGES = {"higgs_audio_v3"}
|
||||
_GLM_TTS_MODEL_STAGES = {"glm_tts"}
|
||||
_STEP_AUDIO2_TTS_MODEL_STAGES = {"step_audio2_thinker"}
|
||||
_INDEXTTS2_TTS_MODEL_STAGES = {"indextts2_talker"}
|
||||
# audex_omni covers the audex_s2s S2S deployment, whose
|
||||
# TTS pass uses the same /v1/audio/speech surface.
|
||||
_AUDEX_TTS_MODEL_STAGES = {"audex_thinker", "audex_omni"}
|
||||
_AUDEX_TTA_MODEL_STAGES = {"audex_tta_thinker"}
|
||||
_TTS_MODEL_STAGES: set[str] = (
|
||||
_VOXTRAL_TTS_MODEL_STAGES
|
||||
| _QWEN3_TTS_MODEL_STAGES
|
||||
| _FISH_TTS_MODEL_STAGES
|
||||
| _COSYVOICE3_TTS_MODEL_STAGES
|
||||
| _OMNIVOICE_TTS_MODEL_STAGES
|
||||
| _HIGGS_AUDIO_V2_TTS_MODEL_STAGES
|
||||
| _HIGGS_V3_TTS_MODEL_STAGES
|
||||
| _COVO_AUDIO_MODEL_STAGES
|
||||
| _VOXCPM2_TTS_MODEL_STAGES
|
||||
| _MING_TTS_MODEL_STAGES
|
||||
| _MOSS_TTS_MODEL_STAGES
|
||||
| _MOSS_TTS_FULL_MODEL_STAGES
|
||||
| _MOSS_TTS_LOCAL_MODEL_STAGES
|
||||
| _GLM_TTS_MODEL_STAGES
|
||||
| _STEP_AUDIO2_TTS_MODEL_STAGES
|
||||
| _INDEXTTS2_TTS_MODEL_STAGES
|
||||
| _AUDEX_TTS_MODEL_STAGES
|
||||
| _AUDEX_TTA_MODEL_STAGES
|
||||
)
|
||||
_SAMPLING_MAX_TOKENS_TTS_MODEL_TYPES = {
|
||||
"fish_tts",
|
||||
"qwen3_tts",
|
||||
@@ -446,7 +414,6 @@ class OmniOpenAIServingSpeech(OpenAIServing, AudioMixin):
|
||||
instance._diffusion_stage_configs = stage_configs
|
||||
instance._tts_model_type = "omnivoice"
|
||||
instance._is_tts = False
|
||||
instance._is_fish_speech = False
|
||||
# Diffusion-only instances don't have a TTS stage; set None so any
|
||||
# ``_is_tts_model()`` / ``_tts_stage`` access doesn't raise AttributeError.
|
||||
instance._tts_stage = None
|
||||
@@ -462,10 +429,6 @@ class OmniOpenAIServingSpeech(OpenAIServing, AudioMixin):
|
||||
# Find and cache the TTS stage (if any) during initialization
|
||||
self._tts_stage = self._find_tts_stage()
|
||||
self._is_tts = self._tts_stage is not None
|
||||
self._is_fish_speech = (
|
||||
self._tts_stage is not None
|
||||
and getattr(getattr(self._tts_stage, "engine_args", None), "model_stage", None) == "fish_speech_slow_ar"
|
||||
)
|
||||
self._fish_speech_tokenizer = None
|
||||
self._covo_audio_tokenizer = None
|
||||
# Cached per process: the CosyVoice3 Qwen tokenizer + resolved model
|
||||
@@ -474,11 +437,6 @@ class OmniOpenAIServingSpeech(OpenAIServing, AudioMixin):
|
||||
# TTFP critical path) in _apply_cosyvoice3_dynamic_tokens.
|
||||
self._cosyvoice3_tokenizer = None
|
||||
|
||||
self._is_cosyvoice3 = (
|
||||
self._tts_stage is not None
|
||||
and getattr(getattr(self._tts_stage, "engine_args", None), "model_stage", None)
|
||||
in _COSYVOICE3_TTS_MODEL_STAGES
|
||||
)
|
||||
# Determine TTS model type or None
|
||||
self._tts_model_type = self._detect_tts_model_type()
|
||||
self.precomputed_speakers = self._load_precomputed_speakers()
|
||||
@@ -687,74 +645,43 @@ class OmniOpenAIServingSpeech(OpenAIServing, AudioMixin):
|
||||
|
||||
def _find_tts_stage(self):
|
||||
"""Find and return the TTS stage config, or None if not found."""
|
||||
all_stages = {getattr(stage.engine_args, "model_stage", None) for stage in self.engine_client.stage_configs}
|
||||
tts_stage_keys = all_tts_stage_keys()
|
||||
entry_stage_archs = tts_entry_stage_archs()
|
||||
all_stages = frozenset(
|
||||
getattr(stage.engine_args, "model_stage", None) for stage in self.engine_client.stage_configs
|
||||
)
|
||||
for stage in self.engine_client.stage_configs:
|
||||
engine_args = stage.engine_args
|
||||
model_stage = engine_args.model_stage
|
||||
model_arch = getattr(engine_args, "model_arch", None)
|
||||
worker_type = getattr(engine_args, "worker_type", None)
|
||||
if model_stage in _TTS_MODEL_STAGES:
|
||||
# The audio-capable Audex thinker is only speech-capable when
|
||||
# deployed WITH the speech decoder (audex_s2s);
|
||||
# the thinker-only deployment is text-final and must not
|
||||
# accept /v1/audio/speech requests.
|
||||
if model_stage == "audex_omni" and "audex_code2wav" not in all_stages:
|
||||
if model_stage in tts_stage_keys:
|
||||
# Owning the stage key is not always enough: a model may be
|
||||
# speech-capable only in some deployment topologies. Ask the
|
||||
# adapter. Stages that resolve to no adapter keep the legacy
|
||||
# behaviour of being accepted here (and detected as ``None``).
|
||||
adapter_cls = resolve_adapter(detect_tts_model_type(model_stage, model_arch))
|
||||
if adapter_cls is not None and not adapter_cls.stage_serves_speech(model_stage, all_stages):
|
||||
continue
|
||||
return stage
|
||||
# Ming dense identifies its AR entry stage by architecture because
|
||||
# it does not use a dedicated TTS model_stage value.
|
||||
if model_arch in _MING_TTS_MODEL_ARCHS and worker_type == "ar":
|
||||
# Models with no dedicated TTS model_stage value identify their AR
|
||||
# entry stage by architecture (Ming dense).
|
||||
if model_arch in entry_stage_archs and worker_type == "ar":
|
||||
return stage
|
||||
return None
|
||||
|
||||
def _detect_tts_model_type(self) -> str | None:
|
||||
"""Detect TTS model type from the stage's model_stage attribute."""
|
||||
"""Detect TTS model type from the resolved stage's deployment metadata.
|
||||
|
||||
The mapping lives on the adapters (``stage_keys`` / ``model_archs``);
|
||||
this only supplies the stage under inspection.
|
||||
"""
|
||||
if self._tts_stage is None:
|
||||
return None
|
||||
model_stage = getattr(self._tts_stage.engine_args, "model_stage", None)
|
||||
model_arch = getattr(self._tts_stage.engine_args, "model_arch", None)
|
||||
if model_arch == "VoxCPM2TalkerForConditionalGeneration":
|
||||
return "voxcpm2"
|
||||
if model_stage in _QWEN3_TTS_MODEL_STAGES:
|
||||
return "qwen3_tts"
|
||||
if model_stage in _VOXTRAL_TTS_MODEL_STAGES:
|
||||
return "voxtral_tts"
|
||||
if model_stage in _FISH_TTS_MODEL_STAGES:
|
||||
return "fish_tts"
|
||||
if model_stage in _COSYVOICE3_TTS_MODEL_STAGES:
|
||||
return "cosyvoice3"
|
||||
if model_stage in _OMNIVOICE_TTS_MODEL_STAGES:
|
||||
return "omnivoice"
|
||||
if model_stage in _COVO_AUDIO_MODEL_STAGES:
|
||||
if model_arch and "CovoAudio" in model_arch:
|
||||
return "covo_audio"
|
||||
if model_stage in _VOXCPM2_TTS_MODEL_STAGES:
|
||||
return "voxcpm2"
|
||||
if model_stage in _MING_TTS_MODEL_STAGES:
|
||||
return "ming_flash_omni_tts"
|
||||
if model_arch in _MING_TTS_MODEL_ARCHS:
|
||||
return "ming_tts"
|
||||
if model_stage in _MOSS_TTS_MODEL_STAGES:
|
||||
return "moss_tts_nano"
|
||||
if model_stage in _MOSS_TTS_FULL_MODEL_STAGES:
|
||||
return "moss_tts"
|
||||
if model_stage in _MOSS_TTS_LOCAL_MODEL_STAGES:
|
||||
return "moss_tts"
|
||||
if model_stage in _HIGGS_AUDIO_V2_TTS_MODEL_STAGES:
|
||||
return "higgs_audio_v2"
|
||||
if model_stage in _HIGGS_V3_TTS_MODEL_STAGES:
|
||||
return "higgs_audio_v3"
|
||||
if model_stage in _GLM_TTS_MODEL_STAGES:
|
||||
return "glm_tts"
|
||||
if model_stage in _STEP_AUDIO2_TTS_MODEL_STAGES:
|
||||
return "step_audio2"
|
||||
if model_stage in _INDEXTTS2_TTS_MODEL_STAGES:
|
||||
return "indextts2"
|
||||
if model_stage in _AUDEX_TTS_MODEL_STAGES:
|
||||
return "audex"
|
||||
if model_stage in _AUDEX_TTA_MODEL_STAGES:
|
||||
return "audex_tta"
|
||||
return None
|
||||
return detect_tts_model_type(
|
||||
getattr(self._tts_stage.engine_args, "model_stage", None),
|
||||
getattr(self._tts_stage.engine_args, "model_arch", None),
|
||||
)
|
||||
|
||||
def _get_custom_voice_dir(self) -> str | None:
|
||||
try:
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
"""Registry of TTS serving adapters.
|
||||
"""Registry of TTS serving adapters, and the model detection built on it.
|
||||
|
||||
Adapters register themselves by their ``name`` (the model-type discriminator
|
||||
returned by ``OmniOpenAIServingSpeech._detect_tts_model_type``) via
|
||||
``@register_tts_adapter``. Resolution is by that name: detection already encodes
|
||||
the (order-sensitive, partly ``model_arch``-based) stage logic, so keying the
|
||||
registry on the resolved type is both simpler and correct by construction.
|
||||
``stage_keys`` is retained on each adapter as documentation metadata.
|
||||
Adapters register themselves by their ``name`` (the model-type discriminator)
|
||||
via ``@register_tts_adapter``, and declare the deployment metadata that
|
||||
identifies them: ``stage_keys``, plus ``model_archs`` for the few models a stage
|
||||
key alone cannot distinguish.
|
||||
|
||||
That metadata is the single source of truth. :func:`detect_tts_model_type` and
|
||||
:func:`all_tts_stage_keys` derive the whole stage -> model-type mapping from it,
|
||||
so a new TTS model is one adapter file and needs no edit to ``serving_speech.py``.
|
||||
Models still awaiting an adapter are listed explicitly in
|
||||
:data:`LEGACY_TTS_DETECTORS`.
|
||||
"""
|
||||
|
||||
from vllm.logger import init_logger
|
||||
@@ -14,6 +18,7 @@ from vllm.logger import init_logger
|
||||
from vllm_omni.entrypoints.openai.tts_adapters.base import (
|
||||
ARTTSAdapter,
|
||||
DiffusionTTSAdapter,
|
||||
LegacyDetector,
|
||||
OutputPolicy,
|
||||
PreparedRequest,
|
||||
SpeechServingContext,
|
||||
@@ -24,6 +29,19 @@ logger = init_logger(__name__)
|
||||
|
||||
TTS_ADAPTER_REGISTRY: dict[str, type[TTSModelAdapter]] = {}
|
||||
|
||||
#: Model types the serving layer detects that have no adapter yet. See
|
||||
#: :class:`LegacyDetector`. This list must only ever shrink.
|
||||
LEGACY_TTS_DETECTORS: tuple[LegacyDetector, ...] = (
|
||||
# Ming *flash-omni* claims the ``ming_tts`` stage key, while Ming *dense*
|
||||
# (which does have an adapter) is identified by architecture. The stage key
|
||||
# must therefore be tested first, hence the explicit priority.
|
||||
LegacyDetector(
|
||||
name="ming_flash_omni_tts",
|
||||
stage_keys=frozenset({"ming_tts"}),
|
||||
detect_priority=50,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def register_tts_adapter(cls: type[TTSModelAdapter]) -> type[TTSModelAdapter]:
|
||||
"""Class decorator: index ``cls`` under its ``name`` (model-type)."""
|
||||
@@ -48,6 +66,56 @@ def resolve_adapter(model_type: str | None) -> type[TTSModelAdapter] | None:
|
||||
return TTS_ADAPTER_REGISTRY.get(model_type)
|
||||
|
||||
|
||||
def iter_tts_detectors() -> list[type[TTSModelAdapter] | LegacyDetector]:
|
||||
"""Every detector, in resolution order.
|
||||
|
||||
Sorted by ``detect_priority`` then ``name``, so the order is total and does
|
||||
not depend on adapter import order.
|
||||
"""
|
||||
detectors: list[type[TTSModelAdapter] | LegacyDetector] = [
|
||||
*TTS_ADAPTER_REGISTRY.values(),
|
||||
*LEGACY_TTS_DETECTORS,
|
||||
]
|
||||
detectors.sort(key=lambda d: (d.detect_priority, d.name))
|
||||
return detectors
|
||||
|
||||
|
||||
def detect_tts_model_type(model_stage: str | None, model_arch: str | None) -> str | None:
|
||||
"""Resolve a deployed stage to its TTS model-type, or ``None``.
|
||||
|
||||
The first detector that matches wins; ties are impossible for distinct model
|
||||
types because overlapping detectors must declare an explicit
|
||||
``detect_priority`` (enforced by ``test_tts_detection.py``).
|
||||
"""
|
||||
for detector in iter_tts_detectors():
|
||||
if detector.matches(model_stage, model_arch):
|
||||
return detector.name
|
||||
return None
|
||||
|
||||
|
||||
def all_tts_stage_keys() -> frozenset[str]:
|
||||
"""Every ``model_stage`` value served by ``/v1/audio/speech``."""
|
||||
keys: set[str] = set()
|
||||
for detector in iter_tts_detectors():
|
||||
keys |= detector.stage_keys
|
||||
return frozenset(keys)
|
||||
|
||||
|
||||
def tts_entry_stage_archs() -> frozenset[str]:
|
||||
"""``model_arch`` values that identify an AR entry stage on their own.
|
||||
|
||||
Only for models that own no ``model_stage`` key; stage discovery falls back
|
||||
to these. Deliberately *not* every declared ``model_arch``: a model that also
|
||||
owns a stage key is found by that key, and widening this would change which
|
||||
stage is selected in mixed deployments.
|
||||
"""
|
||||
archs: set[str] = set()
|
||||
for detector in iter_tts_detectors():
|
||||
if detector.arch_identifies_entry_stage:
|
||||
archs |= detector.model_archs
|
||||
return frozenset(archs)
|
||||
|
||||
|
||||
# Import adapter modules for their registration side effects. Keep at the bottom
|
||||
# so the registry helpers above are defined first.
|
||||
from vllm_omni.entrypoints.openai.tts_adapters import ( # noqa: E402,F401
|
||||
@@ -72,12 +140,18 @@ from vllm_omni.entrypoints.openai.tts_adapters import ( # noqa: E402,F401
|
||||
__all__ = [
|
||||
"ARTTSAdapter",
|
||||
"DiffusionTTSAdapter",
|
||||
"LegacyDetector",
|
||||
"OutputPolicy",
|
||||
"PreparedRequest",
|
||||
"SpeechServingContext",
|
||||
"TTSModelAdapter",
|
||||
"LEGACY_TTS_DETECTORS",
|
||||
"TTS_ADAPTER_REGISTRY",
|
||||
"all_tts_model_types",
|
||||
"all_tts_stage_keys",
|
||||
"detect_tts_model_type",
|
||||
"iter_tts_detectors",
|
||||
"register_tts_adapter",
|
||||
"resolve_adapter",
|
||||
"tts_entry_stage_archs",
|
||||
]
|
||||
@@ -29,6 +29,15 @@ class AudexAdapter(ARTTSAdapter):
|
||||
stage_keys = frozenset({"audex_thinker", "audex_omni"})
|
||||
name = "audex"
|
||||
|
||||
@classmethod
|
||||
def stage_serves_speech(cls, model_stage: str | None, all_stage_keys: frozenset[str]) -> bool:
|
||||
"""``audex_omni`` covers the audex_s2s deployment, whose TTS pass uses
|
||||
the same ``/v1/audio/speech`` surface. Without the speech decoder the
|
||||
same thinker is text-final and must not accept speech requests."""
|
||||
if model_stage == "audex_omni":
|
||||
return "audex_code2wav" in all_stage_keys
|
||||
return True
|
||||
|
||||
def validate(self, request: "OpenAICreateSpeechRequest") -> str | None:
|
||||
if not request.input or not request.input.strip():
|
||||
return "Audex TTS requires non-empty input text"
|
||||
|
||||
@@ -99,8 +99,20 @@ class TTSModelAdapter(ABC):
|
||||
|
||||
#: Stable discriminator string (the model-type from detection); registry key.
|
||||
name: ClassVar[str]
|
||||
#: Engine ``model_stage`` key(s) this model uses, for documentation only.
|
||||
#: Engine ``model_stage`` key(s) this model uses. Load-bearing: the serving
|
||||
#: layer discovers the TTS stage and resolves the model type from these.
|
||||
stage_keys: ClassVar[frozenset[str]] = frozenset()
|
||||
#: Engine ``model_arch`` value(s) that identify this model type. Checked
|
||||
#: before ``stage_keys`` in :meth:`matches`. Only needed by models whose
|
||||
#: ``model_stage`` alone is ambiguous or absent.
|
||||
model_archs: ClassVar[frozenset[str]] = frozenset()
|
||||
#: Set when the model has no dedicated ``model_stage`` value and its AR
|
||||
#: entry stage must be discovered by ``model_archs`` instead (Ming dense).
|
||||
arch_identifies_entry_stage: ClassVar[bool] = False
|
||||
#: Detection order; lower runs first. Only set this to break a genuine
|
||||
#: overlap with another adapter — see ``tests/.../test_tts_detection.py``,
|
||||
#: which fails if two same-priority detectors can match the same input.
|
||||
detect_priority: ClassVar[int] = 100
|
||||
#: Serving backend: ``"ar"`` (engine_client) or ``"diffusion"``.
|
||||
backend: ClassVar[str] = "ar"
|
||||
|
||||
@@ -111,6 +123,31 @@ class TTSModelAdapter(ABC):
|
||||
def __init__(self, ctx: SpeechServingContext) -> None:
|
||||
self.ctx = ctx
|
||||
|
||||
@classmethod
|
||||
def matches(cls, model_stage: str | None, model_arch: str | None) -> bool:
|
||||
"""Whether a deployed stage with this ``model_stage``/``model_arch``
|
||||
is served by this adapter.
|
||||
|
||||
Architecture wins over stage key, so a model that declares both is
|
||||
recognized even when deployed under a stage key it shares with another
|
||||
model. Override only for match rules that are not a set membership
|
||||
test (see ``covo_audio``).
|
||||
"""
|
||||
if model_arch is not None and model_arch in cls.model_archs:
|
||||
return True
|
||||
return model_stage is not None and model_stage in cls.stage_keys
|
||||
|
||||
@classmethod
|
||||
def stage_serves_speech(cls, model_stage: str | None, all_stage_keys: frozenset[str]) -> bool:
|
||||
"""Whether a matched stage really accepts ``/v1/audio/speech`` in *this*
|
||||
deployment.
|
||||
|
||||
Lets a model that is speech-capable only in some topologies say so
|
||||
(Audex: its omni thinker is text-final unless the speech decoder is
|
||||
deployed alongside). Default: always.
|
||||
"""
|
||||
return True
|
||||
|
||||
def normalize(self, request: "OpenAICreateSpeechRequest") -> None:
|
||||
"""In-place request normalization/mutation (e.g. infer task type,
|
||||
lowercase voice). Default: no-op."""
|
||||
@@ -189,10 +226,37 @@ class DiffusionTTSAdapter(TTSModelAdapter):
|
||||
return frozenset(params) if params is not None else frozenset()
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class LegacyDetector:
|
||||
"""A model type the serving layer detects but has no adapter for yet.
|
||||
|
||||
Detection has to keep naming these models so ``serving_speech.py`` can route
|
||||
them down its legacy path, but they own none of the adapter contract. Each
|
||||
entry is a migration debt: delete it when the model gets an adapter. The
|
||||
pre-commit gate (``tools/pre_commit/check_tts_adapter.py``) fails if the list
|
||||
grows.
|
||||
|
||||
Exposes the subset of the :class:`TTSModelAdapter` class surface that
|
||||
detection reads, so both kinds live in one sorted sequence.
|
||||
"""
|
||||
|
||||
name: str
|
||||
stage_keys: frozenset[str] = frozenset()
|
||||
model_archs: frozenset[str] = frozenset()
|
||||
arch_identifies_entry_stage: bool = False
|
||||
detect_priority: int = 100
|
||||
|
||||
def matches(self, model_stage: str | None, model_arch: str | None) -> bool:
|
||||
if model_arch is not None and model_arch in self.model_archs:
|
||||
return True
|
||||
return model_stage is not None and model_stage in self.stage_keys
|
||||
|
||||
|
||||
# Re-exported here to avoid import cycles at call sites.
|
||||
__all__ = [
|
||||
"ARTTSAdapter",
|
||||
"DiffusionTTSAdapter",
|
||||
"LegacyDetector",
|
||||
"OutputPolicy",
|
||||
"PreparedRequest",
|
||||
"SpeechServingContext",
|
||||
|
||||
@@ -15,6 +15,13 @@ class CovoAudioAdapter(ARTTSAdapter):
|
||||
stage_keys = frozenset({"fused_thinker_talker"})
|
||||
name = "covo_audio"
|
||||
|
||||
@classmethod
|
||||
def matches(cls, model_stage: str | None, model_arch: str | None) -> bool:
|
||||
"""``fused_thinker_talker`` is a generic stage key that non-CoVo fused
|
||||
deployments also use, so the architecture has to confirm it. A fused
|
||||
stage from another model falls through to "not a TTS model"."""
|
||||
return super().matches(model_stage, model_arch) and bool(model_arch) and "CovoAudio" in model_arch
|
||||
|
||||
def validate(self, request: "OpenAICreateSpeechRequest") -> str | None:
|
||||
if not request.input or not request.input.strip():
|
||||
return "Input text cannot be empty"
|
||||
|
||||
@@ -17,8 +17,16 @@ logger = init_logger(__name__)
|
||||
|
||||
@register_tts_adapter
|
||||
class MingTTSAdapter(ARTTSAdapter):
|
||||
# Detected by model_arch (MingTTSForConditionalGeneration), not stage key.
|
||||
# Ming dense has no dedicated model_stage value, so both stage discovery and
|
||||
# model-type detection go through the architecture. ``ming_flash_omni_tts``
|
||||
# is the model that owns the ``ming_tts`` *stage key*, and is matched first.
|
||||
name = "ming_tts"
|
||||
model_archs = frozenset({"MingTTSForConditionalGeneration"})
|
||||
arch_identifies_entry_stage = True
|
||||
# Ming dense deploys its AR stage as the generic ``model_stage="llm"``, so
|
||||
# this is an architecture *fallback*: it must run after every adapter that
|
||||
# owns a real stage key, or it would claim stages those adapters own.
|
||||
detect_priority = 200
|
||||
|
||||
def validate(self, request: "OpenAICreateSpeechRequest") -> str | None:
|
||||
"""Validate Ming TTS request parameters. Returns error message or None."""
|
||||
|
||||
@@ -16,7 +16,12 @@ class VoxCPM2Adapter(ARTTSAdapter):
|
||||
stage is present (and/or via ``model_arch``)."""
|
||||
|
||||
stage_keys = frozenset({"latent_generator"})
|
||||
model_archs = frozenset({"VoxCPM2TalkerForConditionalGeneration"})
|
||||
name = "voxcpm2"
|
||||
# The talker architecture is authoritative and is tested ahead of every
|
||||
# stage key, so a VoxCPM2 talker deployed under a stage key another model
|
||||
# claims still resolves to VoxCPM2.
|
||||
detect_priority = 10
|
||||
|
||||
def validate(self, request: "OpenAICreateSpeechRequest") -> str | None:
|
||||
"""Validate VoxCPM2 request parameters. Returns error message or None."""
|
||||
|
||||
Reference in new issue
Block a user