Revert "[Doc][Frontend][Model][VoxCPM2] Support instructions and per-request …"
This reverts commit 1069a144a8.
This commit is contained in:
1 parent
9de131e6b0
commit
3adae7ca6f
5 files changed
+9
-472
No files matched your search
@@ -83,12 +83,7 @@ class OpenAICreateSpeechRequest(BaseModel):
|
||||
)
|
||||
extra_params: dict[str, Any] | None = Field(
|
||||
default=None,
|
||||
description=(
|
||||
"Optional model-specific parameters passed directly to the model's extra_args. "
|
||||
"VoxCPM2 reads `cfg_value` (float in 0.1-10.0; default 2.0) from this dict to set "
|
||||
"the classifier-free guidance scale per request; Voxtral TTS reads `cfg_alpha` here "
|
||||
"the same way."
|
||||
),
|
||||
description=("Optional model-specific parameters passed directly to the model's extra_args."),
|
||||
)
|
||||
|
||||
@field_validator("stream_format")
|
||||
|
||||
@@ -492,39 +492,15 @@ class OmniOpenAIServingSpeech(OpenAIServing, AudioMixin):
|
||||
ref_sr = None
|
||||
if request.ref_audio is not None:
|
||||
ref_audio, ref_sr = await self._resolve_ref_audio(request.ref_audio)
|
||||
# VoxCPM2 uses a text-prefix convention for style/voice instructions:
|
||||
# the native CLI wraps the instruction in parens and prepends it.
|
||||
# Mirror that here so `instructions` works through the OpenAI endpoint.
|
||||
# The Hi-Fi Cloning mode (ref_audio + ref_text) + instructions combo
|
||||
# is rejected upstream in `_validate_tts_request`, so by the time we
|
||||
# reach this builder we can assume the combination is valid.
|
||||
text = request.input
|
||||
if request.instructions:
|
||||
text = f"({request.instructions.strip()}){text}"
|
||||
prompt = build_voxcpm2_prompt(
|
||||
return build_voxcpm2_prompt(
|
||||
hf_config=self.engine_client.model_config.hf_config,
|
||||
tokenizer=self._voxcpm2_tokenizer,
|
||||
split_map=self._voxcpm2_split_map,
|
||||
text=text,
|
||||
text=request.input,
|
||||
ref_audio=ref_audio,
|
||||
ref_sr=ref_sr,
|
||||
ref_text=request.ref_text,
|
||||
)
|
||||
# Per-request cfg_value threads via additional_information; the talker
|
||||
# lifts it onto _RequestState in preprocess() and uses it in _run_cfm.
|
||||
# Following the convention from #2338 (Voxtral TTS / cfg_alpha), the
|
||||
# value is provided via the shared `extra_params` dict rather than as
|
||||
# a top-level protocol field, keeping OpenAICreateSpeechRequest free
|
||||
# of model-specific knobs.
|
||||
if request.extra_params and "cfg_value" in request.extra_params:
|
||||
try:
|
||||
cfg_value = float(request.extra_params["cfg_value"])
|
||||
except (TypeError, ValueError) as e:
|
||||
raise ValueError(f"extra_params['cfg_value'] must be a number: {e}") from e
|
||||
if not 0.1 <= cfg_value <= 10.0:
|
||||
raise ValueError(f"extra_params['cfg_value']={cfg_value} out of range (0.1-10.0)")
|
||||
prompt.setdefault("additional_information", {})["cfg_value"] = cfg_value
|
||||
return prompt
|
||||
|
||||
def _get_uploaded_audio_data(self, voice_name: str) -> str | None:
|
||||
"""Get base64 encoded audio data for uploaded voice."""
|
||||
@@ -880,27 +856,7 @@ class OmniOpenAIServingSpeech(OpenAIServing, AudioMixin):
|
||||
if self._tts_model_type == "voxcpm":
|
||||
return self._validate_voxcpm_request(request)
|
||||
if self._tts_model_type == "voxcpm2":
|
||||
# Hi-Fi Cloning mode (`ref_audio` + `ref_text`) does not use the
|
||||
# control instruction. Upstream voxcpm CLI errors out on the same
|
||||
# combination (src/voxcpm/cli.py:128-131: --control cannot be used
|
||||
# together with --prompt-text); we surface a 400 to match instead
|
||||
# of silently dropping user input.
|
||||
if request.instructions and request.ref_text:
|
||||
return (
|
||||
"`instructions` is incompatible with `ref_text` in Hi-Fi Cloning "
|
||||
"mode (the control instruction is ignored when ref_text is set)."
|
||||
)
|
||||
# Cap `instructions` length for parity with qwen3_tts / voxtral /
|
||||
# fish_tts (prevents blowing the prefill budget via an unbounded
|
||||
# parenthetical prefix). Upstream voxcpm has no cap; this is a
|
||||
# serving-side safety net, see PR #3118 discussion.
|
||||
if request.instructions and len(request.instructions) > self._max_instructions_length:
|
||||
return (
|
||||
f"Instructions too long ({len(request.instructions)}/"
|
||||
f"{self._max_instructions_length} chars). Upstream voxcpm has no cap; "
|
||||
f"this limit prevents exceeding the prefill budget."
|
||||
)
|
||||
return None
|
||||
return None # VoxCPM2 accepts any text input
|
||||
if self._tts_model_type == "ming_flash_omni_tts":
|
||||
return self._validate_ming_tts_request(request)
|
||||
if self._tts_model_type == "moss_tts_nano":
|
||||
@@ -1761,12 +1717,6 @@ class OmniOpenAIServingSpeech(OpenAIServing, AudioMixin):
|
||||
if request.instructions:
|
||||
prompt["instruct"] = request.instructions
|
||||
elif self._tts_model_type == "voxcpm2":
|
||||
# Run the same validator the batch endpoint uses so single-request
|
||||
# /v1/audio/speech enforces the instructions-length cap and any
|
||||
# other voxcpm2-specific checks (e.g. Hi-Fi mode + instructions).
|
||||
validation_error = self._validate_tts_request(request)
|
||||
if validation_error:
|
||||
raise ValueError(validation_error)
|
||||
prompt = await self._build_voxcpm2_prompt(request)
|
||||
tts_params = {}
|
||||
elif self._is_tts:
|
||||
|
||||
@@ -185,8 +185,6 @@ class _RequestState:
|
||||
prefill_masks: tuple | None = None
|
||||
is_stopping: bool = False
|
||||
last_decoded_audio: torch.Tensor | None = None
|
||||
# Per-request classifier-free guidance override (None -> talker default).
|
||||
cfg_value: float | None = None
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
@@ -892,8 +890,7 @@ class VoxCPM2TalkerForConditionalGeneration(nn.Module):
|
||||
res_input = tts.fusion_concat_proj(torch.cat([lm_h, prev], dim=-1))
|
||||
return res_input, {"new_lm_hidden": lm_h}
|
||||
|
||||
def _run_cfm(self, dit_h: torch.Tensor, cond: torch.Tensor, cfg_value: float | None = None) -> torch.Tensor:
|
||||
cfg = self._cfg_value if cfg_value is None else float(cfg_value)
|
||||
def _run_cfm(self, dit_h: torch.Tensor, cond: torch.Tensor) -> torch.Tensor:
|
||||
if self._cfm_buffers is not None:
|
||||
return _optimized_solve_euler(
|
||||
self.tts.feat_decoder,
|
||||
@@ -901,7 +898,7 @@ class VoxCPM2TalkerForConditionalGeneration(nn.Module):
|
||||
self._patch_size,
|
||||
cond,
|
||||
self._inference_timesteps,
|
||||
cfg,
|
||||
self._cfg_value,
|
||||
self._cfm_buffers,
|
||||
cfg_cutoff_ratio=self._cfg_cutoff_ratio,
|
||||
perf=self._perf,
|
||||
@@ -911,7 +908,7 @@ class VoxCPM2TalkerForConditionalGeneration(nn.Module):
|
||||
patch_size=self._patch_size,
|
||||
cond=cond,
|
||||
n_timesteps=self._inference_timesteps,
|
||||
cfg_value=cfg,
|
||||
cfg_value=self._cfg_value,
|
||||
).transpose(1, 2)
|
||||
|
||||
def _finish_prefill(self, state: _RequestState, meta: dict, res_out: torch.Tensor, dev: Any):
|
||||
@@ -927,7 +924,7 @@ class VoxCPM2TalkerForConditionalGeneration(nn.Module):
|
||||
if self._enable_torch_compile:
|
||||
self._setup_torch_compile()
|
||||
|
||||
pred_feat = self._run_cfm(dit_h, prefix_feat_cond.transpose(1, 2).contiguous(), cfg_value=state.cfg_value)
|
||||
pred_feat = self._run_cfm(dit_h, prefix_feat_cond.transpose(1, 2).contiguous())
|
||||
|
||||
with torch.no_grad():
|
||||
curr_embed = tts.enc_to_lm_proj(tts.feat_encoder(pred_feat.unsqueeze(1))).squeeze(1)
|
||||
@@ -960,7 +957,7 @@ class VoxCPM2TalkerForConditionalGeneration(nn.Module):
|
||||
if pfc.ndim == 2:
|
||||
pfc = pfc.unsqueeze(0)
|
||||
|
||||
pred_feat = self._run_cfm(dit_h, pfc.transpose(1, 2).contiguous(), cfg_value=state.cfg_value)
|
||||
pred_feat = self._run_cfm(dit_h, pfc.transpose(1, 2).contiguous())
|
||||
next_embed = tts.enc_to_lm_proj(tts.feat_encoder(pred_feat.unsqueeze(1))).squeeze(1)
|
||||
|
||||
state.precomputed_stop_logits = stop_fn(lm_h).detach()
|
||||
@@ -1143,9 +1140,6 @@ class VoxCPM2TalkerForConditionalGeneration(nn.Module):
|
||||
state.is_stopping = False
|
||||
state.last_decoded_audio = None
|
||||
|
||||
# Per-request cfg_value override (threaded via additional_information).
|
||||
state.cfg_value = info_dict.get("cfg_value")
|
||||
|
||||
# Voice clone / continuation
|
||||
ref_audio = info_dict.get("reference_audio") or info_dict.get("ref_audio")
|
||||
prompt_audio = info_dict.get("prompt_audio")
|
||||
|
||||
Reference in new issue
Block a user