[diffusion] profile: support performance metric dumping and comparison (#13630)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import multiprocessing as mp
|
||||
import os
|
||||
import time
|
||||
from typing import List
|
||||
|
||||
import torch
|
||||
@@ -25,6 +26,10 @@ from sglang.multimodal_gen.runtime.utils.logging_utils import (
|
||||
init_logger,
|
||||
suppress_other_loggers,
|
||||
)
|
||||
from sglang.multimodal_gen.runtime.utils.perf_logger import (
|
||||
PerformanceLogger,
|
||||
RequestTimings,
|
||||
)
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
@@ -86,27 +91,35 @@ class GPUWorker:
|
||||
f"Worker {self.rank}: Initialized device, model, and distributed environment."
|
||||
)
|
||||
|
||||
def execute_forward(self, batch: List[Req], server_args: ServerArgs) -> OutputBatch:
|
||||
def execute_forward(self, batch: List[Req]) -> OutputBatch:
|
||||
"""
|
||||
Execute a forward pass.
|
||||
"""
|
||||
assert self.pipeline is not None
|
||||
# TODO: dealing with first req for now
|
||||
req = batch[0]
|
||||
output_batch = self.pipeline.forward(req, server_args)
|
||||
if req.perf_logger:
|
||||
logging_info = getattr(output_batch, "logging_info", None) or getattr(
|
||||
req, "logging_info", None
|
||||
)
|
||||
if logging_info:
|
||||
try:
|
||||
req.perf_logger.log_stage_metrics(logging_info)
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"Failed to log stage metrics for request %s", req.request_id
|
||||
)
|
||||
req.perf_logger.log_total_duration("total_inference_time")
|
||||
return output_batch
|
||||
output_batch = None
|
||||
try:
|
||||
start_time = time.monotonic()
|
||||
timings = RequestTimings(request_id=req.request_id)
|
||||
req.timings = timings
|
||||
|
||||
output_batch = self.pipeline.forward(req, self.server_args)
|
||||
duration_ms = (time.monotonic() - start_time) * 1000
|
||||
|
||||
if output_batch.timings:
|
||||
output_batch.timings.total_duration_ms = duration_ms
|
||||
PerformanceLogger.log_request_summary(timings=output_batch.timings)
|
||||
except Exception as e:
|
||||
if output_batch is None:
|
||||
from sglang.multimodal_gen.runtime.pipelines_core.schedule_batch import (
|
||||
OutputBatch,
|
||||
)
|
||||
|
||||
output_batch = OutputBatch()
|
||||
output_batch.error = f"Error executing request {req.request_id}: {e}"
|
||||
finally:
|
||||
return output_batch
|
||||
|
||||
def set_lora_adapter(
|
||||
self, lora_nickname: str, lora_path: str | None = None
|
||||
|
||||
Reference in New Issue
Block a user