[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)},
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user