[Refactor] Migrate and clean up TTS configs: CosyVoice3, OmniVoice, VoxCPM (#3338)
Signed-off-by: yuanheng <jonathan.zhaoyh@gmail.com> Signed-off-by: Yuanheng Zhao <jonathan.zhaoyh@gmail.com>
This commit is contained in:
1 parent
c08959ee04
commit
a64ebf103b
17 files changed
+106
-71
No files matched your search
@@ -1,133 +0,0 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from transformers.configuration_utils import PretrainedConfig
|
||||
|
||||
|
||||
class CosyVoice3Config(PretrainedConfig):
|
||||
model_type = "cosyvoice3"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
# Set primary speech EOS so vLLM stops generation at the right token.
|
||||
# The official CosyVoice3 treats ALL tokens >= speech_token_size
|
||||
# (6561-6760) as stop signals; see stop_token_ids in the YAML configs.
|
||||
kwargs.setdefault("eos_token_id", 6562)
|
||||
super().__init__(**kwargs)
|
||||
self.sample_rate = 24000
|
||||
self.llm_input_size = 896
|
||||
self.llm_output_size = 896
|
||||
self.hidden_size = self.llm_output_size
|
||||
self.num_attention_heads = 14
|
||||
self.num_hidden_layers = 24
|
||||
self.spk_embed_dim = 192
|
||||
self.token_frame_rate = 25
|
||||
self.token_mel_ratio = 2
|
||||
self.vocab_size = 151923
|
||||
self.min_token_text_ratio = 2
|
||||
self.max_token_text_ratio = 20
|
||||
self.allowed_special = "all"
|
||||
self.skip_special_tokens = True
|
||||
self.target_sr = 24000
|
||||
self.feat_extractor = {
|
||||
"n_fft": 1920,
|
||||
"num_mels": 80,
|
||||
"sampling_rate": self.sample_rate,
|
||||
"hop_size": 480,
|
||||
"win_size": 1920,
|
||||
"fmin": 0,
|
||||
"fmax": None,
|
||||
"center": False,
|
||||
}
|
||||
self.speculative_config = None
|
||||
self.qwen_pretrain_path = "CosyVoice-BlankEN"
|
||||
self.campplus_onxx_path = "campplus.onnx"
|
||||
self.speech_tokenizer_path = "speech_tokenizer_v3.onnx"
|
||||
self.spk2info_path = "spk2info.pt"
|
||||
self.version = "cosyvoice3"
|
||||
self.llm = {
|
||||
"llm_input_size": self.llm_input_size,
|
||||
"llm_output_size": self.llm_output_size,
|
||||
"speech_token_size": 6561,
|
||||
"eos_token_id": 6561 + 1,
|
||||
"length_normalized_loss": True,
|
||||
"lsm_weight": 0,
|
||||
"mix_ratio": [5, 15],
|
||||
"llm": {
|
||||
"pretrain_path": self.qwen_pretrain_path,
|
||||
},
|
||||
"sampling": {
|
||||
"top_p": 0.8,
|
||||
"top_k": 25,
|
||||
"win_size": 10,
|
||||
"tau_r": 0.1,
|
||||
},
|
||||
"spk_embed_dim": self.spk_embed_dim,
|
||||
}
|
||||
self.flow = {
|
||||
"input_size": 80,
|
||||
"output_size": 80,
|
||||
"spk_embed_dim": self.spk_embed_dim,
|
||||
"output_type": "mel",
|
||||
"vocab_size": 6561,
|
||||
"input_frame_rate": self.token_frame_rate,
|
||||
"only_mask_loss": True,
|
||||
"token_mel_ratio": self.token_mel_ratio,
|
||||
"pre_lookahead_len": 3,
|
||||
"pre_lookahead_layer": {
|
||||
"in_channels": 80,
|
||||
"channels": 1024,
|
||||
"pre_lookahead_len": 3,
|
||||
},
|
||||
"decoder": {
|
||||
"in_channels": 240,
|
||||
"n_spks": 1,
|
||||
"spk_emb_dim": 80,
|
||||
"cfm_params": {
|
||||
"sigma_min": 1e-06,
|
||||
"solver": "euler",
|
||||
"t_scheduler": "cosine",
|
||||
"training_cfg_rate": 0.2,
|
||||
"inference_cfg_rate": 0.7,
|
||||
"reg_loss_type": "l1",
|
||||
},
|
||||
"estimator": {
|
||||
"dim": 1024,
|
||||
"depth": 22,
|
||||
"heads": 16,
|
||||
"dim_head": 64,
|
||||
"ff_mult": 2,
|
||||
"mel_dim": 80,
|
||||
"mu_dim": 80,
|
||||
"spk_dim": 80,
|
||||
"out_channels": 80,
|
||||
"static_chunk_size": self.token_frame_rate * self.token_mel_ratio,
|
||||
"num_decoding_left_chunks": -1,
|
||||
},
|
||||
},
|
||||
}
|
||||
self.hift = {
|
||||
"in_channels": 80,
|
||||
"base_channels": 512,
|
||||
"nb_harmonics": 8,
|
||||
"sampling_rate": self.sample_rate,
|
||||
"nsf_alpha": 0.1,
|
||||
"nsf_sigma": 0.003,
|
||||
"nsf_voiced_threshold": 10,
|
||||
"upsample_rates": [8, 5, 3],
|
||||
"upsample_kernel_sizes": [16, 11, 7],
|
||||
"istft_params": {
|
||||
"n_fft": 16,
|
||||
"hop_len": 4,
|
||||
},
|
||||
"resblock_kernel_sizes": [3, 7, 11],
|
||||
"resblock_dilation_sizes": [[1, 3, 5], [1, 3, 5], [1, 3, 5]],
|
||||
"source_resblock_kernel_sizes": [7, 7, 11],
|
||||
"source_resblock_dilation_sizes": [[1, 3, 5], [1, 3, 5], [1, 3, 5]],
|
||||
"lrelu_slope": 0.1,
|
||||
"audio_limit": 0.99,
|
||||
"conv_pre_look_right": 4,
|
||||
"f0_predictor": {
|
||||
"num_class": 1,
|
||||
"in_channels": 80,
|
||||
"cond_channels": 512,
|
||||
},
|
||||
}
|
||||
@@ -33,7 +33,6 @@ from vllm.v1.sample.metadata import SamplingMetadata
|
||||
from vllm.v1.sample.sampler import Sampler
|
||||
|
||||
from vllm_omni.data_entry_keys import EmbeddingsStruct, OmniPayloadStruct, to_dict, to_struct
|
||||
from vllm_omni.model_executor.models.cosyvoice3.config import CosyVoice3Config
|
||||
from vllm_omni.model_executor.models.cosyvoice3.utils import (
|
||||
concat_text_with_prompt_ids,
|
||||
extract_speech_feat,
|
||||
@@ -42,6 +41,7 @@ from vllm_omni.model_executor.models.cosyvoice3.utils import (
|
||||
extract_text_token,
|
||||
)
|
||||
from vllm_omni.model_executor.models.output_templates import OmniOutput
|
||||
from vllm_omni.transformers_utils.configs.cosyvoice3 import CosyVoice3Config
|
||||
from vllm_omni.utils.speaker_cache import get_speaker_cache
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
@@ -29,7 +29,7 @@ from vllm_omni.model_executor.models.cosyvoice3.code2wav_core.hifigan import (
|
||||
CausalHiFTGenerator,
|
||||
)
|
||||
from vllm_omni.model_executor.models.cosyvoice3.code2wav_core.layers import PreLookaheadLayer
|
||||
from vllm_omni.model_executor.models.cosyvoice3.config import CosyVoice3Config
|
||||
from vllm_omni.transformers_utils.configs.cosyvoice3 import CosyVoice3Config
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""OmniVoice configuration for vLLM-Omni two-stage pipeline."""
|
||||
|
||||
from transformers.configuration_utils import PretrainedConfig
|
||||
|
||||
|
||||
class OmniVoiceConfig(PretrainedConfig):
|
||||
"""Configuration for OmniVoice model in vLLM-Omni.
|
||||
|
||||
This mirrors the HuggingFace OmniVoiceConfig but adds fields needed
|
||||
for the two-stage serving pipeline.
|
||||
"""
|
||||
|
||||
model_type = "omnivoice"
|
||||
|
||||
def get_text_config(self, **kwargs):
|
||||
"""Return self so vLLM uses our top-level config (which has
|
||||
num_attention_heads etc.) instead of trying to extract a sub-config."""
|
||||
return self
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
# HF repos (e.g. k2-fsa/OmniVoice) may nest generation hyperparameters.
|
||||
gen_cfg = kwargs.pop("generation_config", None)
|
||||
if isinstance(gen_cfg, dict):
|
||||
for k, v in gen_cfg.items():
|
||||
kwargs.setdefault(k, v)
|
||||
|
||||
super().__init__(**kwargs)
|
||||
|
||||
# Audio codec params (prefer values set by PretrainedConfig from config.json)
|
||||
self.audio_vocab_size = getattr(self, "audio_vocab_size", 1025)
|
||||
self.audio_mask_id = getattr(self, "audio_mask_id", 1024)
|
||||
self.num_audio_codebook = getattr(self, "num_audio_codebook", 8)
|
||||
self.audio_codebook_weights = getattr(
|
||||
self,
|
||||
"audio_codebook_weights",
|
||||
[8, 8, 6, 6, 4, 4, 2, 2],
|
||||
)
|
||||
|
||||
# LLM backbone params (Qwen3-0.6B defaults from HF config)
|
||||
llm_config = getattr(self, "llm_config", None) or {}
|
||||
if isinstance(llm_config, PretrainedConfig):
|
||||
llm_config = llm_config.to_dict()
|
||||
elif not isinstance(llm_config, dict):
|
||||
llm_config = {}
|
||||
self.llm_hidden_size = llm_config.get("hidden_size", 1024)
|
||||
self.llm_num_hidden_layers = llm_config.get("num_hidden_layers", 28)
|
||||
self.llm_num_attention_heads = llm_config.get("num_attention_heads", 16)
|
||||
self.llm_num_key_value_heads = llm_config.get("num_key_value_heads", 8)
|
||||
self.llm_intermediate_size = llm_config.get("intermediate_size", 3072)
|
||||
self.llm_vocab_size = llm_config.get("vocab_size", 151676)
|
||||
self.llm_max_position_embeddings = llm_config.get("max_position_embeddings", 40960)
|
||||
self.llm_rope_theta = llm_config.get("rope_theta", 1000000.0)
|
||||
self.llm_rms_norm_eps = llm_config.get("rms_norm_eps", 1e-6)
|
||||
self.llm_head_dim = llm_config.get("head_dim", self.llm_hidden_size // self.llm_num_attention_heads)
|
||||
|
||||
# Expose LLM params at top level for vLLM ModelConfig compatibility
|
||||
# (vLLM expects num_attention_heads, hidden_size, etc. on the config)
|
||||
self.num_attention_heads = self.llm_num_attention_heads
|
||||
self.num_key_value_heads = self.llm_num_key_value_heads
|
||||
self.num_hidden_layers = self.llm_num_hidden_layers
|
||||
self.hidden_size = self.llm_hidden_size
|
||||
self.head_dim = self.llm_head_dim
|
||||
if not hasattr(self, "vocab_size"):
|
||||
self.vocab_size = self.llm_vocab_size
|
||||
|
||||
# Generation params (defaults from OmniVoiceGenerationConfig)
|
||||
self.num_step = getattr(self, "num_step", 32)
|
||||
self.guidance_scale = getattr(self, "guidance_scale", 2.0)
|
||||
self.t_shift = getattr(self, "t_shift", 0.1)
|
||||
self.layer_penalty_factor = getattr(self, "layer_penalty_factor", 5.0)
|
||||
self.position_temperature = getattr(self, "position_temperature", 5.0)
|
||||
self.class_temperature = getattr(self, "class_temperature", 0.0)
|
||||
|
||||
# Audio output
|
||||
self.sample_rate = getattr(self, "sample_rate", 24000)
|
||||
self.frame_rate = getattr(self, "frame_rate", 25)
|
||||
|
||||
# Serving
|
||||
self.speculative_config = None
|
||||
@@ -37,8 +37,8 @@ from vllm.multimodal.processing import (
|
||||
)
|
||||
from vllm.sequence import IntermediateTensors
|
||||
|
||||
from vllm_omni.model_executor.models.omnivoice.config import OmniVoiceConfig
|
||||
from vllm_omni.model_executor.models.output_templates import OmniOutput
|
||||
from vllm_omni.transformers_utils.configs.omnivoice import OmniVoiceConfig
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import torch
|
||||
import torch.nn as nn
|
||||
from vllm.logger import init_logger
|
||||
|
||||
from vllm_omni.model_executor.models.omnivoice.config import OmniVoiceConfig
|
||||
from vllm_omni.transformers_utils.configs.omnivoice import OmniVoiceConfig
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import torch.nn as nn
|
||||
import torch.nn.functional as F
|
||||
from vllm.logger import init_logger
|
||||
|
||||
from vllm_omni.model_executor.models.omnivoice.config import OmniVoiceConfig
|
||||
from vllm_omni.transformers_utils.configs.omnivoice import OmniVoiceConfig
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
from .configuration_voxcpm import VoxCPMConfig
|
||||
from .voxcpm import VoxCPMForConditionalGeneration
|
||||
|
||||
__all__ = [
|
||||
"VoxCPMConfig",
|
||||
"VoxCPMForConditionalGeneration",
|
||||
]
|
||||
@@ -1,3 +0,0 @@
|
||||
from vllm_omni.transformers_utils.configs.voxcpm import VoxCPMConfig
|
||||
|
||||
__all__ = ["VoxCPMConfig"]
|
||||
Reference in new issue
Block a user