[Model] Preserve MiniCPM-o Talker full attention until capacity (#6799)
Signed-off-by: natureofnature <wzliu@connect.hku.hk> Co-authored-by: amy-why-3459 <wuhaiyan17@huawei.com>
This commit is contained in:
1 parent
715b8b8746
commit
ff6e906a25
12 files changed
+913
-108
No files matched your search
@@ -6,6 +6,7 @@ from __future__ import annotations
|
||||
import time
|
||||
from collections import defaultdict
|
||||
from collections.abc import Iterable, Iterator
|
||||
from dataclasses import replace
|
||||
from typing import Any
|
||||
|
||||
import numpy as np
|
||||
@@ -763,11 +764,15 @@ class OmniARScheduler(OmniSchedulerMixin, VLLMScheduler):
|
||||
return engine_core_outputs
|
||||
|
||||
def _update_request_as_session(self, session: Request, update: StreamingUpdate) -> None:
|
||||
"""
|
||||
Override: Only extend prompt at stage 0, and replace
|
||||
the existing session with the next streaming update at other stages.
|
||||
"""Apply the next streaming update to a persistent session.
|
||||
|
||||
Discards the last sampled output token from the prior input chunk at stage 0.
|
||||
Stage 0 uses upstream prompt extension. A MiniCPM Talker preserves its
|
||||
accumulated prompt while it fits, then rebuilds a bounded window and
|
||||
re-enters admission. Other downstream stages retain their existing
|
||||
replacement or connector-polling behavior.
|
||||
|
||||
Discards the last sampled output token from the prior input chunk at
|
||||
stage 0.
|
||||
"""
|
||||
req_id = session.request_id
|
||||
self._new_prompt_len_snapshot[req_id] = len(update.prompt_token_ids)
|
||||
@@ -818,6 +823,56 @@ class OmniARScheduler(OmniSchedulerMixin, VLLMScheduler):
|
||||
if self.log_stats:
|
||||
session.record_event(EngineCoreEventType.QUEUED)
|
||||
return
|
||||
streaming_prompt_payload = next(
|
||||
(
|
||||
info
|
||||
for info in update_infos
|
||||
if isinstance(info, dict)
|
||||
and isinstance(info.get("meta"), dict)
|
||||
and "next_stage_prompt_len" in info["meta"]
|
||||
),
|
||||
None,
|
||||
)
|
||||
update_streaming_prompt = getattr(
|
||||
self.chunk_transfer_adapter,
|
||||
"update_streaming_prompt_for_condition",
|
||||
None,
|
||||
)
|
||||
if stage_id != 0 and streaming_prompt_payload is not None and callable(update_streaming_prompt):
|
||||
mm_feature_base = session.num_computed_tokens
|
||||
try:
|
||||
replaced = update_streaming_prompt(
|
||||
streaming_prompt_payload,
|
||||
session,
|
||||
update_prompt=True,
|
||||
)
|
||||
except ValueError as exc:
|
||||
# This streaming update has already been dequeued. Report the
|
||||
# permanent contract failure so the next scheduling pass
|
||||
# finishes only this request instead of crashing EngineCore.
|
||||
self.chunk_transfer_adapter.record_receive_failure(req_id, str(exc))
|
||||
return
|
||||
if replaced is not None:
|
||||
if replaced:
|
||||
# The window recipe needs the old prompt and confirmed
|
||||
# codec ids, so it runs before their KV/encoder state is
|
||||
# released. The rebuilt prompt is then admitted from zero.
|
||||
self._release_replaced_streaming_prompt_cache(session)
|
||||
self._reset_streaming_session_replacement_state(session)
|
||||
else:
|
||||
session._omni_segment_generation = int(getattr(session, "_omni_segment_generation", 0) or 0) + 1
|
||||
if update.mm_features:
|
||||
# Match upstream streaming-session extension semantics.
|
||||
# The helper has already appended this condition, so use
|
||||
# the pre-append confirmed length as the MM offset base.
|
||||
for mm_feature in update.mm_features:
|
||||
mm_feature.mm_position = replace(
|
||||
mm_feature.mm_position,
|
||||
offset=mm_feature.mm_position.offset + mm_feature_base,
|
||||
)
|
||||
session.mm_features.extend(update.mm_features)
|
||||
self._finish_streaming_session_update(session, update)
|
||||
return
|
||||
replace_streaming_prompt = any(
|
||||
isinstance(info, dict)
|
||||
and isinstance(info.get("meta"), dict)
|
||||
|
||||
@@ -147,8 +147,8 @@ class OmniSchedulerMixin:
|
||||
if input_coordinator is not None:
|
||||
input_coordinator.free_finished_request(request_id)
|
||||
|
||||
def _replace_streaming_session(self, session: Request, update: StreamingUpdate) -> None:
|
||||
"""Replace a downstream stage's placeholder with its next payload."""
|
||||
def _reset_streaming_session_replacement_state(self, session: Request) -> None:
|
||||
"""Fence transport and async state that belongs to an old prompt."""
|
||||
session._omni_segment_generation = int(getattr(session, "_omni_segment_generation", 0) or 0) + 1
|
||||
adapter = getattr(self, "chunk_transfer_adapter", None)
|
||||
if adapter is not None:
|
||||
@@ -156,8 +156,6 @@ class OmniSchedulerMixin:
|
||||
watermark = getattr(adapter, "requests_num_chunks_sent", None)
|
||||
if watermark is not None:
|
||||
watermark.pop(session.external_req_id, None)
|
||||
session._output_token_ids.clear()
|
||||
session._all_token_ids.clear()
|
||||
# In-flight outputs from the previous segment were optimistically
|
||||
# scheduled (async lookahead). Mark them stale so update_from_output
|
||||
# drops them instead of underflowing num_output_placeholders
|
||||
@@ -172,18 +170,15 @@ class OmniSchedulerMixin:
|
||||
session.num_stale_output_tokens = int(getattr(session, "num_in_flight_tokens", 0) or 0)
|
||||
session.num_output_placeholders = 0
|
||||
session.spec_token_ids = []
|
||||
new_prompt = update.prompt_token_ids or ()
|
||||
session._all_token_ids.extend(new_prompt)
|
||||
session.num_computed_tokens = 0
|
||||
session.prompt_token_ids = new_prompt
|
||||
|
||||
def _finish_streaming_session_update(self, session: Request, update: StreamingUpdate) -> None:
|
||||
"""Install payload metadata and send an updated session to admission."""
|
||||
session.additional_information = update.additional_information or None
|
||||
session.model_intermediate_buffer = getattr(
|
||||
update,
|
||||
"model_intermediate_buffer",
|
||||
None,
|
||||
)
|
||||
session.update_block_hashes()
|
||||
session.num_prompt_tokens = len(new_prompt)
|
||||
session.arrival_time = update.arrival_time
|
||||
session.sampling_params = update.sampling_params
|
||||
if session.status == RequestStatus.WAITING_FOR_STREAMING_REQ:
|
||||
@@ -195,6 +190,19 @@ class OmniSchedulerMixin:
|
||||
if self.log_stats:
|
||||
session.record_event(EngineCoreEventType.QUEUED)
|
||||
|
||||
def _replace_streaming_session(self, session: Request, update: StreamingUpdate) -> None:
|
||||
"""Replace a downstream stage's placeholder with its next payload."""
|
||||
self._reset_streaming_session_replacement_state(session)
|
||||
session._output_token_ids.clear()
|
||||
session._all_token_ids.clear()
|
||||
new_prompt = update.prompt_token_ids or ()
|
||||
session._all_token_ids.extend(new_prompt)
|
||||
session.num_computed_tokens = 0
|
||||
session.prompt_token_ids = new_prompt
|
||||
session.update_block_hashes()
|
||||
session.num_prompt_tokens = len(new_prompt)
|
||||
self._finish_streaming_session_update(session, update)
|
||||
|
||||
def _release_replaced_streaming_prompt_cache(self, session: Request) -> None:
|
||||
"""Discard cache state that belongs to a replaced prompt."""
|
||||
# A prompt replacement is not a normal streaming extension: none of
|
||||
@@ -272,7 +280,7 @@ class OmniSchedulerMixin:
|
||||
self._log_failed_chunk_sends()
|
||||
|
||||
def _process_chunk_receive_failures(self) -> None:
|
||||
"""Fail requests whose consumed async chunk violated its contract."""
|
||||
"""Fail requests whose consumed streaming input violated its contract."""
|
||||
adapter = getattr(self, "chunk_transfer_adapter", None)
|
||||
collector = getattr(adapter, "collect_failed_receive_request_ids", None)
|
||||
if collector is None:
|
||||
@@ -282,7 +290,7 @@ class OmniSchedulerMixin:
|
||||
if not present_ids:
|
||||
return
|
||||
logger.error(
|
||||
"Marking %d request(s) as FINISHED_ERROR after invalid connector input: %s",
|
||||
"Marking %d request(s) as FINISHED_ERROR after invalid streaming input: %s",
|
||||
len(present_ids),
|
||||
{request_id: failures[request_id] for request_id in sorted(present_ids)},
|
||||
)
|
||||
|
||||
@@ -64,13 +64,8 @@ stages:
|
||||
|
||||
- stage_id: 1
|
||||
max_num_seqs: 4
|
||||
# Native duplex uses MiniCPMTTS.generate_with_buffer's supported
|
||||
# sliding_recompute policy: retain one completed condition/codec chunk
|
||||
# when the next condition arrives. Other deploy profiles continue to use
|
||||
# the checkpoint's full_attention policy.
|
||||
hf_overrides:
|
||||
tts_config:
|
||||
attention_type: sliding_recompute
|
||||
# Preserve the checkpoint's full-attention Talker prompt while it fits;
|
||||
# native duplex rolls over to a one-chunk window at context capacity.
|
||||
# Leave device-level headroom for the colocated HiFi-GAN cuDNN workspace.
|
||||
gpu_memory_utilization: 0.15
|
||||
enforce_eager: false
|
||||
@@ -118,8 +113,10 @@ platforms:
|
||||
cuda:
|
||||
stages:
|
||||
- stage_id: 1
|
||||
# Four Talker streams need much less KV than automatic sizing.
|
||||
# Leave single-GPU headroom for concurrent Stage 2 diffusion batches.
|
||||
# Full-attention occupancy is bounded by max_num_seqs * max_model_len
|
||||
# (4 * 4096 = 16384 tokens). Keep the reported CUDA KV token capacity
|
||||
# above that bound because physical-preemption replay is unsupported.
|
||||
# The explicit cap leaves device headroom for concurrent Stage 2.
|
||||
kv_cache_memory_bytes: 2147483648 # 2 GiB
|
||||
|
||||
npu:
|
||||
|
||||
@@ -227,16 +227,21 @@ def construct_next_stage_streaming_input_prompt(
|
||||
previous_condition_seq: int | None = None,
|
||||
condition_seq: int | None = None,
|
||||
recompute_previous_chunks: int = 0,
|
||||
recompute_on_capacity: bool = False,
|
||||
) -> bool:
|
||||
"""Update a downstream streaming request prompt from connector payload ids.
|
||||
"""Update a downstream streaming request prompt from connector payload.
|
||||
|
||||
Async-chunk downstream stages are prewarmed before the real Talker prompt is
|
||||
known. When a Thinker payload carries ``ids.prompt``, this helper:
|
||||
known. When a Thinker payload carries ``ids.prompt`` or declares the
|
||||
placeholder length in ``meta.next_stage_prompt_len``, this helper:
|
||||
|
||||
* Preserves ``num_computed_tokens`` while extending a non-window prompt.
|
||||
Explicit replacements and one-condition window recomputes reset it.
|
||||
Explicit replacements and one-condition window recomputes reset it. A
|
||||
full-attention Talker recomputes only when the next condition would
|
||||
exceed its context limit.
|
||||
* Moves already-computed output tokens into ``prompt_token_ids``.
|
||||
* Appends a new placeholder prompt slice sized from the upstream ids.
|
||||
* Appends a placeholder slice using the declared downstream prompt length,
|
||||
or derives its length from ``ids.prompt`` for legacy producers.
|
||||
* Refreshes block hashes so the scheduler allocates KV slots for the
|
||||
extended prompt without discarding prior computed state.
|
||||
"""
|
||||
@@ -285,13 +290,29 @@ def construct_next_stage_streaming_input_prompt(
|
||||
explicit_replacement = meta.get("replace_streaming_prompt") is True
|
||||
if isinstance(recompute_previous_chunks, bool) or recompute_previous_chunks not in (0, 1):
|
||||
raise ValueError("streaming prompt recompute supports exactly one previous chunk")
|
||||
if not isinstance(recompute_on_capacity, bool):
|
||||
raise ValueError("recompute_on_capacity must be a bool")
|
||||
has_window_contract = recompute_previous_chunks == 1
|
||||
window_recompute = not explicit_replacement and has_window_contract and previous_condition_seq is not None
|
||||
if recompute_on_capacity and not has_window_contract:
|
||||
raise ValueError("capacity-triggered streaming prompt recompute requires window_size=1")
|
||||
if (
|
||||
recompute_on_capacity
|
||||
and not explicit_replacement
|
||||
and previous_condition_seq is not None
|
||||
and generation_reserve == 0
|
||||
):
|
||||
raise ValueError("capacity-triggered streaming prompt recompute requires a positive generation reserve")
|
||||
exceeds_accumulated_capacity = (
|
||||
managed_prompt_len is not None
|
||||
and capacity_limit is not None
|
||||
and request.num_computed_tokens + managed_prompt_len + generation_reserve > capacity_limit
|
||||
)
|
||||
window_recompute = (
|
||||
not explicit_replacement
|
||||
and has_window_contract
|
||||
and previous_condition_seq is not None
|
||||
and (exceeds_accumulated_capacity if recompute_on_capacity else True)
|
||||
)
|
||||
if not explicit_replacement and exceeds_accumulated_capacity and not window_recompute:
|
||||
raise ValueError("capacity-managed streaming prompt rollover requires window_size=1")
|
||||
replacement_prompt_len = next_stage_prompt_len
|
||||
@@ -369,7 +390,12 @@ def construct_next_stage_streaming_input_prompt(
|
||||
request.update_block_hashes()
|
||||
return True
|
||||
prompt_token_ids = ids.get("prompt", None)
|
||||
if not prompt_token_ids:
|
||||
has_declared_prompt_len = (
|
||||
isinstance(next_stage_prompt_len, int)
|
||||
and not isinstance(next_stage_prompt_len, bool)
|
||||
and next_stage_prompt_len > 0
|
||||
)
|
||||
if not has_declared_prompt_len and not prompt_token_ids:
|
||||
return False
|
||||
num_computed_tokens = request.num_computed_tokens
|
||||
kept_output_tokens = request._all_token_ids[request.num_prompt_tokens : num_computed_tokens]
|
||||
@@ -378,7 +404,7 @@ def construct_next_stage_streaming_input_prompt(
|
||||
assert request.prompt_token_ids is not None
|
||||
# Extend prompt with kept output tokens.
|
||||
request.prompt_token_ids.extend(kept_output_tokens)
|
||||
if isinstance(next_stage_prompt_len, int) and next_stage_prompt_len > 0:
|
||||
if has_declared_prompt_len:
|
||||
next_prompt_len = next_stage_prompt_len
|
||||
else:
|
||||
next_prompt_len = max(1, compute_talker_prompt_ids_length(prompt_token_ids))
|
||||
|
||||
@@ -51,13 +51,21 @@ class _LoadEntry:
|
||||
return self.request.external_req_id
|
||||
|
||||
|
||||
def _resolve_talker_streaming_prompt_config(model_config: Any) -> tuple[int, int]:
|
||||
"""Return the effective Talker context limit and recompute window."""
|
||||
def _resolve_talker_streaming_prompt_config(model_config: Any) -> tuple[int, int, bool]:
|
||||
"""Return the Talker context limit and streaming recompute policy."""
|
||||
max_model_len = int(getattr(model_config, "max_model_len", 0) or 0)
|
||||
if getattr(model_config, "hf_config_name", None) != "tts_config":
|
||||
return max_model_len, 0, False
|
||||
hf_config = getattr(model_config, "hf_config", None)
|
||||
tts_config = getattr(hf_config, "tts_config", None)
|
||||
if tts_config is None and getattr(hf_config, "model_type", None) == "minicpmtts":
|
||||
if tts_config is None:
|
||||
tts_config = hf_config
|
||||
if isinstance(tts_config, Mapping):
|
||||
tts_model_type = tts_config.get("model_type")
|
||||
else:
|
||||
tts_model_type = getattr(tts_config, "model_type", None)
|
||||
if tts_model_type not in {"conditional_chattts", "minicpmtts"}:
|
||||
return max_model_len, 0, False
|
||||
tts_max_model_len = (
|
||||
tts_config.get("max_position_embeddings", 0)
|
||||
if isinstance(tts_config, Mapping)
|
||||
@@ -71,11 +79,17 @@ def _resolve_talker_streaming_prompt_config(model_config: Any) -> tuple[int, int
|
||||
if isinstance(tts_config, Mapping)
|
||||
else getattr(tts_config, "attention_type", None)
|
||||
)
|
||||
# Official MiniCPMTTS supports both full_attention and
|
||||
# sliding_recompute. Only an explicit Talker-stage policy enables the
|
||||
# latter; native duplex alone must not override checkpoint semantics.
|
||||
previous_chunks = 1 if attention_type == "sliding_recompute" else 0
|
||||
return max_model_len, previous_chunks
|
||||
if tts_config is not None and attention_type is None:
|
||||
attention_type = "full_attention"
|
||||
# ``full_attention`` keeps the complete prompt until its next condition
|
||||
# would exceed the Talker context. It then falls back to the same supported
|
||||
# one-previous-chunk recompute recipe. An explicitly configured
|
||||
# ``sliding_recompute`` applies that recipe at every condition boundary.
|
||||
if attention_type == "sliding_recompute":
|
||||
return max_model_len, 1, False
|
||||
if attention_type == "full_attention":
|
||||
return max_model_len, 1, True
|
||||
return max_model_len, 0, False
|
||||
|
||||
|
||||
class OmniChunkTransferAdapter(OmniTransferAdapterBase):
|
||||
@@ -113,9 +127,11 @@ class OmniChunkTransferAdapter(OmniTransferAdapterBase):
|
||||
self._registered_load_entries: dict[str, _LoadEntry] = {}
|
||||
self._sender_tokens: dict[str, _SenderGeneration] = {}
|
||||
self.scheduler_max_num_seqs = vllm_config.scheduler_config.max_num_seqs
|
||||
self._max_model_len, self._streaming_prompt_previous_chunks = _resolve_talker_streaming_prompt_config(
|
||||
model_config
|
||||
)
|
||||
(
|
||||
self._max_model_len,
|
||||
self._streaming_prompt_previous_chunks,
|
||||
self._streaming_prompt_recompute_on_capacity,
|
||||
) = _resolve_talker_streaming_prompt_config(model_config)
|
||||
active_stream_window = int(getattr(model_config, "active_stream_window", 0) or 0)
|
||||
model_max_num_seqs = int(getattr(model_config, "max_num_seqs", self.scheduler_max_num_seqs) or 0)
|
||||
if model_max_num_seqs <= 0:
|
||||
@@ -962,6 +978,99 @@ class OmniChunkTransferAdapter(OmniTransferAdapterBase):
|
||||
self._promote_active_streams(waiting_queue)
|
||||
self._preempt_non_active_running(waiting_queue, running_queue)
|
||||
|
||||
def update_streaming_prompt_for_condition(
|
||||
self,
|
||||
payload_data: dict[str, Any],
|
||||
request: Request,
|
||||
*,
|
||||
update_prompt: bool,
|
||||
) -> bool | None:
|
||||
"""Track one Talker condition and optionally update its prompt.
|
||||
|
||||
Returns ``None`` when the payload is not governed by the Talker
|
||||
streaming-window contract. Otherwise returns whether the prompt was
|
||||
replaced, as opposed to extended in place.
|
||||
"""
|
||||
if self._streaming_prompt_previous_chunks != 1:
|
||||
return None
|
||||
meta = payload_data.get("meta")
|
||||
if not isinstance(meta, dict):
|
||||
return None
|
||||
condition_len = meta.get("next_stage_prompt_len")
|
||||
if not isinstance(condition_len, int) or isinstance(condition_len, bool) or condition_len <= 0:
|
||||
return None
|
||||
|
||||
request_id = request.request_id
|
||||
previous_condition_seq = self._streaming_condition_seqs.get(request_id)
|
||||
previous_condition_len = self._streaming_condition_lengths.get(request_id)
|
||||
if (previous_condition_seq is None) != (previous_condition_len is None):
|
||||
raise ValueError("streaming Talker condition tracking is incomplete")
|
||||
if previous_condition_seq is None and not self.receives_chunks:
|
||||
# A sender-only Talker is admitted with its first real condition,
|
||||
# before this adapter observes any StreamingUpdate. Seed that
|
||||
# condition as sequence zero from the active request so its first
|
||||
# continuation follows the same lifecycle as receiver stages.
|
||||
initial_info = getattr(request, "model_intermediate_buffer", None)
|
||||
initial_meta = initial_info.get("meta") if isinstance(initial_info, dict) else None
|
||||
initial_condition_len = (
|
||||
initial_meta.get("next_stage_prompt_len") if isinstance(initial_meta, dict) else None
|
||||
)
|
||||
initial_condition_seq = (
|
||||
initial_meta.get("streaming_condition_seq") if isinstance(initial_meta, dict) else None
|
||||
)
|
||||
if (
|
||||
isinstance(initial_info, dict)
|
||||
and initial_info.get("native_duplex") is True
|
||||
and isinstance(initial_condition_len, int)
|
||||
and not isinstance(initial_condition_len, bool)
|
||||
and initial_condition_len > 0
|
||||
and isinstance(initial_condition_seq, int)
|
||||
and not isinstance(initial_condition_seq, bool)
|
||||
and initial_condition_seq == 0
|
||||
):
|
||||
if initial_condition_len != request.num_prompt_tokens:
|
||||
raise ValueError(
|
||||
"initial streaming Talker condition length does not match its prompt: "
|
||||
f"condition={initial_condition_len}, prompt={request.num_prompt_tokens}"
|
||||
)
|
||||
previous_condition_seq = initial_condition_seq
|
||||
previous_condition_len = initial_condition_len
|
||||
supplied_condition_seq = meta.get("streaming_condition_seq")
|
||||
if supplied_condition_seq is None:
|
||||
if payload_data.get("native_duplex") is True and not self.receives_chunks:
|
||||
raise ValueError("native duplex Talker condition is missing streaming_condition_seq")
|
||||
condition_seq = previous_condition_seq + 1 if previous_condition_seq is not None else 0
|
||||
meta["streaming_condition_seq"] = condition_seq
|
||||
elif (
|
||||
not isinstance(supplied_condition_seq, int)
|
||||
or isinstance(supplied_condition_seq, bool)
|
||||
or supplied_condition_seq < 0
|
||||
):
|
||||
raise ValueError("streaming_condition_seq must be a non-negative integer")
|
||||
else:
|
||||
condition_seq = supplied_condition_seq
|
||||
expected_condition_seq = previous_condition_seq + 1 if previous_condition_seq is not None else 0
|
||||
if condition_seq != expected_condition_seq:
|
||||
raise ValueError(
|
||||
"native duplex Talker condition sequence is not contiguous: "
|
||||
f"expected={expected_condition_seq}, received={condition_seq}"
|
||||
)
|
||||
replaced = False
|
||||
if update_prompt:
|
||||
replaced = construct_next_stage_streaming_input_prompt(
|
||||
payload_data,
|
||||
request,
|
||||
max_model_len=self._max_model_len,
|
||||
previous_condition_len=previous_condition_len,
|
||||
previous_condition_seq=previous_condition_seq,
|
||||
condition_seq=condition_seq,
|
||||
recompute_previous_chunks=self._streaming_prompt_previous_chunks,
|
||||
recompute_on_capacity=self._streaming_prompt_recompute_on_capacity,
|
||||
)
|
||||
self._streaming_condition_lengths[request_id] = condition_len
|
||||
self._streaming_condition_seqs[request_id] = condition_seq
|
||||
return replaced
|
||||
|
||||
def _apply_pending_ar_prompt_updates(self, scheduler_requests: dict[str, Request] | None) -> None:
|
||||
"""Finalize ready AR prompt updates on the scheduler thread."""
|
||||
for request_id in tuple(self.requests_with_ready_chunks):
|
||||
@@ -981,31 +1090,31 @@ class OmniChunkTransferAdapter(OmniTransferAdapterBase):
|
||||
continue
|
||||
|
||||
request.additional_information = payload_data
|
||||
meta = payload_data.get("meta")
|
||||
meta = meta if isinstance(meta, dict) else {}
|
||||
previous_condition_seq = self._streaming_condition_seqs.get(request_id)
|
||||
condition_seq = previous_condition_seq + 1 if previous_condition_seq is not None else 0
|
||||
is_window_condition = window_condition_len is not None
|
||||
if is_window_condition:
|
||||
meta["streaming_condition_seq"] = condition_seq
|
||||
if is_window_condition:
|
||||
previous_condition_seq = self._streaming_condition_seqs.get(request_id)
|
||||
meta = payload_data.get("meta")
|
||||
assert isinstance(meta, dict)
|
||||
update_prompt = bool(
|
||||
was_resumable
|
||||
and (previous_condition_seq is not None or meta.get("replace_streaming_prompt") is True)
|
||||
)
|
||||
try:
|
||||
if update_prompt:
|
||||
replaced = self.update_streaming_prompt_for_condition(
|
||||
payload_data,
|
||||
request,
|
||||
update_prompt=update_prompt,
|
||||
)
|
||||
if replaced is None and update_prompt:
|
||||
# Non-window AR receivers still use the generic
|
||||
# prompt-extension contract from the base adapter.
|
||||
replaced = construct_next_stage_streaming_input_prompt(
|
||||
payload_data,
|
||||
request,
|
||||
max_model_len=self._max_model_len,
|
||||
previous_condition_len=self._streaming_condition_lengths.get(request_id),
|
||||
previous_condition_seq=previous_condition_seq,
|
||||
condition_seq=condition_seq,
|
||||
recompute_previous_chunks=self._streaming_prompt_previous_chunks,
|
||||
)
|
||||
if replaced:
|
||||
self.replaced_streaming_prompt_ids.add(request_id)
|
||||
if replaced:
|
||||
self.replaced_streaming_prompt_ids.add(request_id)
|
||||
except ValueError as exc:
|
||||
# The connector chunk was consumed, so retrying would skip
|
||||
# this transition and desynchronize Talker. Let the
|
||||
@@ -1013,10 +1122,6 @@ class OmniChunkTransferAdapter(OmniTransferAdapterBase):
|
||||
self.record_receive_failure(request_id, str(exc))
|
||||
continue
|
||||
|
||||
if window_condition_len is not None:
|
||||
self._streaming_condition_lengths[request_id] = window_condition_len
|
||||
self._streaming_condition_seqs[request_id] = condition_seq
|
||||
|
||||
def _requeue_replaced_prompts(self, waiting_queue: Any, running_queue: list[Request]) -> None:
|
||||
"""Move a replaced running prompt back through scheduler admission."""
|
||||
for request in list(running_queue):
|
||||
|
||||
@@ -319,10 +319,26 @@ class MiniCPMO45OmniTTSForConditionalGeneration(nn.Module, SupportsPP):
|
||||
|
||||
if not recompute:
|
||||
if condition_seq > previous_seq:
|
||||
raise ValueError(
|
||||
"a native duplex Talker condition advanced without its streaming recompute marker: "
|
||||
f"current={condition_seq}, previous={previous_seq}"
|
||||
)
|
||||
attention_type = getattr(self._tts_config, "attention_type", "full_attention")
|
||||
if attention_type == "sliding_recompute":
|
||||
raise ValueError(
|
||||
"a native duplex Talker condition advanced without its streaming recompute marker: "
|
||||
f"current={condition_seq}, previous={previous_seq}"
|
||||
)
|
||||
audio_state = self._request_audio_states.get(request_id)
|
||||
recent_codes = audio_state.get("recent_codes") if isinstance(audio_state, dict) else None
|
||||
if isinstance(recent_codes, list):
|
||||
base_recent_codes = tuple(int(code_id) for code_id in recent_codes[-_CODEC_PENALTY_WINDOW:])
|
||||
else:
|
||||
base_recent_codes = state.get("base_recent_codes")
|
||||
if not isinstance(base_recent_codes, tuple):
|
||||
raise ValueError("streaming Talker condition lost its frozen codec history")
|
||||
states[request_id] = {
|
||||
"condition_seq": condition_seq,
|
||||
"condition": current_condition.detach().clone(),
|
||||
"base_recent_codes": base_recent_codes,
|
||||
}
|
||||
return current_condition
|
||||
if "active_embeddings" in state:
|
||||
raise ValueError("an active streaming recompute was replayed without its recompute marker")
|
||||
return current_condition
|
||||
|
||||
@@ -637,6 +637,7 @@ def _native_duplex_segment_output_ids(
|
||||
state["request_id"] = request_id
|
||||
state["sent_output_len"] = 0
|
||||
state["sent_output_ids"] = []
|
||||
state["condition_seq"] = -1
|
||||
previous_turn_id = state.get("turn_id")
|
||||
sent_len = state.get("sent_output_len", 0)
|
||||
prev_output_ids = state.get("sent_output_ids", [])
|
||||
@@ -1000,6 +1001,8 @@ def llm2tts(
|
||||
if native_turn_end_handoff:
|
||||
model_intermediate_buffer.setdefault("meta", {})["turn_end"] = True
|
||||
|
||||
condition_sequence_state = None
|
||||
condition_sequence_value = None
|
||||
if handoff_ids is not None and handoff_hidden is not None:
|
||||
condition_suffix_length = 1 if is_native_duplex_handoff else 2
|
||||
condition_length = max(len(handoff_ids), len(handoff_hidden)) + condition_suffix_length
|
||||
@@ -1011,6 +1014,20 @@ def llm2tts(
|
||||
handoff_meta["next_stage_prompt_len"] = condition_length
|
||||
if is_native_duplex_handoff:
|
||||
handoff_meta["next_stage_generation_tokens"] = MINICPMO45_DUPLEX_CODEC_TOKENS_PER_CHUNK
|
||||
bridge_states = getattr(_streaming_context, "bridge_states", None)
|
||||
handoff_state = bridge_states.get("minicpmo45_tts_handoff") if isinstance(bridge_states, dict) else None
|
||||
if not isinstance(handoff_state, dict) or handoff_state.get("request_id") != str(llm_output.request_id):
|
||||
raise ValueError("native duplex Talker handoff is missing request-local streaming state")
|
||||
previous_condition_seq = handoff_state.get("condition_seq", -1)
|
||||
if (
|
||||
not isinstance(previous_condition_seq, int)
|
||||
or isinstance(previous_condition_seq, bool)
|
||||
or previous_condition_seq < -1
|
||||
):
|
||||
raise ValueError("native duplex Talker condition sequence state is invalid")
|
||||
condition_sequence_state = handoff_state
|
||||
condition_sequence_value = previous_condition_seq + 1
|
||||
handoff_meta["streaming_condition_seq"] = condition_sequence_value
|
||||
# Native duplex resumes one Talker request within a turn, but a new
|
||||
# assistant turn must discard the previous turn's prompt and KV.
|
||||
if not is_native_duplex_handoff or native_turn_start:
|
||||
@@ -1033,6 +1050,8 @@ def llm2tts(
|
||||
mm_processor_kwargs=None,
|
||||
)
|
||||
)
|
||||
if condition_sequence_state is not None:
|
||||
condition_sequence_state["condition_seq"] = condition_sequence_value
|
||||
if native_turn_end_handoff:
|
||||
bridge_states = getattr(_streaming_context, "bridge_states", None)
|
||||
duplex_state = bridge_states.get("duplex") if isinstance(bridge_states, dict) else None
|
||||
|
||||
Reference in new issue
Block a user