[Perf][Ming-TTS] Cache speaker embeddings for uploaded reference audio (#5240)

Signed-off-by: LHXuuu <xulianhao.xlh@antgroup.com>
This commit is contained in:
LHXuuu authored and GitHub committed 2026-07-23 11:22:51 +08:00
1 parent be667a8067
commit 00bdb5dcd7
7 files changed
+213 -37

No files matched your search

@@ -27,6 +27,7 @@ from vllm.sequence import IntermediateTensors
from vllm_omni.model_executor.custom_process_mixin import CustomProcessMixin
from vllm_omni.model_executor.model_loader.weight_utils import download_weights_from_hf_specific
from vllm_omni.model_executor.models.common.ming.audio_vae import AudioVAE, AudioVAEConfig
from vllm_omni.model_executor.models.ming_tts.constants import SPEAKER_EMBEDDING_DIM
from vllm_omni.model_executor.models.output_templates import OmniOutput
from vllm_omni.transformers_utils.configs.ming_flash_omni import MingFlashOmniTalkerConfig
@@ -120,8 +121,7 @@ class MingFlashOmniTalkerForConditionalGeneration(nn.Module, CustomProcessMixin)
)
self.aggregator = Aggregator(llm_input_dim=self.hidden_size, **config.aggregator)
self.stop_head = nn.Linear(self.hidden_size, 2, bias=True)
# CAMPPlus 192-dim -> hidden
self.spk_head = nn.Linear(192, self.hidden_size, bias=True)
self.spk_head = nn.Linear(SPEAKER_EMBEDDING_DIM, self.hidden_size, bias=True)
# AudioVAE
self.audio_vae, self._vae_weight_source = self._init_audio_vae(config, self.talker_dir, model_path)
@@ -16,6 +16,7 @@ from .config_ming_tts import (
VAE_PATCH_SIZE,
MingTTSConfig,
)
from .constants import SPEAKER_EMBEDDING_DIM
def pad_prompt_waveform(
@@ -56,7 +57,7 @@ def coerce_prompt_waveform(value: Any) -> torch.Tensor:
def coerce_speaker_embeddings(value: Any, *, use_zero_spk_emb: bool = False) -> list[torch.Tensor] | None:
if value is None:
return [torch.zeros((192,), dtype=torch.float32)] if use_zero_spk_emb else None
return [torch.zeros((SPEAKER_EMBEDDING_DIM,), dtype=torch.float32)] if use_zero_spk_emb else None
if isinstance(value, torch.Tensor):
tensor = value.detach()
if tensor.ndim == 1:
@@ -78,10 +79,10 @@ def coerce_speaker_embeddings(value: Any, *, use_zero_spk_emb: bool = False) ->
else:
return coerce_speaker_embeddings(torch.as_tensor(value), use_zero_spk_emb=use_zero_spk_emb)
if not items:
return [torch.zeros((192,), dtype=torch.float32)] if use_zero_spk_emb else None
return [torch.zeros((SPEAKER_EMBEDDING_DIM,), dtype=torch.float32)] if use_zero_spk_emb else None
for item in items:
if int(item.numel()) != 192:
raise ValueError(f"Ming speaker embedding must have 192 dims, got {int(item.numel())}")
if int(item.numel()) != SPEAKER_EMBEDDING_DIM:
raise ValueError(f"Ming speaker embedding must have {SPEAKER_EMBEDDING_DIM} dims, got {int(item.numel())}")
return items
@@ -43,6 +43,7 @@ LLM_VOCAB_SIZE = 151936
AGGREGATOR_HIDDEN_SIZE = 1024
VAE_PATCH_SIZE = 4
SAMPLE_RATE = 44100
SPEAKER_EMBEDDING_DIM = 192 # CAMPPlus output width and speaker projection input width
# AudioVAE frame/hop geometry (confirmed)
AUDIO_FRAME_HOP = 882 # enc input_dim / hop_size / dec output_dim
@@ -33,6 +33,7 @@ from .config_ming_tts import (
KEY_TEXT_MODE,
MingTTSConfig,
)
from .constants import SPEAKER_EMBEDDING_DIM
from .flowloss_head import FlowLoss
from .patch_emission import (
MING_STOP_REASON_CODES,
@@ -91,7 +92,7 @@ class MingLLMModel(nn.Module):
**self.ming_config.ditar_config,
)
self.stop_head = nn.Linear(self.ming_config.llm_hidden_size, 2, bias=True)
self.spk_head = nn.Linear(192, self.ming_config.llm_hidden_size, bias=True)
self.spk_head = nn.Linear(SPEAKER_EMBEDDING_DIM, self.ming_config.llm_hidden_size, bias=True)
self.flowloss.to(dtype=self.fm_dtype)
self.linear_proj_audio.to(dtype=self.fm_dtype)
self.stop_head.to(dtype=self.fm_dtype)