fix: preserve CosyVoice full payload and live conditioning (#8343)

Signed-off-by: andyluo7 <andy.luo@amd.com>
This commit is contained in:
andyluo7 authored and GitHub committed 2026-10-04 16:03:27 +13:00
1 parent 09d704907f
commit b171731c81
6 files changed
+149 -14

No files matched your search

@@ -74,6 +74,27 @@ logger = init_logger(__name__)
_RUNTIME_COMPONENTS_CACHE: dict[str, dict] = {}
def _normalize_request_conditioning(payload: dict) -> dict:
"""Unwrap singleton conditioning containers at the per-request boundary.
A processor/prefix-cache passthrough can retain a one-item tensor list.
The code2wav schema consumes one request, so that wrapper carries no
batch dimension. A multi-item list here is an unsplit batch and must
fail instead of silently choosing another request's voice.
"""
embed = payload.get("embed")
if not isinstance(embed, Mapping):
return payload
normalized = dict(embed)
for key in ("speech_token", "speech_feat", "embedding", "speech_token_len"):
value = normalized.get(key)
if isinstance(value, (list, tuple)):
if len(value) != 1:
raise ValueError(f"CosyVoice3 per-request {key} contains an unsplit batch of {len(value)} items")
normalized[key] = value[0]
return {**payload, "embed": normalized}
def _cosyvoice3_trt_enabled() -> bool:
"""COSYVOICE3_TRT env toggle (default on) for the optional TensorRT paths.
@@ -1501,9 +1522,10 @@ class CosyVoice3Model(
# [total_tokens, hidden]
hidden_states = self.model.llm(inputs_embeds, positions)
if getattr(self, "_mrv2_tensor_output", False) or cosyvoice3_packed_inference_enabled():
return hidden_states
return self.make_omni_output(hidden_states, **kwargs)
# Both runners attach the live step's conditioning after replay.
# Capturing an OmniOutput here would retain the dummy prefill lists
# and re-emit them during decode, replacing the real reference.
return hidden_states
elif self.model_stage == "cosyvoice3_code2wav":
# Lazily swap the flow-decoder estimator to a TensorRT engine on the
# first code2wav step (after weights are loaded), gated by the same
@@ -1539,7 +1561,7 @@ class CosyVoice3Model(
for idx, req_ids in enumerate(request_ids_list):
raw = runtime_info[idx] if idx < len(runtime_info) and isinstance(runtime_info[idx], dict) else {}
payload = to_struct(raw)
payload = to_struct(_normalize_request_conditioning(raw))
meta = payload.meta
embed = payload.embed