[diffusion] log: avoid logging in hot path if unnecessary (#15818)
This commit is contained in:
@@ -26,10 +26,7 @@ from sglang.multimodal_gen.runtime.utils.logging_utils import (
|
||||
globally_suppress_loggers,
|
||||
init_logger,
|
||||
)
|
||||
from sglang.multimodal_gen.runtime.utils.perf_logger import (
|
||||
PerformanceLogger,
|
||||
RequestTimings,
|
||||
)
|
||||
from sglang.multimodal_gen.runtime.utils.perf_logger import PerformanceLogger
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
@@ -101,19 +98,18 @@ class GPUWorker:
|
||||
torch.cuda.reset_peak_memory_stats()
|
||||
|
||||
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 self.rank == 0:
|
||||
peak_memory_bytes = torch.cuda.max_memory_allocated()
|
||||
output_batch.peak_memory_mb = peak_memory_bytes / (1024**2)
|
||||
|
||||
if output_batch.timings:
|
||||
duration_ms = (time.monotonic() - start_time) * 1000
|
||||
output_batch.timings.total_duration_ms = duration_ms
|
||||
PerformanceLogger.log_request_summary(timings=output_batch.timings)
|
||||
if req.perf_dump_path is not None:
|
||||
PerformanceLogger.log_request_summary(timings=output_batch.timings)
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"Error executing request {req.request_id}: {e}", exc_info=True
|
||||
|
||||
@@ -14,7 +14,7 @@ from __future__ import annotations
|
||||
import os
|
||||
import pprint
|
||||
from dataclasses import asdict, dataclass, field
|
||||
from typing import TYPE_CHECKING, Any, Optional
|
||||
from typing import Any, Optional
|
||||
|
||||
import PIL.Image
|
||||
import torch
|
||||
@@ -26,13 +26,9 @@ from sglang.multimodal_gen.configs.sample.teacache import (
|
||||
)
|
||||
from sglang.multimodal_gen.runtime.server_args import ServerArgs
|
||||
from sglang.multimodal_gen.runtime.utils.logging_utils import init_logger
|
||||
from sglang.multimodal_gen.runtime.utils.perf_logger import RequestTimings
|
||||
from sglang.multimodal_gen.utils import align_to
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
||||
from sglang.multimodal_gen.runtime.utils.perf_logger import RequestTimings
|
||||
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
@@ -229,6 +225,8 @@ class Req:
|
||||
if self.guidance_scale_2 is None:
|
||||
self.guidance_scale_2 = self.guidance_scale
|
||||
|
||||
self.timings = RequestTimings(request_id=self.request_id)
|
||||
|
||||
def adjust_size(self, server_args: ServerArgs):
|
||||
pass
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ class TimestepPreparationStage(PipelineStage):
|
||||
|
||||
# Update batch with prepared timesteps
|
||||
batch.timesteps = timesteps
|
||||
self.log_debug(f"timesteps: {timesteps}")
|
||||
self.log_debug("timesteps: %s", timesteps)
|
||||
return batch
|
||||
|
||||
def verify_input(self, batch: Req, server_args: ServerArgs) -> VerificationResult:
|
||||
|
||||
@@ -138,20 +138,24 @@ class StageProfiler:
|
||||
self.simple_log = simple_log
|
||||
self.start_time = 0.0
|
||||
|
||||
self._metrics_enabled = StageProfiler.metrics_enabled()
|
||||
|
||||
@staticmethod
|
||||
def metrics_enabled():
|
||||
# Check env var at runtime to ensure we pick up changes (e.g. from CLI args)
|
||||
self.metrics_enabled = envs.SGLANG_DIFFUSION_STAGE_LOGGING
|
||||
return envs.SGLANG_DIFFUSION_STAGE_LOGGING
|
||||
|
||||
def __enter__(self):
|
||||
if self.simple_log:
|
||||
self.logger.info(f"[{self.stage_name}] started...")
|
||||
|
||||
if (self.metrics_enabled and self.timings) or self.simple_log:
|
||||
if (self._metrics_enabled and self.timings) or self.simple_log:
|
||||
self.start_time = time.perf_counter()
|
||||
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
if not ((self.metrics_enabled and self.timings) or self.simple_log):
|
||||
if not ((self._metrics_enabled and self.timings) or self.simple_log):
|
||||
return False
|
||||
|
||||
execution_time_s = time.perf_counter() - self.start_time
|
||||
@@ -171,7 +175,7 @@ class StageProfiler:
|
||||
f"[{self.stage_name}] finished in {execution_time_s:.4f} seconds",
|
||||
)
|
||||
|
||||
if self.metrics_enabled and self.timings:
|
||||
if self._metrics_enabled and self.timings:
|
||||
if "denoising_step_" in self.stage_name:
|
||||
index = int(self.stage_name[len("denoising_step_") :])
|
||||
self.timings.record_steps(index, execution_time_s)
|
||||
@@ -240,6 +244,8 @@ class PerformanceLogger:
|
||||
):
|
||||
"""logs the stage metrics and total duration for a completed request
|
||||
to the performance_log file.
|
||||
|
||||
Note that this accords to the time spent internally in server, postprocess is not included
|
||||
"""
|
||||
formatted_stages = [
|
||||
{"name": name, "execution_time_ms": duration_ms}
|
||||
|
||||
Reference in New Issue
Block a user