Benchmark data statistics for each stage of omni models (#3628)
Signed-off-by: ZacheryAU <70869627+ZacheryAU@users.noreply.github.com>
This commit is contained in:
1 parent
e10aca30ec
commit
bfc7cedcf1
28 files changed
+2297
-152
No files matched your search
@@ -123,6 +123,7 @@ class StageRuntimeInfo:
|
||||
final_output: bool
|
||||
final_output_type: FinalOutputModalityType | None
|
||||
stage_type: str
|
||||
model_stage: str | None = None
|
||||
|
||||
|
||||
# ============================================================================
|
||||
@@ -1247,6 +1248,7 @@ class AsyncOmniEngine:
|
||||
final_output=first_client.final_output,
|
||||
final_output_type=first_client.final_output_type,
|
||||
stage_type=first_client.stage_type,
|
||||
model_stage=getattr(first_client, "model_stage", None),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1616,6 +1618,7 @@ class AsyncOmniEngine:
|
||||
prompt_text: str | None = None,
|
||||
sampling_params_list: Sequence[Any] | None = None,
|
||||
final_stage_id: int = 0,
|
||||
final_output_stage_ids: Sequence[int] | None = None,
|
||||
arrival_time: float | None = None,
|
||||
lora_request: Any = None,
|
||||
tokenization_kwargs: dict[str, Any] | None = None,
|
||||
@@ -1628,6 +1631,7 @@ class AsyncOmniEngine:
|
||||
message_type: Literal["add_request", "streaming_update"] = "add_request",
|
||||
) -> StageSubmissionMessage:
|
||||
"""Build an add_request message after stage-0 preprocessing."""
|
||||
request_timestamp = float(arrival_time) if arrival_time is not None else time.time()
|
||||
effective_sampling_params_list: list[OmniSamplingParams] = (
|
||||
list(cast(Sequence[OmniSamplingParams], sampling_params_list))
|
||||
if sampling_params_list is not None
|
||||
@@ -1713,7 +1717,9 @@ class AsyncOmniEngine:
|
||||
output_prompt_text=output_prompt_text,
|
||||
sampling_params_list=effective_sampling_params_list,
|
||||
final_stage_id=final_stage_id,
|
||||
final_output_stage_ids=list(final_output_stage_ids) if final_output_stage_ids is not None else None,
|
||||
preprocess_ms=_preprocess_ms,
|
||||
request_timestamp=request_timestamp,
|
||||
enqueue_ts=time.perf_counter(),
|
||||
)
|
||||
|
||||
@@ -2186,6 +2192,7 @@ class AsyncOmniEngine:
|
||||
prompt_text: str | None = None,
|
||||
sampling_params_list: Sequence[Any] | None = None,
|
||||
final_stage_id: int = 0,
|
||||
final_output_stage_ids: Sequence[int] | None = None,
|
||||
arrival_time: float | None = None,
|
||||
lora_request: Any = None,
|
||||
tokenization_kwargs: dict[str, Any] | None = None,
|
||||
@@ -2209,6 +2216,7 @@ class AsyncOmniEngine:
|
||||
prompt_text=prompt_text,
|
||||
sampling_params_list=sampling_params_list,
|
||||
final_stage_id=final_stage_id,
|
||||
final_output_stage_ids=final_output_stage_ids,
|
||||
arrival_time=arrival_time,
|
||||
lora_request=lora_request,
|
||||
tokenization_kwargs=tokenization_kwargs,
|
||||
@@ -2236,6 +2244,7 @@ class AsyncOmniEngine:
|
||||
prompt_text: str | None = None,
|
||||
sampling_params_list: Sequence[Any] | None = None,
|
||||
final_stage_id: int = 0,
|
||||
final_output_stage_ids: Sequence[int] | None = None,
|
||||
arrival_time: float | None = None,
|
||||
lora_request: Any = None,
|
||||
tokenization_kwargs: dict[str, Any] | None = None,
|
||||
@@ -2253,6 +2262,7 @@ class AsyncOmniEngine:
|
||||
prompt_text=prompt_text,
|
||||
sampling_params_list=sampling_params_list,
|
||||
final_stage_id=final_stage_id,
|
||||
final_output_stage_ids=final_output_stage_ids,
|
||||
arrival_time=arrival_time,
|
||||
lora_request=lora_request,
|
||||
tokenization_kwargs=tokenization_kwargs,
|
||||
@@ -2270,6 +2280,7 @@ class AsyncOmniEngine:
|
||||
prompt_text: str | None = None,
|
||||
sampling_params_list: Sequence[Any] | None = None,
|
||||
final_stage_id: int = 0,
|
||||
final_output_stage_ids: Sequence[int] | None = None,
|
||||
arrival_time: float | None = None,
|
||||
*,
|
||||
resumable: bool = True,
|
||||
@@ -2281,6 +2292,7 @@ class AsyncOmniEngine:
|
||||
prompt_text=prompt_text,
|
||||
sampling_params_list=sampling_params_list,
|
||||
final_stage_id=final_stage_id,
|
||||
final_output_stage_ids=final_output_stage_ids,
|
||||
arrival_time=arrival_time,
|
||||
resumable=resumable,
|
||||
message_type="streaming_update",
|
||||
@@ -2294,6 +2306,7 @@ class AsyncOmniEngine:
|
||||
prompt_text: str | None = None,
|
||||
sampling_params_list: Sequence[Any] | None = None,
|
||||
final_stage_id: int = 0,
|
||||
final_output_stage_ids: Sequence[int] | None = None,
|
||||
arrival_time: float | None = None,
|
||||
*,
|
||||
resumable: bool = True,
|
||||
@@ -2305,6 +2318,7 @@ class AsyncOmniEngine:
|
||||
prompt_text=prompt_text,
|
||||
sampling_params_list=sampling_params_list,
|
||||
final_stage_id=final_stage_id,
|
||||
final_output_stage_ids=final_output_stage_ids,
|
||||
arrival_time=arrival_time,
|
||||
resumable=resumable,
|
||||
)
|
||||
|
||||
@@ -24,7 +24,9 @@ class StageSubmissionMessage(EngineQueueMessage, kw_only=True):
|
||||
sampling_params_list: list[OmniSamplingParams]
|
||||
final_stage_id: int
|
||||
preprocess_ms: float
|
||||
request_timestamp: float
|
||||
enqueue_ts: float
|
||||
final_output_stage_ids: list[int] | None = None
|
||||
|
||||
|
||||
class AddCompanionRequestMessage(EngineQueueMessage, kw_only=True):
|
||||
|
||||
@@ -126,6 +126,11 @@ class OrchestratorRequestState:
|
||||
prompt: Any = None
|
||||
sampling_params_list: list[Any] = field(default_factory=list)
|
||||
final_stage_id: int = -1
|
||||
final_output_stage_ids: set[int] = field(default_factory=set)
|
||||
finished_final_output_stage_ids: set[int] = field(default_factory=set)
|
||||
|
||||
# Wall-clock timestamp when the client-facing engine request was accepted.
|
||||
request_timestamp: float = 0.0
|
||||
|
||||
# Metrics: timestamp when request was submitted to each stage.
|
||||
stage_submit_ts: dict[int, float] = field(default_factory=dict)
|
||||
@@ -451,6 +456,7 @@ class Orchestrator:
|
||||
if not sampling_params_list:
|
||||
raise ValueError(f"Missing sampling params for stage 0. Got {len(sampling_params_list)} stage params.")
|
||||
final_stage_id = msg.final_stage_id
|
||||
final_output_stage_ids = set(msg.final_output_stage_ids or [final_stage_id])
|
||||
|
||||
logger.debug(
|
||||
"[Orchestrator] _handle_add_request: stage=%s req=%s "
|
||||
@@ -469,6 +475,8 @@ class Orchestrator:
|
||||
prompt=original_prompt,
|
||||
sampling_params_list=sampling_params_list,
|
||||
final_stage_id=final_stage_id,
|
||||
final_output_stage_ids=final_output_stage_ids,
|
||||
request_timestamp=float(msg.request_timestamp or _time.time()),
|
||||
mm_features=getattr(prompt, "mm_features", None),
|
||||
)
|
||||
self.request_states[request_id] = req_state
|
||||
@@ -512,7 +520,9 @@ class Orchestrator:
|
||||
output_prompt_text=msg.output_prompt_text,
|
||||
sampling_params_list=msg.sampling_params_list,
|
||||
final_stage_id=msg.final_stage_id,
|
||||
final_output_stage_ids=msg.final_output_stage_ids,
|
||||
preprocess_ms=msg.preprocess_ms,
|
||||
request_timestamp=msg.request_timestamp,
|
||||
enqueue_ts=msg.enqueue_ts,
|
||||
)
|
||||
await self._handle_add_request(fallback_msg)
|
||||
@@ -558,6 +568,8 @@ class Orchestrator:
|
||||
prompt=companion_prompt,
|
||||
sampling_params_list=sampling_params_list,
|
||||
final_stage_id=0,
|
||||
final_output_stage_ids={0},
|
||||
request_timestamp=parent_state.request_timestamp,
|
||||
)
|
||||
self.request_states[companion_id] = companion_state
|
||||
companion_state.stage_submit_ts[0] = _time.time()
|
||||
@@ -665,6 +677,7 @@ class Orchestrator:
|
||||
if output is None:
|
||||
continue
|
||||
|
||||
pool.record_output_timestamps([output])
|
||||
await self._handle_processed_outputs(stage_id, replica_id, [output])
|
||||
idle = False
|
||||
else:
|
||||
@@ -775,7 +788,9 @@ class Orchestrator:
|
||||
stage_metrics = pool.build_stage_metrics(
|
||||
[output],
|
||||
submit_ts=req_state.stage_submit_ts.get(stage_id, _time.time()),
|
||||
request_timestamp=req_state.request_timestamp,
|
||||
replica_id=replica_id,
|
||||
sampling_params=req_state.sampling_params_list[stage_id],
|
||||
)
|
||||
stage_metrics.pipeline_timings = dict(req_state.pipeline_timings)
|
||||
|
||||
@@ -852,6 +867,12 @@ class Orchestrator:
|
||||
await self._cleanup_request_ids([req_id])
|
||||
return
|
||||
|
||||
request_finished = False
|
||||
if finished and self.stage_pools[stage_id].final_output:
|
||||
req_state.finished_final_output_stage_ids.add(stage_id)
|
||||
final_output_stage_ids = req_state.final_output_stage_ids or {req_state.final_stage_id}
|
||||
request_finished = final_output_stage_ids.issubset(req_state.finished_final_output_stage_ids)
|
||||
|
||||
if self.stage_pools[stage_id].final_output:
|
||||
await self.output_async_queue.put(
|
||||
OutputMessage(
|
||||
@@ -860,7 +881,7 @@ class Orchestrator:
|
||||
replica_id=replica_id,
|
||||
engine_outputs=output,
|
||||
metrics=stage_metrics,
|
||||
finished=finished and stage_id == req_state.final_stage_id,
|
||||
finished=request_finished,
|
||||
stage_submit_ts=submit_ts,
|
||||
)
|
||||
)
|
||||
@@ -915,7 +936,7 @@ class Orchestrator:
|
||||
is_final_update=True,
|
||||
)
|
||||
|
||||
if finished and stage_id == req_state.final_stage_id:
|
||||
if request_finished:
|
||||
await self._cleanup_request_ids([req_id, *self._cfg_tracker.cleanup_parent(req_id)])
|
||||
|
||||
def _next_stage_already_submitted(self, stage_id: int, req_state: OrchestratorRequestState) -> bool:
|
||||
@@ -1341,7 +1362,12 @@ class Orchestrator:
|
||||
resumable=downstream_resumable,
|
||||
)
|
||||
request.external_req_id = request.request_id
|
||||
await next_pool.submit_initial(request_id, req_state, request, prompt_text=None)
|
||||
await next_pool.submit_initial(
|
||||
request_id,
|
||||
req_state,
|
||||
request,
|
||||
prompt_text=None,
|
||||
)
|
||||
|
||||
# async_chunk pre-submit fires per stage edge (N-1 -> N). Source
|
||||
# replica is stage 0's bound replica (single-replica thinker in
|
||||
|
||||
@@ -13,7 +13,7 @@ from vllm.v1.engine.output_processor import (
|
||||
RequestState,
|
||||
)
|
||||
from vllm.v1.engine.parallel_sampling import ParentRequest
|
||||
from vllm.v1.metrics.stats import IterationStats
|
||||
from vllm.v1.metrics.stats import IterationStats, RequestStateStats
|
||||
|
||||
from vllm_omni.data_entry_keys import unflatten_payload
|
||||
from vllm_omni.engine.output_modality import DRAINABLE_MODALITIES
|
||||
@@ -35,13 +35,21 @@ class OmniRequestState(RequestState):
|
||||
*args,
|
||||
**kwargs,
|
||||
):
|
||||
arrival_time = kwargs.get("arrival_time")
|
||||
if arrival_time is None and len(args) > 12:
|
||||
arrival_time = args[12]
|
||||
super().__init__(*args, **kwargs)
|
||||
self.native_text_stats = RequestStateStats(arrival_time=float(arrival_time or 0.0))
|
||||
# Omni-specific: multimodal output accumulation
|
||||
# NOTE: Keys in mm_accumulated matter, because they dictate which
|
||||
# outputs are drained (i.e., only drain modality keys, don't drain
|
||||
# hidden states).
|
||||
self.mm_accumulated: dict[str, Any] = {}
|
||||
|
||||
def apply_streaming_update(self, update) -> None:
|
||||
super().apply_streaming_update(update)
|
||||
self.native_text_stats.arrival_time = update.arrival_time
|
||||
|
||||
@staticmethod
|
||||
def _to_cpu(x):
|
||||
"""Try to convert to CPU tensor if needed."""
|
||||
@@ -318,6 +326,32 @@ class MultimodalOutputProcessor(VLLMOutputProcessor):
|
||||
tracing_enabled=tracing_enabled,
|
||||
)
|
||||
self.engine_core_output_type = engine_core_output_type
|
||||
self._native_text_metrics_by_request: dict[str, dict[str, Any]] = {}
|
||||
|
||||
def _native_text_metric_record(self, request_id: str) -> dict[str, Any]:
|
||||
return self._native_text_metrics_by_request.setdefault(
|
||||
request_id,
|
||||
{
|
||||
"vllm_ttft_ms": 0.0,
|
||||
"vllm_tpot_ms": 0.0,
|
||||
"vllm_itl_ms": 0.0,
|
||||
"vllm_itls_ms": [],
|
||||
},
|
||||
)
|
||||
|
||||
def pop_native_text_metrics(self, request_id: str) -> dict[str, Any]:
|
||||
return self._native_text_metrics_by_request.pop(request_id, {})
|
||||
|
||||
def abort_requests(self, request_ids, internal: bool) -> list[str]:
|
||||
request_ids = list(request_ids)
|
||||
for request_id in request_ids:
|
||||
if internal:
|
||||
req_state = self.request_states.get(request_id)
|
||||
if req_state is not None:
|
||||
self._native_text_metrics_by_request.pop(req_state.external_req_id, None)
|
||||
else:
|
||||
self._native_text_metrics_by_request.pop(request_id, None)
|
||||
return super().abort_requests(request_ids, internal)
|
||||
|
||||
def add_request(
|
||||
self,
|
||||
@@ -371,6 +405,7 @@ class MultimodalOutputProcessor(VLLMOutputProcessor):
|
||||
|
||||
external_req_id = getattr(req_state, "external_req_id", None)
|
||||
if external_req_id is not None:
|
||||
self._native_text_metrics_by_request.pop(external_req_id, None)
|
||||
request_ids = self.external_req_ids.get(external_req_id)
|
||||
if request_ids is not None:
|
||||
self.external_req_ids[external_req_id] = [rid for rid in request_ids if rid != request_id]
|
||||
@@ -402,3 +437,73 @@ class MultimodalOutputProcessor(VLLMOutputProcessor):
|
||||
engine_core_timestamp=engine_core_timestamp,
|
||||
iteration_stats=iteration_stats,
|
||||
)
|
||||
|
||||
def _update_stats_from_output(
|
||||
self,
|
||||
req_state: RequestState,
|
||||
engine_core_output: EngineCoreOutput,
|
||||
engine_core_timestamp: float | None,
|
||||
iteration_stats: IterationStats | None,
|
||||
):
|
||||
was_prefilling = req_state.is_prefilling
|
||||
native_stats = req_state.native_text_stats if isinstance(req_state, OmniRequestState) else None
|
||||
previous_last_token_ts = native_stats.last_token_ts if native_stats is not None else 0.0
|
||||
|
||||
super()._update_stats_from_output(
|
||||
req_state,
|
||||
engine_core_output,
|
||||
engine_core_timestamp,
|
||||
None,
|
||||
)
|
||||
|
||||
if iteration_stats is None or engine_core_timestamp is None or native_stats is None:
|
||||
return
|
||||
|
||||
iteration_stats.update_from_output(
|
||||
engine_core_output,
|
||||
engine_core_timestamp,
|
||||
was_prefilling,
|
||||
native_stats,
|
||||
self.lora_states,
|
||||
req_state.lora_name,
|
||||
)
|
||||
record = self._native_text_metric_record(req_state.external_req_id)
|
||||
if was_prefilling:
|
||||
record["vllm_ttft_ms"] = max(float(native_stats.first_token_latency) * 1000.0, 0.0)
|
||||
return
|
||||
|
||||
if previous_last_token_ts > 0:
|
||||
itl_ms = max((engine_core_timestamp - previous_last_token_ts) * 1000.0, 0.0)
|
||||
itls_ms = record.setdefault("vllm_itls_ms", [])
|
||||
itls_ms.append(itl_ms)
|
||||
record["vllm_itl_ms"] = sum(itls_ms) / float(len(itls_ms))
|
||||
|
||||
def _update_stats_from_finished(
|
||||
self,
|
||||
req_state: RequestState,
|
||||
finish_reason: FinishReason | None,
|
||||
iteration_stats: IterationStats | None,
|
||||
):
|
||||
super()._update_stats_from_finished(req_state, finish_reason, None)
|
||||
|
||||
native_stats = req_state.native_text_stats if isinstance(req_state, OmniRequestState) else None
|
||||
if iteration_stats is None or native_stats is None or finish_reason is None:
|
||||
return
|
||||
|
||||
iteration_stats.update_from_finished_request(
|
||||
finish_reason=finish_reason,
|
||||
request_id=req_state.external_req_id,
|
||||
num_prompt_tokens=req_state.prompt_len,
|
||||
max_tokens_param=req_state.max_tokens_param,
|
||||
req_stats=native_stats,
|
||||
num_cached_tokens=req_state.num_cached_tokens,
|
||||
)
|
||||
if not iteration_stats.finished_requests:
|
||||
return
|
||||
|
||||
finished_request = iteration_stats.finished_requests[-1]
|
||||
if finished_request.request_id != req_state.external_req_id:
|
||||
return
|
||||
self._native_text_metric_record(req_state.external_req_id)["vllm_tpot_ms"] = (
|
||||
float(finished_request.mean_time_per_output_token) * 1000.0
|
||||
)
|
||||
@@ -428,6 +428,8 @@ def extract_stage_metadata(stage_config: Any) -> StageMetadata:
|
||||
_mod, _fn = _ckf_path.rsplit(".", 1)
|
||||
cfg_kv_collect_func = getattr(importlib.import_module(_mod), _fn)
|
||||
|
||||
model_stage = getattr(engine_args, "model_stage", None)
|
||||
|
||||
if stage_type == "diffusion":
|
||||
return StageMetadata(
|
||||
stage_id=stage_id,
|
||||
@@ -440,12 +442,11 @@ def extract_stage_metadata(stage_config: Any) -> StageMetadata:
|
||||
final_output_type=final_output_type,
|
||||
default_sampling_params=default_sampling_params,
|
||||
custom_process_input_func=custom_process_input_func,
|
||||
model_stage=None,
|
||||
model_stage=model_stage,
|
||||
runtime_cfg=runtime_cfg,
|
||||
cfg_kv_collect_func=cfg_kv_collect_func,
|
||||
)
|
||||
|
||||
model_stage = getattr(engine_args, "model_stage", None)
|
||||
engine_output_type = getattr(engine_args, "engine_output_type", None)
|
||||
is_comprehension = getattr(stage_config, "is_comprehension", False)
|
||||
requires_multimodal_data = getattr(runtime_cfg, "requires_multimodal_data", False)
|
||||
|
||||
@@ -24,6 +24,7 @@ from vllm_omni.engine.stage_client import (
|
||||
StagePoolLLMClient,
|
||||
)
|
||||
from vllm_omni.inputs.data import OmniDiffusionSamplingParams
|
||||
from vllm_omni.metrics import definitions as defs
|
||||
from vllm_omni.metrics.stats import StageRequestStats as StageRequestMetrics
|
||||
from vllm_omni.metrics.stats import StageStats
|
||||
from vllm_omni.metrics.utils import count_tokens_from_outputs
|
||||
@@ -96,6 +97,10 @@ class StagePool:
|
||||
self._next_replica_id = 0
|
||||
self._request_bindings: dict[str, int] = {}
|
||||
self._replica_metrics: list[_ReplicaMetrics] = [_ReplicaMetrics() for _ in self.clients]
|
||||
self._output_timestamps_by_request: dict[str, list[float]] = {}
|
||||
self._non_empty_first_output_timestamps_by_request: dict[str, float] = {}
|
||||
self._audio_frames_by_request: dict[str, int] = {}
|
||||
self._audio_sample_rate_by_request: dict[str, int] = {}
|
||||
|
||||
# Distributed-mode state. Populated by add_client / remove_client.
|
||||
self._addr_to_replica_id: dict[str, int] = {}
|
||||
@@ -428,6 +433,10 @@ class StagePool:
|
||||
"""Drop the route binding for *request_id* in this stage."""
|
||||
self._request_bindings.pop(request_id, None)
|
||||
self._affinity.pop(request_id, None)
|
||||
self._output_timestamps_by_request.pop(str(request_id), None)
|
||||
self._non_empty_first_output_timestamps_by_request.pop(str(request_id), None)
|
||||
self._audio_frames_by_request.pop(str(request_id), None)
|
||||
self._audio_sample_rate_by_request.pop(str(request_id), None)
|
||||
|
||||
def release_bindings(self, request_ids: list[str]) -> None:
|
||||
"""Drop route bindings for the given request ids in this stage."""
|
||||
@@ -485,13 +494,66 @@ class StagePool:
|
||||
request_outputs: list[Any],
|
||||
*,
|
||||
submit_ts: float,
|
||||
request_timestamp: float,
|
||||
replica_id: int,
|
||||
sampling_params: Any | None = None,
|
||||
) -> StageRequestMetrics:
|
||||
"""Build stage metrics for outputs produced on one replica."""
|
||||
now = _time.time()
|
||||
stage_gen_time_ms = (now - submit_ts) * 1000.0
|
||||
|
||||
request_id = str(getattr(request_outputs[0], "request_id", "")) if request_outputs else ""
|
||||
output_timestamps = self._output_timestamps_by_request.pop(request_id, []) if request_id else []
|
||||
non_empty_first_output_ts = (
|
||||
self._non_empty_first_output_timestamps_by_request.pop(request_id, None) if request_id else None
|
||||
)
|
||||
num_tokens_out = count_tokens_from_outputs(request_outputs)
|
||||
output_unit_type = self._infer_output_unit_type(request_outputs, token_count=num_tokens_out)
|
||||
output_unit_count = self._count_output_units(
|
||||
request_outputs,
|
||||
unit_type=output_unit_type,
|
||||
fallback_token_count=num_tokens_out,
|
||||
)
|
||||
native_text_metrics = {}
|
||||
if request_id:
|
||||
pop_native_text_metrics = getattr(self.output_processor, "pop_native_text_metrics", None)
|
||||
if callable(pop_native_text_metrics):
|
||||
native_text_metrics = pop_native_text_metrics(request_id)
|
||||
current_audio_frames, current_audio_sample_rate, _ = self._collect_audio_metrics(request_outputs)
|
||||
accumulated_audio_frames = self._audio_frames_by_request.pop(request_id, 0) if request_id else 0
|
||||
accumulated_audio_sample_rate = self._audio_sample_rate_by_request.pop(request_id, 0) if request_id else 0
|
||||
audio_generated_frames = max(accumulated_audio_frames, current_audio_frames)
|
||||
audio_sample_rate = accumulated_audio_sample_rate or current_audio_sample_rate
|
||||
audio_duration_s = (
|
||||
float(audio_generated_frames) / float(audio_sample_rate)
|
||||
if audio_generated_frames > 0 and audio_sample_rate > 0
|
||||
else 0.0
|
||||
)
|
||||
image_pixels = self._count_image_pixels(request_outputs) if output_unit_type == "image" else 0
|
||||
num_inference_steps = self._coerce_int_scalar(getattr(sampling_params, "num_inference_steps", None))
|
||||
denoise_step_latency_ms = (
|
||||
defs.compute_denoise_step_latency(stage_gen_time_ms, num_inference_steps)
|
||||
if output_unit_type == "image"
|
||||
else 0.0
|
||||
)
|
||||
has_output_timestamps = bool(output_timestamps)
|
||||
first_ts = output_timestamps[0] if has_output_timestamps else now
|
||||
serving_time_to_first_output_ms = (
|
||||
max((non_empty_first_output_ts - request_timestamp) * 1000.0, 0.0)
|
||||
if non_empty_first_output_ts is not None
|
||||
else 0.0
|
||||
)
|
||||
remaining_ms = max((now - first_ts) * 1000.0, 0.0)
|
||||
if output_unit_count > 1 and self._is_streaming_output_unit_type(output_unit_type):
|
||||
time_per_output_unit_ms = remaining_ms / float(output_unit_count - 1)
|
||||
else:
|
||||
time_per_output_unit_ms = 0.0
|
||||
inter_output_latencies_ms = [
|
||||
max((cur_ts - prev_ts) * 1000.0, 0.0) for prev_ts, cur_ts in zip(output_timestamps, output_timestamps[1:])
|
||||
]
|
||||
inter_output_latency_ms = (
|
||||
sum(inter_output_latencies_ms) / float(len(inter_output_latencies_ms)) if inter_output_latencies_ms else 0.0
|
||||
)
|
||||
num_tokens_in = 0
|
||||
if self.stage_id == 0:
|
||||
for ro in request_outputs:
|
||||
@@ -504,6 +566,7 @@ class StagePool:
|
||||
batch_id = metrics.batch_seq
|
||||
metrics.agg_total_tokens += num_tokens_out
|
||||
metrics.agg_total_gen_time_ms += stage_gen_time_ms
|
||||
audio_rtf = defs.compute_audio_rtf(stage_gen_time_ms / 1000.0, audio_duration_s)
|
||||
|
||||
return StageRequestMetrics(
|
||||
num_tokens_in=num_tokens_in,
|
||||
@@ -519,8 +582,321 @@ class StagePool:
|
||||
total_token=metrics.agg_total_tokens,
|
||||
total_gen_time_ms=metrics.agg_total_gen_time_ms,
|
||||
),
|
||||
audio_generated_frames=audio_generated_frames,
|
||||
audio_sample_rate=audio_sample_rate,
|
||||
audio_duration_s=audio_duration_s,
|
||||
audio_rtf=audio_rtf,
|
||||
image_pixels=image_pixels,
|
||||
denoise_step_latency_ms=denoise_step_latency_ms,
|
||||
output_unit_type=output_unit_type,
|
||||
output_unit_count=output_unit_count,
|
||||
serving_time_to_first_output_ms=serving_time_to_first_output_ms,
|
||||
time_per_output_unit_ms=time_per_output_unit_ms,
|
||||
inter_output_latency_ms=inter_output_latency_ms,
|
||||
inter_output_latencies_ms=inter_output_latencies_ms,
|
||||
vllm_ttft_ms=float(native_text_metrics.get("vllm_ttft_ms") or 0.0),
|
||||
vllm_tpot_ms=float(native_text_metrics.get("vllm_tpot_ms") or 0.0),
|
||||
vllm_itl_ms=float(native_text_metrics.get("vllm_itl_ms") or 0.0),
|
||||
vllm_itls_ms=list(native_text_metrics.get("vllm_itls_ms") or []),
|
||||
)
|
||||
|
||||
def _infer_output_unit_type(self, request_outputs: list[Any], *, token_count: int) -> str:
|
||||
final_output_type = getattr(self.stage_client, "final_output_type", None)
|
||||
|
||||
if self._has_image_output(request_outputs) or final_output_type in {"image", "images"}:
|
||||
return "image"
|
||||
if self._has_video_output(request_outputs) or final_output_type in {"video", "videos"}:
|
||||
return "video"
|
||||
if self._has_audio_output(request_outputs) or final_output_type == "audio":
|
||||
return "audio"
|
||||
if self._has_trajectory_latent_output(request_outputs) or self._has_latent_output(request_outputs):
|
||||
return "latent"
|
||||
if final_output_type in {"latent", "latents"}:
|
||||
return "latent"
|
||||
if final_output_type == "text":
|
||||
return "text"
|
||||
if token_count > 0:
|
||||
return "stream"
|
||||
return "other"
|
||||
|
||||
@staticmethod
|
||||
def _is_streaming_output_unit_type(unit_type: str) -> bool:
|
||||
return unit_type in {"text", "stream"}
|
||||
|
||||
def _count_output_units(
|
||||
self,
|
||||
request_outputs: list[Any],
|
||||
*,
|
||||
unit_type: str,
|
||||
fallback_token_count: int,
|
||||
) -> int:
|
||||
if unit_type == "audio":
|
||||
total_frames, _, _ = self._collect_audio_metrics(request_outputs)
|
||||
if total_frames > 0:
|
||||
return total_frames
|
||||
if unit_type == "image":
|
||||
total_images = sum(self._count_images(ro) for ro in request_outputs)
|
||||
if total_images > 0:
|
||||
return total_images
|
||||
if unit_type == "video":
|
||||
total_videos = sum(self._count_videos(ro) for ro in request_outputs)
|
||||
if total_videos > 0:
|
||||
return total_videos
|
||||
if unit_type == "latent":
|
||||
total_latents = sum(
|
||||
self._count_value_units(getattr(ro, "trajectory_latents", None))
|
||||
+ self._count_value_units(getattr(ro, "latents", None))
|
||||
for ro in request_outputs
|
||||
)
|
||||
if total_latents > 0:
|
||||
return total_latents
|
||||
return int(fallback_token_count)
|
||||
|
||||
def _has_audio_output(self, request_outputs: list[Any]) -> bool:
|
||||
for ro in request_outputs:
|
||||
for mm_output in self._iter_multimodal_outputs(ro):
|
||||
if isinstance(mm_output, dict) and mm_output.get("audio") is not None:
|
||||
return True
|
||||
return False
|
||||
|
||||
def _collect_audio_metrics(self, request_outputs: list[Any]) -> tuple[int, int, float]:
|
||||
total_frames = 0
|
||||
sample_rate = 0
|
||||
for ro in request_outputs:
|
||||
for mm_output in self._iter_multimodal_outputs(ro):
|
||||
if not isinstance(mm_output, dict):
|
||||
continue
|
||||
if sample_rate <= 0:
|
||||
sample_rate = self._infer_audio_sample_rate(mm_output)
|
||||
audio_output = mm_output.get("audio")
|
||||
if audio_output is None:
|
||||
continue
|
||||
items = audio_output if isinstance(audio_output, list) else [audio_output]
|
||||
for item in items:
|
||||
total_frames += self._count_audio_frames(item)
|
||||
duration_s = (float(total_frames) / float(sample_rate)) if total_frames > 0 and sample_rate > 0 else 0.0
|
||||
return int(total_frames), int(sample_rate), duration_s
|
||||
|
||||
@staticmethod
|
||||
def _count_audio_frames(audio_output: Any) -> int:
|
||||
shape = getattr(audio_output, "shape", None)
|
||||
if shape is not None and len(shape) > 0:
|
||||
# Audio chunks are concatenated on dim=-1 in the output processor,
|
||||
# so the frame/sample axis is the last dim (e.g. [channels, frames]).
|
||||
# Keep this aligned with serving_chat.py: audio tensors are consumed
|
||||
# as (T,), (C, T), or (B, C, T). Flattening would corrupt
|
||||
# multi-channel audio.
|
||||
return int(shape[-1])
|
||||
try:
|
||||
return len(audio_output)
|
||||
except TypeError:
|
||||
return 1
|
||||
|
||||
def _infer_audio_sample_rate(self, mm_output: dict[str, Any]) -> int:
|
||||
for key in ("audio_sample_rate", "sample_rate", "sampling_rate", "sr"):
|
||||
rate = self._coerce_int_scalar(mm_output.get(key))
|
||||
if rate > 0:
|
||||
return rate
|
||||
for attr in ("audio_sample_rate", "sample_rate", "sampling_rate", "output_sample_rate"):
|
||||
rate = self._coerce_int_scalar(getattr(self.stage_client, attr, None))
|
||||
if rate > 0:
|
||||
return rate
|
||||
rate = self._coerce_int_scalar(getattr(self._stage_vllm_config, attr, None))
|
||||
if rate > 0:
|
||||
return rate
|
||||
return 0
|
||||
|
||||
@classmethod
|
||||
def _coerce_int_scalar(cls, value: Any) -> int:
|
||||
if value is None:
|
||||
return 0
|
||||
if isinstance(value, (list, tuple)):
|
||||
for item in value:
|
||||
coerced = cls._coerce_int_scalar(item)
|
||||
if coerced > 0:
|
||||
return coerced
|
||||
return 0
|
||||
item = getattr(value, "item", None)
|
||||
if callable(item):
|
||||
try:
|
||||
return int(item())
|
||||
except Exception:
|
||||
return 0
|
||||
try:
|
||||
return int(value)
|
||||
except (TypeError, ValueError):
|
||||
return 0
|
||||
|
||||
def _has_image_output(self, request_outputs: list[Any]) -> bool:
|
||||
for ro in request_outputs:
|
||||
if self._count_images(ro) > 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
def _has_video_output(self, request_outputs: list[Any]) -> bool:
|
||||
for ro in request_outputs:
|
||||
if self._count_videos(ro) > 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
def _has_trajectory_latent_output(self, request_outputs: list[Any]) -> bool:
|
||||
return any(self._is_non_empty_value(getattr(ro, "trajectory_latents", None)) for ro in request_outputs)
|
||||
|
||||
def _has_latent_output(self, request_outputs: list[Any]) -> bool:
|
||||
return any(self._is_non_empty_value(getattr(ro, "latents", None)) for ro in request_outputs)
|
||||
|
||||
def _count_images(self, request_output: Any) -> int:
|
||||
total_images = self._count_value_units(getattr(request_output, "images", None))
|
||||
for mm_output in self._iter_multimodal_outputs(request_output):
|
||||
if isinstance(mm_output, dict):
|
||||
total_images += self._count_value_units(mm_output.get("image"))
|
||||
total_images += self._count_value_units(mm_output.get("images"))
|
||||
return total_images
|
||||
|
||||
def _count_image_pixels(self, request_outputs: list[Any]) -> int:
|
||||
total_pixels = 0
|
||||
for ro in request_outputs:
|
||||
total_pixels += self._count_image_value_pixels(getattr(ro, "images", None))
|
||||
for mm_output in self._iter_multimodal_outputs(ro):
|
||||
if isinstance(mm_output, dict):
|
||||
total_pixels += self._count_image_value_pixels(mm_output.get("image"))
|
||||
total_pixels += self._count_image_value_pixels(mm_output.get("images"))
|
||||
return total_pixels
|
||||
|
||||
@classmethod
|
||||
def _count_image_value_pixels(cls, value: Any) -> int:
|
||||
if value is None:
|
||||
return 0
|
||||
if isinstance(value, (list, tuple)):
|
||||
return sum(cls._count_image_value_pixels(item) for item in value)
|
||||
|
||||
size = getattr(value, "size", None)
|
||||
if isinstance(size, tuple) and len(size) >= 2:
|
||||
try:
|
||||
return int(size[0]) * int(size[1])
|
||||
except (TypeError, ValueError):
|
||||
return 0
|
||||
|
||||
shape = getattr(value, "shape", None)
|
||||
if shape is None or len(shape) < 2:
|
||||
return 0
|
||||
dims = [int(dim) for dim in shape]
|
||||
if len(dims) >= 4:
|
||||
return dims[0] * dims[-2] * dims[-1]
|
||||
if len(dims) == 3 and dims[0] in (1, 3, 4):
|
||||
return dims[1] * dims[2]
|
||||
if len(dims) == 3 and dims[-1] in (1, 3, 4):
|
||||
return dims[0] * dims[1]
|
||||
return dims[-2] * dims[-1]
|
||||
|
||||
def _count_videos(self, request_output: Any) -> int:
|
||||
total_videos = self._count_video_units(getattr(request_output, "video", None))
|
||||
total_videos += self._count_video_units(getattr(request_output, "videos", None))
|
||||
for mm_output in self._iter_multimodal_outputs(request_output):
|
||||
if isinstance(mm_output, dict):
|
||||
total_videos += self._count_video_units(mm_output.get("video"))
|
||||
total_videos += self._count_video_units(mm_output.get("videos"))
|
||||
return total_videos
|
||||
|
||||
def has_non_empty_output(self, request_output: Any) -> bool:
|
||||
return self._has_non_empty_output(request_output)
|
||||
|
||||
def _has_non_empty_output(self, request_output: Any) -> bool:
|
||||
final_output_type = getattr(request_output, "final_output_type", None)
|
||||
if final_output_type is None:
|
||||
final_output_type = getattr(self.stage_client, "final_output_type", None)
|
||||
if final_output_type == "text":
|
||||
return any(bool(getattr(output, "text", "")) for output in getattr(request_output, "outputs", None) or [])
|
||||
|
||||
if getattr(request_output, "images", None):
|
||||
return True
|
||||
if getattr(request_output, "video", None) or getattr(request_output, "videos", None):
|
||||
return True
|
||||
if getattr(request_output, "trajectory_latents", None) is not None:
|
||||
return True
|
||||
custom_output = getattr(request_output, "_custom_output", None)
|
||||
if isinstance(custom_output, dict) and custom_output:
|
||||
return True
|
||||
for mm_output in self._iter_multimodal_outputs(request_output):
|
||||
if isinstance(mm_output, dict) and any(self._is_non_empty_value(value) for value in mm_output.values()):
|
||||
return True
|
||||
for output in getattr(request_output, "outputs", None) or []:
|
||||
if getattr(output, "text", None):
|
||||
return True
|
||||
token_ids = getattr(output, "token_ids", None)
|
||||
if self._is_non_empty_value(token_ids):
|
||||
return True
|
||||
cumulative_token_ids = getattr(output, "cumulative_token_ids", None)
|
||||
if self._is_non_empty_value(cumulative_token_ids):
|
||||
return True
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def _is_non_empty_value(value: Any) -> bool:
|
||||
if value is None:
|
||||
return False
|
||||
shape = getattr(value, "shape", None)
|
||||
if shape is not None:
|
||||
return all(int(dim) > 0 for dim in shape)
|
||||
try:
|
||||
return len(value) > 0
|
||||
except TypeError:
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def _count_value_units(value: Any) -> int:
|
||||
if value is None:
|
||||
return 0
|
||||
shape = getattr(value, "shape", None)
|
||||
if shape is not None:
|
||||
return int(shape[0]) if len(shape) > 0 and int(shape[0]) > 0 else 0
|
||||
try:
|
||||
return len(value)
|
||||
except TypeError:
|
||||
return 1
|
||||
|
||||
@staticmethod
|
||||
def _count_video_units(value: Any) -> int:
|
||||
if value is None:
|
||||
return 0
|
||||
if isinstance(value, (list, tuple)):
|
||||
return len(value)
|
||||
shape = getattr(value, "shape", None)
|
||||
if shape is not None:
|
||||
return 1 if all(int(dim) > 0 for dim in shape) else 0
|
||||
try:
|
||||
return len(value)
|
||||
except TypeError:
|
||||
return 1
|
||||
|
||||
def record_output_timestamps(self, request_outputs: list[Any], *, output_ts: float | None = None) -> None:
|
||||
"""Record all output timestamps and the first non-empty output timestamp."""
|
||||
output_ts = _time.time() if output_ts is None else output_ts
|
||||
for request_output in request_outputs:
|
||||
request_id = getattr(request_output, "request_id", None)
|
||||
if request_id is None:
|
||||
continue
|
||||
rid = str(request_id)
|
||||
self._output_timestamps_by_request.setdefault(rid, []).append(output_ts)
|
||||
if self._has_non_empty_output(request_output):
|
||||
self._non_empty_first_output_timestamps_by_request.setdefault(rid, output_ts)
|
||||
audio_frames, audio_sample_rate, _ = self._collect_audio_metrics([request_output])
|
||||
if audio_frames > 0:
|
||||
self._audio_frames_by_request[rid] = self._audio_frames_by_request.get(rid, 0) + audio_frames
|
||||
if self._audio_sample_rate_by_request.get(rid, 0) <= 0 and audio_sample_rate > 0:
|
||||
self._audio_sample_rate_by_request[rid] = audio_sample_rate
|
||||
|
||||
def _iter_multimodal_outputs(self, request_output: Any) -> list[dict[str, Any]]:
|
||||
multimodal_outputs: list[dict[str, Any]] = []
|
||||
outer_mm = getattr(request_output, "multimodal_output", None)
|
||||
if isinstance(outer_mm, dict) and outer_mm:
|
||||
multimodal_outputs.append(outer_mm)
|
||||
for output in getattr(request_output, "outputs", None) or []:
|
||||
inner_mm = getattr(output, "multimodal_output", None)
|
||||
if isinstance(inner_mm, dict) and inner_mm:
|
||||
multimodal_outputs.append(inner_mm)
|
||||
return multimodal_outputs
|
||||
|
||||
# ---- Stage-local admission ----
|
||||
|
||||
async def submit_initial(
|
||||
@@ -658,11 +1034,16 @@ class StagePool:
|
||||
return []
|
||||
client = cast(StagePoolLLMClient, raw_client)
|
||||
processor = self.output_processor
|
||||
iteration_stats = IterationStats()
|
||||
processed = processor.process_outputs(
|
||||
raw_outputs.outputs,
|
||||
raw_outputs.timestamp,
|
||||
iteration_stats,
|
||||
)
|
||||
# Use the same wall-clock source as OrchestratorRequestState.stage_submit_ts.
|
||||
# EngineCoreOutputs.timestamp may use a different clock base, which would
|
||||
# make TTFO negative and get clamped to 0.
|
||||
self.record_output_timestamps(processed.request_outputs, output_ts=_time.time())
|
||||
|
||||
if processed.reqs_to_abort:
|
||||
await client.abort_requests_async(processed.reqs_to_abort)
|
||||
|
||||
Reference in new issue
Block a user