text and image metric (#6150)
Signed-off-by: zhuhh97 <zhuhonghan@huawei.com> Signed-off-by: Gao Han <hgaoaf@connect.ust.hk> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com> Co-authored-by: Gao Han <hgaoaf@connect.ust.hk>
This commit is contained in:
33 files changed
+1802
-162
No files matched your search
@@ -1528,6 +1528,9 @@ class DiffusionOutput:
|
||||
# memory usage info
|
||||
peak_memory_mb: float = 0.0
|
||||
|
||||
# KV-recv wall-clock (ms) from the runner; feeds vllm_omni:diffusion_kv_load_s.
|
||||
kv_recv_ms: float = 0.0
|
||||
|
||||
# When True, move tensor fields to CPU at construction time. Useful when
|
||||
# the output is shipped across process boundaries (e.g. step-execution
|
||||
# mode) and the receiving side must not initialise a stray CUDA context.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -56,6 +56,11 @@ from vllm_omni.diffusion.sched.interface import DiffusionRequestStatus
|
||||
from vllm_omni.diffusion.worker.utils import BaseRunnerOutput, BatchRunnerOutput, RunnerOutput
|
||||
from vllm_omni.errors import client_error_from_metadata, is_client_error_status
|
||||
from vllm_omni.inputs.data import OmniDiffusionSamplingParams, OmniTextPrompt
|
||||
from vllm_omni.metrics.utils import (
|
||||
diffusion_scheduler_waiting_metrics,
|
||||
extract_diffusion_denoise_ms,
|
||||
extract_diffusion_vae_decode_ms,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from vllm_omni.outputs import OmniRequestOutput
|
||||
@@ -375,6 +380,9 @@ class DiffusionEngine:
|
||||
self._shutdown_complete = False
|
||||
self.abort_queue: queue.Queue[str] = queue.Queue()
|
||||
self._rpc_queue: queue.Queue[_RpcTask] = queue.Queue()
|
||||
# Copied onto the existing output metrics payload so queue monitoring
|
||||
# reuses the normal diffusion result path without additional IPC.
|
||||
self._scheduler_num_waiting_reqs = 0
|
||||
|
||||
def _init_execute_fn(self) -> None:
|
||||
if self.execution_mode == DiffusionExecutionMode.STEP_BATCH:
|
||||
@@ -444,7 +452,14 @@ class DiffusionEngine:
|
||||
)
|
||||
raise
|
||||
postprocess_start_time = time.perf_counter()
|
||||
formatted_outputs = self.postprocess_output(request, output)
|
||||
scheduler_metrics = diffusion_scheduler_waiting_metrics(getattr(self, "_scheduler_num_waiting_reqs", 0))
|
||||
try:
|
||||
formatted_outputs = self.postprocess_output(request, output)
|
||||
except Exception as exc:
|
||||
# Preserve the latest scheduler snapshot across terminal
|
||||
# abort/error paths, which do not produce formatted outputs.
|
||||
setattr(exc, "diffusion_metrics", scheduler_metrics)
|
||||
raise
|
||||
postprocess_time = time.perf_counter() - postprocess_start_time
|
||||
step_total_ms = (time.perf_counter() - diffusion_engine_start_time) * 1000
|
||||
logger.debug(
|
||||
@@ -456,14 +471,24 @@ class DiffusionEngine:
|
||||
step_total_ms,
|
||||
)
|
||||
for request_output in formatted_outputs:
|
||||
request_output.metrics.update(
|
||||
{
|
||||
"preprocess_time_ms": preprocess_time * 1000,
|
||||
"diffusion_engine_exec_time_ms": exec_total_time * 1000,
|
||||
"diffusion_engine_total_time_ms": step_total_ms,
|
||||
"postprocess_time_ms": postprocess_time * 1000,
|
||||
}
|
||||
)
|
||||
metrics_update = {
|
||||
"preprocess_time_ms": preprocess_time * 1000,
|
||||
"diffusion_engine_exec_time_ms": exec_total_time * 1000,
|
||||
"postprocess_time_ms": postprocess_time * 1000,
|
||||
**scheduler_metrics,
|
||||
}
|
||||
if request.scheduler_queue_wait_ms is not None:
|
||||
metrics_update["scheduler_queue_wait_ms"] = request.scheduler_queue_wait_ms
|
||||
vae_decode_ms = extract_diffusion_vae_decode_ms(output)
|
||||
if vae_decode_ms is not None:
|
||||
metrics_update["vae_decode_time_ms"] = vae_decode_ms
|
||||
forward_ms = extract_diffusion_denoise_ms(output)
|
||||
if forward_ms is not None:
|
||||
metrics_update["forward_time_ms"] = forward_ms
|
||||
kv_recv_ms = getattr(output, "kv_recv_ms", 0.0)
|
||||
if kv_recv_ms > 0:
|
||||
metrics_update["kv_recv_time_ms"] = kv_recv_ms
|
||||
request_output.metrics.update(metrics_update)
|
||||
yield formatted_outputs
|
||||
|
||||
async def step(self, request: OmniDiffusionRequest) -> list[OmniRequestOutput]:
|
||||
@@ -554,6 +579,7 @@ class DiffusionEngine:
|
||||
self._wait_for_admission_if_needed_locked()
|
||||
|
||||
sched_output = self.scheduler.schedule()
|
||||
self._scheduler_num_waiting_reqs = max(int(sched_output.num_waiting_reqs), 0)
|
||||
|
||||
if sched_output.is_empty:
|
||||
self._emit_finished_outputs(sched_output.finished_req_ids, None)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
|
||||
"""Inline Stage Diffusion Client for vLLM-Omni multi-stage runtime.
|
||||
|
||||
Runs DiffusionEngine in a ThreadPoolExecutor inside the Orchestrator process
|
||||
@@ -23,6 +26,7 @@ from vllm_omni.engine.stage_client import StageClientBase
|
||||
from vllm_omni.engine.stage_init_utils import StageMetadata
|
||||
from vllm_omni.errors import client_error_metadata
|
||||
from vllm_omni.inputs.data import OmniDiffusionSamplingParams, OmniInteractionPrompt
|
||||
from vllm_omni.metrics.utils import DIFFUSION_METRICS_ONLY_REQUEST_ID, diffusion_exception_metrics
|
||||
from vllm_omni.outputs import OmniRequestOutput
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -158,6 +162,15 @@ class InlineStageDiffusionClient(StageClientBase):
|
||||
self._output_queue.put_nowait(result)
|
||||
except DiffusionRequestAbortedError as e:
|
||||
logger.info("request_id: %s aborted: %s", request_id, str(e))
|
||||
metrics = diffusion_exception_metrics(e)
|
||||
if metrics:
|
||||
self._output_queue.put_nowait(
|
||||
OmniRequestOutput(
|
||||
request_id=DIFFUSION_METRICS_ONLY_REQUEST_ID,
|
||||
finished=True,
|
||||
metrics=metrics,
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
logger.exception("Diffusion request %s failed: %s", request_id, e)
|
||||
status_code, error_type = client_error_metadata(e)
|
||||
@@ -167,6 +180,7 @@ class InlineStageDiffusionClient(StageClientBase):
|
||||
status_code=status_code,
|
||||
error_type=error_type,
|
||||
)
|
||||
error_output.metrics.update(diffusion_exception_metrics(e))
|
||||
self._output_queue.put_nowait(error_output)
|
||||
finally:
|
||||
self._tasks.pop(request_id, None)
|
||||
@@ -181,9 +195,8 @@ class InlineStageDiffusionClient(StageClientBase):
|
||||
|
||||
async def abort_requests_async(self, request_ids: list[str]) -> None:
|
||||
for rid in request_ids:
|
||||
task = self._tasks.pop(rid, None)
|
||||
if task:
|
||||
task.cancel()
|
||||
# Keep the consumer alive until the engine emits its terminal
|
||||
# abort output. That path carries the refreshed scheduler gauge.
|
||||
self._engine.abort(rid)
|
||||
|
||||
async def submit_interaction_async(
|
||||
|
||||
@@ -67,6 +67,11 @@ class OmniDiffusionRequest:
|
||||
# This is populated by a pipeline preprocessor before the request reaches
|
||||
# the scheduler; ``None`` keeps the default behavior for other pipelines.
|
||||
batch_compatibility_key: tuple[Any, ...] | None = None
|
||||
# KV-recv wall-clock (ms), set by the runner's _prepare_request_for_forward
|
||||
# and carried to DiffusionOutput for the vllm_omni:diffusion_kv_load_s metric.
|
||||
kv_recv_ms: float = 0.0
|
||||
# Time spent waiting for initial admission by the diffusion scheduler.
|
||||
scheduler_queue_wait_ms: float | None = None
|
||||
|
||||
def __post_init__(self):
|
||||
"""Initialize dependent fields after dataclass initialization."""
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
from abc import ABC, abstractmethod
|
||||
from collections import deque
|
||||
from dataclasses import fields
|
||||
@@ -117,6 +118,7 @@ class BaseScheduler(ABC):
|
||||
if request_id in self._request_states:
|
||||
raise ValueError(f"request_id {request_id!r} is already active.")
|
||||
state = self._make_request_state(request_id, request)
|
||||
state.queued_at = time.perf_counter()
|
||||
self._request_states[request_id] = state
|
||||
self._waiting.append(request_id)
|
||||
logger.debug("%s add_request: %s (waiting=%d)", self.__class__.__name__, request_id, len(self._waiting))
|
||||
@@ -178,6 +180,7 @@ class BaseScheduler(ABC):
|
||||
state.status = DiffusionRequestStatus.RUNNING
|
||||
self._running.append(request_id)
|
||||
if was_new_request:
|
||||
state.req.scheduler_queue_wait_ms = max((time.perf_counter() - state.queued_at) * 1000.0, 0.0)
|
||||
scheduled_new_reqs.append(
|
||||
NewRequestData.from_state(
|
||||
state,
|
||||
|
||||
@@ -157,6 +157,7 @@ class SchedulerRequestState:
|
||||
diffusion_kv_requests: tuple[DiffusionKVRequest, ...] = ()
|
||||
status: DiffusionRequestStatus = DiffusionRequestStatus.WAITING
|
||||
error: str | None = None
|
||||
queued_at: float = 0.0
|
||||
|
||||
def is_finished(self) -> bool:
|
||||
return DiffusionRequestStatus.is_finished(self.status)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
|
||||
"""Stage Diffusion Client for vLLM-Omni multi-stage runtime.
|
||||
|
||||
Owns the frontend-side ZMQ sockets for StageDiffusionProc and exposes the
|
||||
@@ -30,6 +33,7 @@ from vllm_omni.distributed.omni_connectors.utils.serialization import (
|
||||
)
|
||||
from vllm_omni.engine.stage_client import StageClientBase
|
||||
from vllm_omni.engine.stage_init_utils import StageMetadata
|
||||
from vllm_omni.metrics.utils import DIFFUSION_METRICS_ONLY_REQUEST_ID
|
||||
from vllm_omni.outputs import OmniRequestOutput
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -240,6 +244,14 @@ class StageDiffusionClient(StageClientBase):
|
||||
|
||||
if msg_type == "result":
|
||||
self._output_queue.put_nowait(msg["output"])
|
||||
elif msg_type == "metrics":
|
||||
self._output_queue.put_nowait(
|
||||
OmniRequestOutput(
|
||||
request_id=DIFFUSION_METRICS_ONLY_REQUEST_ID,
|
||||
finished=True,
|
||||
metrics=msg.get("metrics") or {},
|
||||
)
|
||||
)
|
||||
elif msg_type == "rpc_result":
|
||||
self._rpc_results[msg["rpc_id"]] = msg["result"]
|
||||
elif msg_type == "error":
|
||||
@@ -264,14 +276,14 @@ class StageDiffusionClient(StageClientBase):
|
||||
# Route request errors as error outputs so the Orchestrator
|
||||
# sees the request complete (instead of hanging forever).
|
||||
if req_id is not None:
|
||||
self._output_queue.put_nowait(
|
||||
OmniRequestOutput.from_error(
|
||||
req_id,
|
||||
error_msg,
|
||||
status_code=status_code,
|
||||
error_type=error_type,
|
||||
)
|
||||
error_output = OmniRequestOutput.from_error(
|
||||
req_id,
|
||||
error_msg,
|
||||
status_code=status_code,
|
||||
error_type=error_type,
|
||||
)
|
||||
error_output.metrics.update(msg.get("metrics") or {})
|
||||
self._output_queue.put_nowait(error_output)
|
||||
|
||||
# Fields that are subprocess-local and cannot be serialized across
|
||||
# process boundaries. They are recreated in the subprocess with
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
|
||||
"""Subprocess entry point for the diffusion engine.
|
||||
|
||||
StageDiffusionProc runs DiffusionEngine in a child process,
|
||||
@@ -36,6 +39,7 @@ from vllm_omni.distributed.omni_coordinator import OmniCoordClientForStage
|
||||
from vllm_omni.engine.stage_init_utils import set_death_signal
|
||||
from vllm_omni.errors import client_error_metadata
|
||||
from vllm_omni.inputs.data import OmniDiffusionSamplingParams
|
||||
from vllm_omni.metrics.utils import diffusion_exception_metrics
|
||||
from vllm_omni.outputs import OmniRequestOutput
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -361,6 +365,16 @@ class StageDiffusionProc:
|
||||
request_id,
|
||||
str(e),
|
||||
)
|
||||
metrics = diffusion_exception_metrics(e)
|
||||
if metrics:
|
||||
await response_socket.send(
|
||||
encoder.encode(
|
||||
{
|
||||
"type": "metrics",
|
||||
"metrics": metrics,
|
||||
}
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
logger.exception("Diffusion request %s failed: %s", request_id, e)
|
||||
status_code, error_type = client_error_metadata(e)
|
||||
@@ -372,6 +386,7 @@ class StageDiffusionProc:
|
||||
"error": str(e),
|
||||
"status_code": status_code,
|
||||
"error_type": error_type,
|
||||
"metrics": diffusion_exception_metrics(e),
|
||||
}
|
||||
)
|
||||
)
|
||||
@@ -426,9 +441,8 @@ class StageDiffusionProc:
|
||||
|
||||
elif msg_type == "abort":
|
||||
for rid in msg.get("request_ids", []):
|
||||
task = tasks.pop(rid, None)
|
||||
if task:
|
||||
task.cancel()
|
||||
# Let the request task consume the terminal abort
|
||||
# output so it can publish the scheduler snapshot.
|
||||
self._engine.abort(rid)
|
||||
|
||||
elif msg_type == "collective_rpc":
|
||||
|
||||
@@ -539,6 +539,7 @@ class DiffusionModelRunner(OmniConnectorModelRunnerMixin):
|
||||
target_device=self._target_device if use_prefetch else getattr(self.pipeline, "device", None),
|
||||
)
|
||||
kv_recv_ms = (time.perf_counter() - kv_recv_t0) * 1000
|
||||
req.kv_recv_ms = kv_recv_ms
|
||||
logger.debug("KV recv for %s %.1fms", req.request_id, kv_recv_ms)
|
||||
|
||||
# Kick off the next request's prefetch (+ H2D) to overlap this forward.
|
||||
@@ -596,6 +597,10 @@ class DiffusionModelRunner(OmniConnectorModelRunnerMixin):
|
||||
reqs: list[OmniDiffusionRequest],
|
||||
outputs: list[DiffusionOutput],
|
||||
) -> BatchRunnerOutput:
|
||||
for i in range(len(reqs)):
|
||||
# Carry the runner-measured KV-recv timing onto the output so the
|
||||
# engine's step_streaming can surface it as diffusion_kv_load_s.
|
||||
outputs[i].kv_recv_ms = reqs[i].kv_recv_ms
|
||||
return BatchRunnerOutput.from_list(
|
||||
[
|
||||
RunnerOutput(
|
||||
|
||||
Reference in new issue
Block a user