[perf] Minicpm o4.5 optimization (#5228)

Signed-off-by: R2-Y <ruiruyang2@gmail.com>
Co-authored-by: Sy03 <1370724210@qq.com>
This commit is contained in:
rein yangandSy03 authored and GitHub committed 2026-07-24 17:20:39 +08:00
1 parent acf941da4d
commit ad3a162eb8
54 files changed
+3861 -3997

No files matched your search

@@ -229,6 +229,22 @@ def construct_next_stage_streaming_input_prompt(payload_data: dict[str, Any], re
extended prompt without discarding prior computed state.
"""
ids = payload_data.get("ids", {})
meta = payload_data.get("meta", {})
replace_prompt = isinstance(meta, dict) and meta.get("replace_streaming_prompt") is True
condition_len = meta.get("next_stage_prompt_len") if replace_prompt else None
if isinstance(condition_len, int) and condition_len > 0:
# Some downstream stages consume complete, independently conditioned
# segments instead of extending an existing KV prefix. The producer
# declares that transport behavior explicitly in payload metadata.
new_prompt = [0] * condition_len
request._output_token_ids.clear()
request._all_token_ids.clear()
request._all_token_ids.extend(new_prompt)
request.prompt_token_ids = new_prompt
request.num_computed_tokens = 0
request.num_prompt_tokens = condition_len
request.update_block_hashes()
return
prompt_token_ids = ids.get("prompt", None)
if not prompt_token_ids:
return
@@ -13,7 +13,7 @@ from vllm_omni.data_entry_keys import MetaStruct, OmniPayloadStruct, unflatten_p
from ..adapter import construct_next_stage_streaming_input_prompt
from ..factory import OmniConnectorFactory
from ..utils.config import ConnectorSpec
from ..utils.config import ConnectorSpec, stage_receives_chunks
from ..utils.logging import get_connector_logger
from .base import OmniTransferAdapterBase
@@ -56,6 +56,7 @@ class OmniChunkTransferAdapter(OmniTransferAdapterBase):
self._active_window,
)
self.connector = self.create_connector(model_config)
self.receives_chunks = stage_receives_chunks(model_config)
super().__init__(model_config)
self.model_mode = getattr(model_config, "worker_type", None) or "ar"
# State specific to Chunk management
@@ -135,7 +136,7 @@ class OmniChunkTransferAdapter(OmniTransferAdapterBase):
"""
stage_id = self.connector.stage_id
if stage_id == 0:
if stage_id == 0 or not self.receives_chunks:
return
if not hasattr(request, "additional_information"):
request.additional_information = None
@@ -224,7 +225,8 @@ class OmniChunkTransferAdapter(OmniTransferAdapterBase):
payload_segment_finished = self._is_truthy_scalar(meta.get("is_segment_finished"))
if self.model_mode == "ar":
request.additional_information = payload_data
if chunk_id > 0 and request.resumable:
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)
@@ -464,6 +466,8 @@ class OmniChunkTransferAdapter(OmniTransferAdapterBase):
callers that don't track aborts may omit it to keep the prior
(unguarded) behaviour.
"""
if not self.receives_chunks:
return
if self.connector.stage_id == 0:
return
@@ -628,6 +632,8 @@ class OmniChunkTransferAdapter(OmniTransferAdapterBase):
every parked request is restored unconditionally (the
pre-purge behavior).
"""
if not self.receives_chunks:
return
if scheduler_requests is not None:
self._purge_untracked_chunk_requests(self.waiting_for_chunk_waiting_requests, scheduler_requests)
self._purge_untracked_chunk_requests(self.waiting_for_chunk_running_requests, scheduler_requests)
@@ -659,6 +665,8 @@ class OmniChunkTransferAdapter(OmniTransferAdapterBase):
Add additional info for cached requests and
clean up ready chunks from scheduler output.
"""
if not self.receives_chunks:
return
stage_id = self.connector.stage_id
if stage_id == 0:
@@ -17,6 +17,34 @@ TRANSFER_ENGINE_CONNECTOR_NAMES = frozenset(
)
def get_stage_connector_role(model_config: Any) -> str | None:
"""Return the configured stage connector direction, if explicit."""
connector_config = getattr(model_config, "stage_connector_config", None)
if isinstance(connector_config, dict):
extra = connector_config.get("extra")
else:
extra = getattr(connector_config, "extra", None)
if isinstance(extra, dict):
role = extra.get("role")
return role if isinstance(role, str) else None
return None
def stage_receives_chunks(model_config: Any) -> bool:
"""Whether connector chunks, rather than the orchestrator, feed a stage."""
return get_stage_connector_role(model_config) != "sender"
def stage_sends_async_output(model_config: Any) -> bool:
"""Whether async output should be partitioned for connector transport."""
role = get_stage_connector_role(model_config)
if role is not None:
return role == "sender"
# Preserve legacy partitioning while keeping stage-0 orchestrator bridges
# on the normal RequestOutput path.
return getattr(model_config, "stage_id", None) != 0
@dataclass
class ConnectorSpec:
"""Specification for a connector instance."""