[Bugfix] Fix Nemotron VoiceChat duplex nightly handshake (#7884)

Signed-off-by: Sy03 <1370724210@qq.com>
This commit is contained in:
Sy03 authored and GitHub committed 2026-09-25 17:25:15 +00:00
1 parent 5d0963b3dc
commit d31a2a3ba8
26 files changed
+1186 -934

No files matched your search

+50 -3
View File
@@ -3,7 +3,11 @@
from __future__ import annotations
from typing import TypedDict
from collections.abc import Mapping
from typing import TYPE_CHECKING, TypedDict
if TYPE_CHECKING:
from vllm_omni.engine.duplex.contracts import DuplexFence
class DuplexIntermediateBuffer(TypedDict, total=False):
@@ -32,6 +36,49 @@ class DuplexIntermediateBuffer(TypedDict, total=False):
mel_spec: object
def build_duplex_append_prompt(
*,
request_id: str,
fence: DuplexFence,
session_config: Mapping[str, object],
runtime_config: Mapping[str, object],
seq: int,
turn_seq: int,
payload: object,
final: bool,
prompt_token_ids: list[int],
model_fields: Mapping[str, object],
) -> dict[str, object]:
"""Wrap model-selected tokens and payload in the shared append envelope.
Models own token selection and extra worker fields; the framework owns
request identity, sequencing and shallow config snapshots.
"""
return {
"prompt_token_ids": prompt_token_ids,
"model_intermediate_buffer": {
"request_id": request_id,
"global_request_id": [fence.session_id],
"duplex": {
**model_fields,
"data_plane": True,
"fence": fence,
"session_id": fence.session_id,
"epoch": fence.epoch,
"seq": seq,
"turn_id": fence.turn_id,
"turn_seq": turn_seq,
"mode": "append_audio_chunk",
"payload": payload,
"final": final,
"session_config": dict(session_config),
"runtime_config": dict(runtime_config),
"scheduler_token_budget": len(prompt_token_ids),
},
},
}
def build_duplex_intermediate_buffer(
*,
request_id: str,
@@ -62,12 +109,12 @@ def build_duplex_intermediate_buffer(
return buffer
def set_ref_audio(buffer: dict[str, object], waveform: object, sample_rate_hz: int) -> None:
def set_ref_audio(buffer: DuplexIntermediateBuffer, waveform: object, sample_rate_hz: int) -> None:
buffer.setdefault("codes", {})["ref"] = waveform
buffer.setdefault("meta", {})["ref_audio_sr"] = int(sample_rate_hz)
def set_tts_handoff(buffer: dict[str, object], token_ids: object | None, hidden_states: object | None) -> None:
def set_tts_handoff(buffer: DuplexIntermediateBuffer, token_ids: object | None, hidden_states: object | None) -> None:
"""Store the AR-to-TTS handoff used by the full-duplex stage bridge."""
if token_ids is not None:
buffer.setdefault("ids", {})["tts"] = token_ids
+88
View File
@@ -38,6 +38,21 @@ class DuplexRuntimeConfigError(ValueError):
self.code = code
def reject_private_runtime_keys(
extra_body: object,
private_runtime_config_keys: frozenset[str],
*,
message: str,
error_cls: type[DuplexRuntimeConfigError] = DuplexRuntimeConfigError,
) -> None:
"""Reject client overrides while preserving each plugin's error contract."""
if not isinstance(extra_body, dict):
return
private_keys = sorted(private_runtime_config_keys.intersection(extra_body))
if private_keys:
raise error_cls(message + ", ".join(private_keys))
def reject_changed_runtime_value(
new_value: object,
current_value: object,
@@ -146,6 +161,64 @@ class DuplexModelSessionState(ABC):
def clear_continuation(self) -> None: ...
@dataclass(slots=True)
class DefaultDuplexModelSessionState(DuplexModelSessionState):
"""Framework-owned flag anatomy, implemented once.
The flag set above is the session runner's contract with the model (commit
retention, deferred response/creates, silence-continuation bookkeeping); it
is identical for every lockstep or frame-locked model, so a plugin only
supplies its input packetizer as ``audio_buffer``.
"""
audio_buffer: PcmAppendBuffer
input_since_commit: bool = False
speech_since_commit: bool = False
context_locked: bool = False
committed_audio_payload: dict[str, object] | None = None
committed_audio_operation_id: str | None = None
committed_audio_reserved_bytes: int = 0
deferred_response_create: bool = False
deferred_precreate_response: bool = False
continuation_owner_id: str | None = None
continuation_units: int = 0
pending_silence_task: asyncio.Task[bool] | None = None
pending_silence_owner_id: str | None = None
# Deadline-aligned silence continuation state: the monotonic submission
# time of the most recent native input unit and the next silence
# continuation deadline. A real (non-silence) input resets the chain.
last_native_submit_monotonic: float | None = None
silence_deadline_monotonic: float | None = None
def retain_committed_audio(
self,
payload: dict[str, object],
*,
operation_id: str | None,
reserved_bytes: int = 0,
) -> None:
self.committed_audio_payload = payload
self.committed_audio_operation_id = operation_id
self.committed_audio_reserved_bytes += max(0, int(reserved_bytes))
def clear_committed_audio(self) -> int:
reserved_bytes = self.committed_audio_reserved_bytes
self.committed_audio_payload = None
self.committed_audio_operation_id = None
self.committed_audio_reserved_bytes = 0
self.deferred_response_create = False
self.deferred_precreate_response = False
return reserved_bytes
def clear_continuation(self) -> None:
self.continuation_owner_id = None
self.continuation_units = 0
self.pending_silence_task = None
self.pending_silence_owner_id = None
self.last_native_submit_monotonic = None
self.silence_deadline_monotonic = None
class DuplexDataPlane(ABC):
"""Projects raw stage outputs of one model into internal duplex events."""
@@ -397,6 +470,20 @@ class DuplexModelPlugin(ABC):
del config, current, item
return None
def runtime_config_after_model_output(
self,
current: Mapping[str, object],
output_metadata: Mapping[str, object],
) -> dict[str, object] | None:
"""Return a runtime-config patch after a model output is observed.
Plugins may use model-owned output metadata to retire server-side
runtime state that has been consumed by the worker. The default keeps
the framework unaware of model-specific metadata.
"""
del current, output_metadata
return None
def load_duplex_plugin(path: str, encode_audio: EncodeAudio) -> DuplexModelPlugin:
module_name, separator, attribute_name = path.rpartition(".")
@@ -448,6 +535,7 @@ def coerce_int(value: object) -> int | None:
__all__ = [
"DefaultDuplexModelSessionState",
"DuplexDataPlane",
"DuplexModelPlugin",
"DuplexModelSessionState",
@@ -569,6 +569,12 @@ class ModelChannel:
):
return
engine_output = self._build_stage_output(item)
runtime_config = self._ctx.plugin.runtime_config_after_model_output(
dict(session.runtime_config),
item.context.segment_output_metadata,
)
if runtime_config is not None:
session.replace_runtime_config(runtime_config)
drain_result = {"data_plane_outputs": [engine_output]}
close_reason, emitted_response = await self._send_model_output_events(
drain_result, expected_epoch=expected_epoch