[Bugfix][MiniCPM-o] Fix async-chunk snapshot replacement and prompt cleanup (#6406)
Signed-off-by: natureofnature <wzliu@connect.hku.hk> Co-authored-by: amy-why-3459 <wuhaiyan17@huawei.com>
This commit is contained in:
1 parent
ea0a24465b
commit
4f7c08c0eb
14 files changed
+458
-19
No files matched your search
@@ -216,13 +216,14 @@ def compute_talker_prompt_ids_length(prompt_ids: list[int]) -> int:
|
||||
return sum_user_len + assistant_len
|
||||
|
||||
|
||||
def construct_next_stage_streaming_input_prompt(payload_data: dict[str, Any], request: Any) -> None:
|
||||
def construct_next_stage_streaming_input_prompt(payload_data: dict[str, Any], request: Any) -> bool:
|
||||
"""Update a downstream streaming request prompt from connector payload ids.
|
||||
|
||||
Async-chunk downstream stages are prewarmed before the real Talker prompt is
|
||||
known. When a Thinker payload carries ``ids.prompt``, this helper:
|
||||
|
||||
* Preserves ``num_computed_tokens`` (the scheduler token watermark).
|
||||
* Preserves ``num_computed_tokens`` while extending the current prompt.
|
||||
Explicit replacements reset it with the prompt.
|
||||
* Moves already-computed output tokens into ``prompt_token_ids``.
|
||||
* Appends a new placeholder prompt slice sized from the upstream ids.
|
||||
* Refreshes block hashes so the scheduler allocates KV slots for the
|
||||
@@ -230,8 +231,8 @@ def construct_next_stage_streaming_input_prompt(payload_data: dict[str, Any], re
|
||||
"""
|
||||
ids = payload_data.get("ids", {})
|
||||
meta = payload_data.get("meta", {})
|
||||
replace_prompt = isinstance(meta, dict) and meta.get("replace_streaming_prompt") is True
|
||||
next_stage_prompt_len = meta.get("next_stage_prompt_len") if isinstance(meta, dict) else None
|
||||
replace_prompt = isinstance(meta, dict) and meta.get("replace_streaming_prompt") is True
|
||||
if replace_prompt and isinstance(next_stage_prompt_len, int) and next_stage_prompt_len > 0:
|
||||
# Some downstream stages consume complete, independently conditioned
|
||||
# segments instead of extending an existing KV prefix. The producer
|
||||
@@ -244,10 +245,10 @@ def construct_next_stage_streaming_input_prompt(payload_data: dict[str, Any], re
|
||||
request.num_computed_tokens = 0
|
||||
request.num_prompt_tokens = next_stage_prompt_len
|
||||
request.update_block_hashes()
|
||||
return
|
||||
return True
|
||||
prompt_token_ids = ids.get("prompt", None)
|
||||
if not prompt_token_ids:
|
||||
return
|
||||
return False
|
||||
num_computed_tokens = request.num_computed_tokens
|
||||
kept_output_tokens = request._all_token_ids[request.num_prompt_tokens : num_computed_tokens]
|
||||
del request._all_token_ids[num_computed_tokens:]
|
||||
@@ -264,3 +265,4 @@ def construct_next_stage_streaming_input_prompt(payload_data: dict[str, Any], re
|
||||
request.prompt_token_ids.extend(new_prompt or ())
|
||||
request.update_block_hashes()
|
||||
request.num_prompt_tokens = len(request.prompt_token_ids)
|
||||
return False
|
||||
@@ -84,6 +84,7 @@ class OmniChunkTransferAdapter(OmniTransferAdapterBase):
|
||||
self.waiting_for_chunk_waiting_requests: deque[Any] = deque()
|
||||
self.waiting_for_chunk_running_requests: deque[Any] = deque()
|
||||
self.requests_with_ready_chunks = set()
|
||||
self.replaced_streaming_prompt_ids: set[str] = set()
|
||||
self.requests_origin_status = {}
|
||||
self._active_streams: dict[str, Any] = {}
|
||||
# Private hold-queue for non-active running requests. Restored to
|
||||
@@ -246,7 +247,9 @@ class OmniChunkTransferAdapter(OmniTransferAdapterBase):
|
||||
replace_prompt = meta.get("replace_streaming_prompt") is True
|
||||
if getattr(request, "resumable", False) and (chunk_id > 0 or replace_prompt):
|
||||
# For new streaming input segment, we should update prompt from payload
|
||||
construct_next_stage_streaming_input_prompt(payload_data, request)
|
||||
replaced = construct_next_stage_streaming_input_prompt(payload_data, request)
|
||||
if replaced:
|
||||
self.replaced_streaming_prompt_ids.add(req_id)
|
||||
|
||||
if payload_finished:
|
||||
self.upstream_exhausted_requests.add(req_id)
|
||||
@@ -275,15 +278,26 @@ class OmniChunkTransferAdapter(OmniTransferAdapterBase):
|
||||
else:
|
||||
prompt_token_ids = new_ids
|
||||
request.prompt_token_ids = prompt_token_ids
|
||||
# Full-snapshot producers opt in explicitly; generation and
|
||||
# diffusion models keep their existing incremental merge.
|
||||
prev_info = getattr(request, "additional_information", None)
|
||||
info = dict(prev_info) if isinstance(prev_info, dict) else {}
|
||||
replace_snapshot = meta.get("replace_runtime_additional_information") is True
|
||||
info = {} if replace_snapshot else (dict(prev_info) if isinstance(prev_info, dict) else {})
|
||||
for key, value in payload_data.items():
|
||||
if key == "codes":
|
||||
if use_tensor_codes and isinstance(value, dict):
|
||||
if isinstance(value, dict):
|
||||
existing_sub = info.get(key)
|
||||
merged_sub = dict(existing_sub) if isinstance(existing_sub, dict) else {}
|
||||
merged_sub.update(value)
|
||||
info[key] = merged_sub
|
||||
for subkey, subvalue in value.items():
|
||||
# A 1-D audio tensor is represented by the
|
||||
# placeholder prompt above, but sibling fields
|
||||
# such as the reference voice still belong in
|
||||
# the current runtime snapshot.
|
||||
if subkey == "audio" and not use_tensor_codes:
|
||||
continue
|
||||
merged_sub[subkey] = subvalue
|
||||
if merged_sub:
|
||||
info[key] = merged_sub
|
||||
continue
|
||||
if isinstance(value, dict):
|
||||
existing_sub = info.get(key)
|
||||
@@ -455,6 +469,7 @@ class OmniChunkTransferAdapter(OmniTransferAdapterBase):
|
||||
self.segment_finished_requests.discard(request_id)
|
||||
self.get_req_chunk.pop(request_id, None)
|
||||
self.requests_with_ready_chunks.discard(request_id)
|
||||
self.replaced_streaming_prompt_ids.discard(request_id)
|
||||
self.request_ids_mapping.pop(request_id, None)
|
||||
self.requests_origin_status.pop(request_id, None)
|
||||
self._discard_from_chunk_deque(self.waiting_for_chunk_waiting_requests, request_id)
|
||||
@@ -564,6 +579,7 @@ class OmniChunkTransferAdapter(OmniTransferAdapterBase):
|
||||
RequestStatus.RUNNING,
|
||||
self._finished_load_reqs,
|
||||
)
|
||||
self._requeue_replaced_prompts(waiting_queue, running_queue)
|
||||
while len(running_queue) > self.scheduler_max_num_seqs:
|
||||
request = running_queue.pop()
|
||||
request.status = RequestStatus.PREEMPTED
|
||||
@@ -578,9 +594,24 @@ class OmniChunkTransferAdapter(OmniTransferAdapterBase):
|
||||
self._process_chunk_queue(
|
||||
running_queue, self.waiting_for_chunk_running_requests, RequestStatus.RUNNING, self._finished_load_reqs
|
||||
)
|
||||
self._requeue_replaced_prompts(waiting_queue, running_queue)
|
||||
self._promote_active_streams(waiting_queue)
|
||||
self._preempt_non_active_running(waiting_queue, running_queue)
|
||||
|
||||
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):
|
||||
request_id = request.request_id
|
||||
if (
|
||||
request_id not in self.replaced_streaming_prompt_ids
|
||||
or request_id not in self.requests_with_ready_chunks
|
||||
):
|
||||
continue
|
||||
running_queue.remove(request)
|
||||
request.status = RequestStatus.WAITING
|
||||
self.requests_origin_status[request_id] = RequestStatus.WAITING
|
||||
waiting_queue.add_request(request)
|
||||
|
||||
def _promote_active_streams(self, queue: Any) -> None:
|
||||
if len(self._active_streams) >= self._active_window:
|
||||
return
|
||||
@@ -852,6 +883,11 @@ class OmniChunkTransferAdapter(OmniTransferAdapterBase):
|
||||
for req_data in scheduler_output.scheduled_new_reqs:
|
||||
if req_data.req_id in self.requests_with_ready_chunks:
|
||||
self.requests_with_ready_chunks.remove(req_data.req_id)
|
||||
if req_data.req_id in self.replaced_streaming_prompt_ids:
|
||||
external_req_id = self.request_ids_mapping.get(req_data.req_id)
|
||||
if external_req_id is not None:
|
||||
self.requests_num_chunks_sent.pop(external_req_id, None)
|
||||
self.replaced_streaming_prompt_ids.remove(req_data.req_id)
|
||||
|
||||
if scheduler_output.scheduled_cached_reqs:
|
||||
for req_id in scheduler_output.scheduled_cached_reqs.req_ids:
|
||||
|
||||
Reference in new issue
Block a user