[Metrics] Add audio SLOs + cross-stage transfer families + per-(stage, replica) wrap for upstream vllm:* (#3576)
Signed-off-by: vraiti <vraiti@redhat.com> Signed-off-by: LHXuuu <xulianhao.xlh@antgroup.com> Co-authored-by: vraiti <vraiti@redhat.com>
This commit is contained in:
1 parent
ee33601571
commit
41a795b5d6
29 files changed
+3377
-25
No files matched your search
@@ -160,6 +160,20 @@ class AsyncOmni(EngineClient, OmniBase):
|
||||
renderer = renderer_from_config(vllm_config)
|
||||
self.io_processor = get_io_processor(vllm_config, renderer, io_processor_plugin)
|
||||
|
||||
def _resolve_transfer_replica(self, stage_id: int, request_id: str) -> int | None:
|
||||
"""Look up the sticky-routed replica for (stage_id, request_id).
|
||||
|
||||
Used as the ``replica_resolver`` callback by ``OrchestratorAggregator``
|
||||
to label transfer_* metrics without plumbing replica ids through
|
||||
``TransferEdgeStats`` / ``StageRequestStats`` / connector adapters.
|
||||
Returns None when stage_id is out of range or the request hasn't been
|
||||
bound to a replica yet — the metric emit then defensive-skips.
|
||||
"""
|
||||
pools = getattr(self.engine, "stage_pools", None)
|
||||
if pools is None or not (0 <= stage_id < len(pools)):
|
||||
return None
|
||||
return pools[stage_id].get_bound_replica_id(request_id)
|
||||
|
||||
def _get_comprehension_stage_index(self) -> int | None:
|
||||
fallback_idx: int | None = None
|
||||
for idx, stage_client in enumerate(self.engine.stage_clients):
|
||||
@@ -331,6 +345,8 @@ class AsyncOmni(EngineClient, OmniBase):
|
||||
self.log_stats,
|
||||
wall_start_ts,
|
||||
final_stage_id_for_e2e,
|
||||
transfer_emitter=getattr(self, "transfer_metrics", None),
|
||||
replica_resolver=self._resolve_transfer_replica,
|
||||
)
|
||||
|
||||
req_state = ClientRequestState(
|
||||
@@ -338,6 +354,7 @@ class AsyncOmni(EngineClient, OmniBase):
|
||||
external_request_id=external_request_id,
|
||||
)
|
||||
req_state.metrics = metrics
|
||||
req_state.request_arrival_ts = wall_start_ts
|
||||
self.request_states[request_id] = req_state
|
||||
|
||||
# PD disaggregation: modify prefill-stage sampling params per request
|
||||
@@ -387,10 +404,12 @@ class AsyncOmni(EngineClient, OmniBase):
|
||||
except (asyncio.CancelledError, GeneratorExit):
|
||||
if input_stream_task is not None and not input_stream_task.done():
|
||||
input_stream_task.cancel()
|
||||
self._fire_failure_counter_if_alive(request_id)
|
||||
await self._abort_internal_requests(request_id)
|
||||
logger.info(f"[AsyncOmni] Request {request_id} aborted.")
|
||||
raise
|
||||
except Exception as e:
|
||||
self._fire_failure_counter_if_alive(request_id)
|
||||
await self._abort_internal_requests(request_id)
|
||||
logger.info(f"[AsyncOmni] Request {request_id} failed (input error): {e}")
|
||||
raise
|
||||
|
||||
@@ -17,3 +17,23 @@ class ClientRequestState:
|
||||
self.stage_id: int | None = None
|
||||
self.queue = queue if queue is not None else asyncio.Queue()
|
||||
self.metrics: OrchestratorAggregator | None = None
|
||||
# Wall-clock time at which the user's request arrived in the engine
|
||||
# entrypoint. Set in async_omni.generate() before the orchestrator
|
||||
# accepts the request. Used as the t0 anchor for audio_ttfp.
|
||||
self.request_arrival_ts: float = 0.0
|
||||
# Wall-clock time at which the first audio packet was observed for
|
||||
# this request. None means the streaming hook hasn't fired yet.
|
||||
# Used as the once-per-request guard for audio_ttfp_s emit.
|
||||
self.first_audio_ts: float | None = None
|
||||
# Per-chunk timeline (seconds since request_arrival_ts) and PCM byte
|
||||
# counts for the audio streaming response. Populated by the streaming
|
||||
# endpoint on every audio.chunk emit; consumed at request finalize to
|
||||
# compute audio_underrun_s and audio_continuity_ok_total.
|
||||
self.audio_chunk_arrivals_s: list[float] = []
|
||||
self.audio_chunk_bytes: list[int] = []
|
||||
self.audio_sample_rate: int | None = None
|
||||
# Stage / replica that produced the audio packets — captured at the
|
||||
# first-packet hook so the finalize-time emit can label correctly
|
||||
# without re-querying stage_pools.
|
||||
self.audio_emit_stage_id: int | None = None
|
||||
self.audio_emit_replica_id: int | None = None
|
||||
@@ -23,7 +23,10 @@ from vllm_omni.engine.messages import (
|
||||
from vllm_omni.entrypoints.client_request_state import ClientRequestState
|
||||
from vllm_omni.entrypoints.pd_utils import PDDisaggregationMixin
|
||||
from vllm_omni.entrypoints.utils import coerce_param_message_types, get_final_stage_id_for_e2e
|
||||
from vllm_omni.metrics.modality import OmniModalityMetrics, observe_modality_at_finalize
|
||||
from vllm_omni.metrics.prometheus import OmniPrometheusMetrics
|
||||
from vllm_omni.metrics.stats import OrchestratorAggregator as OrchestratorMetrics
|
||||
from vllm_omni.metrics.transfer import OmniTransferMetrics
|
||||
from vllm_omni.model_executor.model_loader.weight_utils import download_weights_from_hf_specific
|
||||
from vllm_omni.outputs import OmniRequestOutput
|
||||
|
||||
@@ -170,6 +173,10 @@ class OmniBase(PDDisaggregationMixin):
|
||||
self.tts_batch_max_items: int = kwargs.pop("tts_batch_max_items", 32)
|
||||
|
||||
logger.info("[%s] Initializing with model %s", self.__class__.__name__, model)
|
||||
# Construct transfer_metrics first so we can hand it to AsyncOmniEngine
|
||||
# (which forwards it to the Orchestrator background thread for
|
||||
# TX-side emit; see Orchestrator._forward_to_next_stage).
|
||||
self.transfer_metrics = OmniTransferMetrics(model_name=model, log_stats=log_stats)
|
||||
st = time.time()
|
||||
self.engine = AsyncOmniEngine(
|
||||
model=model,
|
||||
@@ -177,6 +184,8 @@ class OmniBase(PDDisaggregationMixin):
|
||||
init_timeout=init_timeout,
|
||||
stage_init_timeout=stage_init_timeout,
|
||||
diffusion_batch_size=diffusion_batch_size,
|
||||
transfer_emitter=self.transfer_metrics,
|
||||
log_stats=log_stats,
|
||||
**kwargs,
|
||||
)
|
||||
self._shutdown_called = False
|
||||
@@ -190,6 +199,8 @@ class OmniBase(PDDisaggregationMixin):
|
||||
self.async_chunk = bool(getattr(self.engine, "async_chunk", False))
|
||||
|
||||
self.request_states: dict[str, ClientRequestState] = {}
|
||||
self.prom_metrics = OmniPrometheusMetrics(model_name=model, log_stats=log_stats)
|
||||
self.mod_metrics = OmniModalityMetrics(model_name=model, log_stats=log_stats)
|
||||
|
||||
self.default_sampling_params_list = self.engine.default_sampling_params_list
|
||||
if not self.output_modalities:
|
||||
@@ -272,11 +283,29 @@ class OmniBase(PDDisaggregationMixin):
|
||||
raise ValueError(f"Expected {self.num_stages} sampling params, got {len(normalized)}")
|
||||
return normalized
|
||||
|
||||
def _fire_failure_counter_if_alive(self, request_id: str) -> None:
|
||||
"""Fire the abort/exception bucket of requests_success_total.
|
||||
|
||||
Called from cancel / exception paths in async_omni.generate() BEFORE
|
||||
_abort_internal_requests pops request_states — that method resolves
|
||||
the internal id by dict lookup, so popping first would no-op it. We
|
||||
keep this counter fire separate from _log_summary_and_cleanup (which
|
||||
pops) so the abort path can still find the state to clean up.
|
||||
"""
|
||||
req_state = self.request_states.get(request_id)
|
||||
prom = getattr(self, "prom_metrics", None)
|
||||
if req_state is None or req_state.metrics is None or prom is None:
|
||||
return
|
||||
if str(request_id) not in req_state.metrics.e2e_done:
|
||||
prom.request_failed()
|
||||
|
||||
def _log_summary_and_cleanup(self, request_id: str) -> None:
|
||||
req_state = self.request_states.get(request_id)
|
||||
try:
|
||||
if req_state is None or req_state.metrics is None:
|
||||
return
|
||||
if str(request_id) not in req_state.metrics.e2e_done:
|
||||
self.prom_metrics.request_failed()
|
||||
if self.log_stats:
|
||||
# Emit per-request orchestrator timing (including e2e_total_ms)
|
||||
# before dropping request state.
|
||||
@@ -289,6 +318,16 @@ class OmniBase(PDDisaggregationMixin):
|
||||
)
|
||||
finally:
|
||||
self.request_states.pop(request_id, None)
|
||||
# Republish gauges so any stale value left by the per-stage
|
||||
# publish in _process_single_result (which runs while the request
|
||||
# is still in self.request_states) is corrected after the pop.
|
||||
prom = getattr(self, "prom_metrics", None)
|
||||
counter = getattr(getattr(self, "engine", None), "_running_counter", None)
|
||||
if prom is not None:
|
||||
total = len(self.request_states)
|
||||
running = counter.value if counter is not None else total
|
||||
prom.set_running(running)
|
||||
prom.set_waiting(max(0, total - running))
|
||||
|
||||
def _compute_final_stage_id(self, output_modalities: list[str] | None) -> int:
|
||||
return get_final_stage_id_for_e2e(
|
||||
@@ -435,6 +474,8 @@ class OmniBase(PDDisaggregationMixin):
|
||||
if not stage_meta.final_output:
|
||||
return None
|
||||
|
||||
output_type = getattr(engine_outputs, "final_output_type", stage_meta.final_output_type)
|
||||
|
||||
try:
|
||||
rid_key = str(req_id)
|
||||
if stage_id == final_stage_id_for_e2e and rid_key not in metrics.e2e_done and finished:
|
||||
@@ -443,10 +484,41 @@ class OmniBase(PDDisaggregationMixin):
|
||||
req_id,
|
||||
req_start_ts.get(req_id, wall_start_ts),
|
||||
)
|
||||
e2e_seconds = now - req_start_ts.get(req_id, wall_start_ts)
|
||||
# Extract finished_reason from upstream CompletionOutput so
|
||||
# the per-reason completion Counter is labelled correctly.
|
||||
completion_outputs = getattr(engine_outputs, "outputs", None) or []
|
||||
fr = (getattr(completion_outputs[0], "finish_reason", None) if completion_outputs else None) or "stop"
|
||||
self.prom_metrics.request_succeeded(
|
||||
e2e_seconds,
|
||||
finished_reason=fr,
|
||||
)
|
||||
|
||||
# Modality observe inside the same finalize guard so it fires
|
||||
# once per request and inherits the try/except isolation.
|
||||
observe_modality_at_finalize(
|
||||
self.mod_metrics,
|
||||
output_type=output_type,
|
||||
stage_id=stage_id,
|
||||
replica_id=result.replica_id,
|
||||
stage_metrics=_m,
|
||||
engine_outputs=engine_outputs,
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("[%s] Finalize request handling error", self.__class__.__name__)
|
||||
|
||||
output_type = getattr(engine_outputs, "final_output_type", stage_meta.final_output_type)
|
||||
# When this result finalizes the request, the orchestrator has
|
||||
# already decremented _running_counter but _log_summary_and_cleanup
|
||||
# hasn't popped self.request_states yet — exclude the finalizing
|
||||
# request from `total` so waiting doesn't read 1 and stay stuck
|
||||
# there until the next request arrives.
|
||||
counter = getattr(self.engine, "_running_counter", None)
|
||||
is_finalizing = finished and stage_id == final_stage_id_for_e2e
|
||||
total = max(0, len(self.request_states) - (1 if is_finalizing else 0))
|
||||
running = counter.value if counter is not None else total
|
||||
self.prom_metrics.set_running(running)
|
||||
self.prom_metrics.set_waiting(max(0, total - running))
|
||||
|
||||
images = getattr(engine_outputs, "images", []) if output_type == "image" else []
|
||||
return OmniRequestOutput(
|
||||
request_id=req_id or "",
|
||||
|
||||
@@ -20,6 +20,11 @@ from vllm_omni.entrypoints.async_omni import AsyncOmni
|
||||
from vllm_omni.entrypoints.openai.protocol.chat_completion import OmniChatCompletionResponse
|
||||
from vllm_omni.entrypoints.utils import coerce_param_message_types
|
||||
from vllm_omni.inputs.data import OmniDiffusionSamplingParams, OmniTextPrompt
|
||||
from vllm_omni.metrics import definitions as _metric_defs
|
||||
from vllm_omni.metrics.modality import (
|
||||
observe_audio_first_packet,
|
||||
observe_audio_streaming_finalize,
|
||||
)
|
||||
|
||||
try:
|
||||
import soundfile
|
||||
@@ -110,6 +115,7 @@ from vllm_omni.entrypoints.openai.utils import (
|
||||
)
|
||||
from vllm_omni.lora.request import LoRARequest
|
||||
from vllm_omni.outputs import OmniRequestOutput
|
||||
from vllm_omni.utils.audio import audio_chunk_pcm_bytes, audio_chunk_sample_rate
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
@@ -1032,6 +1038,11 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
|
||||
include_usage, include_continuous_usage = should_include_usage(stream_options, self.enable_force_include_usage)
|
||||
|
||||
last_metrics: dict[str, Any] | None = None
|
||||
# Hold a strong reference to the audio request state so the
|
||||
# streaming-finalize hook below survives the inner generator's
|
||||
# _log_summary_and_cleanup, which pops request_states[request_id]
|
||||
# before this outer block runs.
|
||||
req_state_audio_ref: Any = None
|
||||
try:
|
||||
async for omni_res in result_generator:
|
||||
final_output_type = omni_res.final_output_type
|
||||
@@ -1605,8 +1616,53 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
|
||||
yield f"data: {data}\n\n"
|
||||
|
||||
elif final_output_type == "audio":
|
||||
# Observe audio_ttfp_s on first audio packet for this request_id
|
||||
# (once-per-request guard via first_audio_ts). The same hook
|
||||
# also captures (stage, replica) for the streaming-continuity
|
||||
# emit at request finalize. self.engine_client.request_states
|
||||
# is keyed by the internal UUID-suffixed id (set by
|
||||
# AsyncOmni.generate via _get_unique_request_id), but the
|
||||
# `request_id` we have here is the external (user-visible) id,
|
||||
# so resolve via the external_request_id field.
|
||||
req_state = next(
|
||||
(s for s in self.engine_client.request_states.values() if s.external_request_id == request_id),
|
||||
None,
|
||||
)
|
||||
if req_state is not None and req_state_audio_ref is None:
|
||||
req_state_audio_ref = req_state
|
||||
now_ts = time.time()
|
||||
if req_state is not None and req_state.first_audio_ts is None:
|
||||
req_state.first_audio_ts = now_ts
|
||||
stage_pools = getattr(self.engine_client.engine, "stage_pools", None)
|
||||
# The orchestrator binds requests by their internal id,
|
||||
# not the user-visible external id, so look up the
|
||||
# replica with req_state.request_id (internal).
|
||||
replica_id = (
|
||||
stage_pools[omni_res.stage_id].get_bound_replica_id(req_state.request_id)
|
||||
if stage_pools is not None and 0 <= omni_res.stage_id < len(stage_pools)
|
||||
else None
|
||||
)
|
||||
req_state.audio_emit_stage_id = omni_res.stage_id
|
||||
req_state.audio_emit_replica_id = replica_id
|
||||
observe_audio_first_packet(
|
||||
self.engine_client.mod_metrics,
|
||||
stage_id=omni_res.stage_id,
|
||||
replica_id=replica_id,
|
||||
arrival_ts=req_state.request_arrival_ts,
|
||||
now_ts=now_ts,
|
||||
)
|
||||
|
||||
role = self.get_chat_request_role(request)
|
||||
choices_data = self._create_audio_choice(omni_res, role, request, stream=True)
|
||||
# Record per-chunk PCM byte count + arrival timestamp for
|
||||
# audio_underrun_s / audio_continuity_ok_total at finalize.
|
||||
if req_state is not None and req_state.request_arrival_ts > 0:
|
||||
chunk_bytes = audio_chunk_pcm_bytes(omni_res)
|
||||
if chunk_bytes > 0:
|
||||
req_state.audio_chunk_arrivals_s.append(max(now_ts - req_state.request_arrival_ts, 0.0))
|
||||
req_state.audio_chunk_bytes.append(chunk_bytes)
|
||||
if req_state.audio_sample_rate is None:
|
||||
req_state.audio_sample_rate = audio_chunk_sample_rate(omni_res)
|
||||
chunk = OmniChatCompletionStreamResponse(
|
||||
id=request_id,
|
||||
object=chunk_object_type,
|
||||
@@ -1627,6 +1683,24 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
|
||||
logger.warning(f"Unsupported streaming final output type: {final_output_type}")
|
||||
continue
|
||||
|
||||
# Emit audio_underrun_s + audio_continuity_ok_total once per
|
||||
# request after the audio chunk stream is exhausted. The
|
||||
# captured reference (req_state_audio_ref) outlives the inner
|
||||
# _log_summary_and_cleanup that pops request_states[request_id].
|
||||
if (
|
||||
req_state_audio_ref is not None
|
||||
and req_state_audio_ref.audio_chunk_arrivals_s
|
||||
and req_state_audio_ref.audio_emit_replica_id is not None
|
||||
):
|
||||
observe_audio_streaming_finalize(
|
||||
self.engine_client.mod_metrics,
|
||||
stage_id=req_state_audio_ref.audio_emit_stage_id or 0,
|
||||
replica_id=req_state_audio_ref.audio_emit_replica_id,
|
||||
chunk_arrival_times_s=req_state_audio_ref.audio_chunk_arrivals_s,
|
||||
chunk_bytes=req_state_audio_ref.audio_chunk_bytes,
|
||||
sample_rate=(req_state_audio_ref.audio_sample_rate or _metric_defs.DEFAULT_AUDIO_SAMPLE_RATE),
|
||||
)
|
||||
|
||||
# once the final token is handled, if stream_options.include_usage
|
||||
# is sent, send the usage
|
||||
if include_usage:
|
||||
|
||||
Reference in new issue
Block a user