fix: preserve CosyVoice full payload and live conditioning (#8343)
Signed-off-by: andyluo7 <andy.luo@amd.com>
This commit is contained in:
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
|
||||
|
||||
|
||||
@@ -292,7 +292,9 @@ def talker2code2wav_async_chunk(
|
||||
# CONCAT across the (already trivial) per-request accumulator history so a
|
||||
# regression where decode unexpectedly re-emits them does not silently
|
||||
# duplicate the prefill tensor. See mixin._FULL_PAYLOAD_REPLACE_KEYS.
|
||||
_FULL_PAYLOAD_REPLACE_KEYS: frozenset[str] = frozenset({"embed.speech_token", "embed.speech_feat", "embed.embedding"})
|
||||
_FULL_PAYLOAD_REPLACE_KEYS: frozenset[str] = frozenset(
|
||||
{"embed.speech_token", "embed.speech_feat", "embed.embedding", "embed.speech_token_len"}
|
||||
)
|
||||
|
||||
|
||||
def text2flow_token_only(
|
||||
@@ -347,20 +349,20 @@ def text2flow_full_payload(
|
||||
"""
|
||||
del transfer_manager
|
||||
rid = getattr(request, "external_req_id", None) or getattr(request, "request_id", "?")
|
||||
if not isinstance(pooling_output, dict):
|
||||
if not isinstance(pooling_output, Mapping):
|
||||
logger.warning(
|
||||
"cosyvoice3.text2flow_full_payload: pooling_output not a dict "
|
||||
"cosyvoice3.text2flow_full_payload: pooling_output not a mapping "
|
||||
"(type=%s) for req=%s; consumer wait gate may hang.",
|
||||
type(pooling_output).__name__,
|
||||
rid,
|
||||
)
|
||||
return None
|
||||
embed_out: dict[str, Any] = {}
|
||||
for key in ("speech_token", "speech_feat", "embedding"):
|
||||
for key in ("speech_token", "speech_feat", "embedding", "speech_token_len"):
|
||||
v = pooling_output.get(f"embed.{key}")
|
||||
if v is None:
|
||||
nested = pooling_output.get("embed")
|
||||
if isinstance(nested, dict):
|
||||
if isinstance(nested, Mapping):
|
||||
v = nested.get(key)
|
||||
if isinstance(v, torch.Tensor) and v.numel() > 0:
|
||||
embed_out[key] = v
|
||||
|
||||
Reference in new issue
Block a user