[Bugfix][MiniCPM-o] Prevent native duplex Stage-1 prompt overflow

Signed-off-by: Sy03 <1370724210@qq.com>
This commit is contained in:
Sy03 committed 2026-08-24 05:13:31 +08:00
1 parent 1c917b2751
commit 5edee1393a
32 files changed
+1591 -99

No files matched your search

@@ -550,6 +550,35 @@ def _native_tts_boundary_token_ids(special_token_ids):
}
def _native_duplex_output_is_control_only(
output_ids: Sequence[int],
special_token_ids: Mapping[str, int],
) -> bool:
"""Whether a native output is a confirmed no-speech handoff.
Empty and control/terminal-only deltas intentionally have no Talker
conditioning. Any ordinary text or explicit speech boundary is not a
confirmed no-op and must retain the missing-hidden-state error path.
"""
if not output_ids:
return True
control_ids = {
token_id
for token_id in (
special_token_ids.get("tts_eos_token_id"),
special_token_ids.get("tts_pad_token_id"),
special_token_ids.get("listen_token_id"),
special_token_ids.get("chunk_eos_token_id"),
special_token_ids.get("chunk_tts_eos_token_id"),
special_token_ids.get("turn_eos_token_id"),
special_token_ids.get("unit_token_id"),
special_token_ids.get("unit_end_token_id"),
)
if token_id is not None
}
return bool(control_ids) and all(token_id in control_ids for token_id in output_ids)
def _decode_native_duplex_token_ids(
token_ids: list[int],
streaming_context,
@@ -757,10 +786,23 @@ def llm2tts(
)
prompt_token_ids_len = len(prompt_token_ids)
is_native_duplex_handoff = _has_native_duplex_prompt_metadata(mm_output)
latent = mm_output.get("latent", None)
if latent is None:
latent = output.hidden_states if hasattr(output, "hidden_states") else None
if latent is None:
if is_native_duplex_handoff and _native_duplex_output_is_control_only(
llm_output_ids, special_token_ids
):
# Listen/control/terminal outputs have no Talker payload by
# design. They are a successful no-op handoff, not a stage
# failure, so do not let one such unit stop the orchestrator.
logger.debug(
"Skipping no-speech MiniCPM-o native duplex handoff for request_id=%s",
llm_output.request_id,
)
continue
raise ValueError("No latent or hidden_states found in thinker output")
thinker_hidden_states = latent.detach()
@@ -771,7 +813,6 @@ def llm2tts(
full_token_ids = prompt_token_ids + llm_output_ids
tts_bos_id = special_token_ids.get("tts_bos_token_id")
is_native_duplex_handoff = _has_native_duplex_prompt_metadata(mm_output)
if is_native_duplex_handoff:
_require_native_tts_boundary_metadata(special_token_ids)
tts_end_ids = _native_tts_boundary_token_ids(special_token_ids)