From 62004fd2beb77daa10502e292e66a0d2f5662e3e Mon Sep 17 00:00:00 2001 From: Mick Date: Tue, 3 Feb 2026 10:35:05 +0800 Subject: [PATCH] [diffusion] UX: improve logging (#18122) --- .../runtime/managers/gpu_worker.py | 1 + .../runtime/pipelines/diffusers_pipeline.py | 6 +-- .../pipelines_core/composed_pipeline_base.py | 2 - .../stages/latent_preparation.py | 10 +---- .../runtime/utils/logging_utils.py | 40 ++++++------------- 5 files changed, 19 insertions(+), 40 deletions(-) diff --git a/python/sglang/multimodal_gen/runtime/managers/gpu_worker.py b/python/sglang/multimodal_gen/runtime/managers/gpu_worker.py index 55536832b..5008c1d61 100644 --- a/python/sglang/multimodal_gen/runtime/managers/gpu_worker.py +++ b/python/sglang/multimodal_gen/runtime/managers/gpu_worker.py @@ -162,6 +162,7 @@ class GPUWorker: start_time = time.monotonic() + req.log(server_args=self.server_args) result = self.pipeline.forward(req, self.server_args) if isinstance(result, Req): diff --git a/python/sglang/multimodal_gen/runtime/pipelines/diffusers_pipeline.py b/python/sglang/multimodal_gen/runtime/pipelines/diffusers_pipeline.py index 73f44f6b3..bb01bfef9 100644 --- a/python/sglang/multimodal_gen/runtime/pipelines/diffusers_pipeline.py +++ b/python/sglang/multimodal_gen/runtime/pipelines/diffusers_pipeline.py @@ -136,7 +136,7 @@ class DiffusersExecutionStage(PipelineStage): result = self._convert_to_tensor(data) if result is not None: - logger.info( + logger.debug( "Extracted output from '%s': shape=%s, dtype=%s", attr, result.shape, @@ -225,7 +225,7 @@ class DiffusersExecutionStage(PipelineStage): # Ensure correct shape for downstream processing output = self._fix_output_shape(output) - logger.info("Final output tensor shape: %s", output.shape) + logger.debug("Final output tensor shape: %s", output.shape) return output def _fix_output_shape(self, output: torch.Tensor) -> torch.Tensor: @@ -585,7 +585,7 @@ class DiffusersPipeline(ComposedPipelineBase): pipe_class_name = self.diffusers_pipe.__class__.__name__.lower() video_indicators = ["video", "animat", "cogvideo", "wan", "hunyuan"] self.is_video_pipeline = any(ind in pipe_class_name for ind in video_indicators) - logger.info( + logger.debug( "Detected pipeline type: %s", "video" if self.is_video_pipeline else "image", ) diff --git a/python/sglang/multimodal_gen/runtime/pipelines_core/composed_pipeline_base.py b/python/sglang/multimodal_gen/runtime/pipelines_core/composed_pipeline_base.py index 65e56cab7..0b3004ad6 100644 --- a/python/sglang/multimodal_gen/runtime/pipelines_core/composed_pipeline_base.py +++ b/python/sglang/multimodal_gen/runtime/pipelines_core/composed_pipeline_base.py @@ -343,8 +343,6 @@ class ComposedPipelineBase(ABC): "LoRA adapter is set, but not effective. Please make sure the LoRA weights are merged" ) - batch.log(server_args=server_args) - # Execute each stage if not batch.is_warmup and not batch.suppress_logs: logger.info( diff --git a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/latent_preparation.py b/python/sglang/multimodal_gen/runtime/pipelines_core/stages/latent_preparation.py index 82582f04a..1c0675905 100644 --- a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/latent_preparation.py +++ b/python/sglang/multimodal_gen/runtime/pipelines_core/stages/latent_preparation.py @@ -48,10 +48,8 @@ class LatentPreparationStage(PipelineStage): The batch with prepared latent variables. """ - latent_num_frames = None # Adjust video length based on VAE version if needed - if hasattr(self, "adjust_video_length"): - latent_num_frames = self.adjust_video_length(batch, server_args) + latent_num_frames = self.adjust_video_length(batch, server_args) batch_size = batch.batch_size @@ -108,14 +106,10 @@ class LatentPreparationStage(PipelineStage): def adjust_video_length(self, batch: Req, server_args: ServerArgs) -> int: """ Adjust video length based on VAE version. - - - - Returns: - The batch with adjusted video length. """ video_length = batch.num_frames + latent_num_frames = video_length use_temporal_scaling_frames = ( server_args.pipeline_config.vae_config.use_temporal_scaling_frames ) diff --git a/python/sglang/multimodal_gen/runtime/utils/logging_utils.py b/python/sglang/multimodal_gen/runtime/utils/logging_utils.py index 18af7e71f..2b5fafb40 100644 --- a/python/sglang/multimodal_gen/runtime/utils/logging_utils.py +++ b/python/sglang/multimodal_gen/runtime/utils/logging_utils.py @@ -68,21 +68,7 @@ DEFAULT_LOGGING_CONFIG = { } -class NewLineFormatter(logging.Formatter): - """Adds logging prefix to newlines to align multi-line messages.""" - - def __init__(self, fmt, datefmt=None, style="%"): - logging.Formatter.__init__(self, fmt, datefmt, style) - - def format(self, record): - msg = logging.Formatter.format(self, record) - if record.message != "": - parts = msg.split(record.message) - msg = msg.replace("\n", "\r\n" + parts[0]) - return msg - - -class ColoredFormatter(NewLineFormatter): +class ColoredFormatter(logging.Formatter): """A logging formatter that adds color to log levels.""" LEVEL_COLORS = { @@ -91,16 +77,13 @@ class ColoredFormatter(NewLineFormatter): } def format(self, record: logging.LogRecord) -> str: - """Adds color to the log level name.""" - original_levelname = record.levelname - color = self.LEVEL_COLORS.get(record.levelno) - if color: - record.levelname = f"{color}{original_levelname}{RESET}" + """Adds color to the log""" formatted_message = super().format(record) + color = self.LEVEL_COLORS.get(record.levelno) if color: - record.levelname = original_levelname + formatted_message = f"{color}{formatted_message}{RESET}" return formatted_message @@ -376,12 +359,15 @@ def set_uvicorn_logging_configs(): def configure_logger(server_args, prefix: str = ""): log_format = f"[%(asctime)s{prefix}] %(message)s" datefmt = "%m-%d %H:%M:%S" - logging.basicConfig( - level=getattr(logging, server_args.log_level.upper()), - format=log_format, - datefmt=datefmt, - force=True, - ) + + formatter = ColoredFormatter(log_format, datefmt=datefmt) + handler = logging.StreamHandler(sys.stdout) + handler.setFormatter(formatter) + + root = logging.getLogger() + root.handlers.clear() + root.addHandler(handler) + root.setLevel(getattr(logging, server_args.log_level.upper())) set_uvicorn_logging_configs()