[diffusion] UX: improve logging (#18122)
This commit is contained in:
@@ -162,6 +162,7 @@ class GPUWorker:
|
|||||||
|
|
||||||
start_time = time.monotonic()
|
start_time = time.monotonic()
|
||||||
|
|
||||||
|
req.log(server_args=self.server_args)
|
||||||
result = self.pipeline.forward(req, self.server_args)
|
result = self.pipeline.forward(req, self.server_args)
|
||||||
|
|
||||||
if isinstance(result, Req):
|
if isinstance(result, Req):
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ class DiffusersExecutionStage(PipelineStage):
|
|||||||
|
|
||||||
result = self._convert_to_tensor(data)
|
result = self._convert_to_tensor(data)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
logger.info(
|
logger.debug(
|
||||||
"Extracted output from '%s': shape=%s, dtype=%s",
|
"Extracted output from '%s': shape=%s, dtype=%s",
|
||||||
attr,
|
attr,
|
||||||
result.shape,
|
result.shape,
|
||||||
@@ -225,7 +225,7 @@ class DiffusersExecutionStage(PipelineStage):
|
|||||||
# Ensure correct shape for downstream processing
|
# Ensure correct shape for downstream processing
|
||||||
output = self._fix_output_shape(output)
|
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
|
return output
|
||||||
|
|
||||||
def _fix_output_shape(self, output: torch.Tensor) -> torch.Tensor:
|
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()
|
pipe_class_name = self.diffusers_pipe.__class__.__name__.lower()
|
||||||
video_indicators = ["video", "animat", "cogvideo", "wan", "hunyuan"]
|
video_indicators = ["video", "animat", "cogvideo", "wan", "hunyuan"]
|
||||||
self.is_video_pipeline = any(ind in pipe_class_name for ind in video_indicators)
|
self.is_video_pipeline = any(ind in pipe_class_name for ind in video_indicators)
|
||||||
logger.info(
|
logger.debug(
|
||||||
"Detected pipeline type: %s",
|
"Detected pipeline type: %s",
|
||||||
"video" if self.is_video_pipeline else "image",
|
"video" if self.is_video_pipeline else "image",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -343,8 +343,6 @@ class ComposedPipelineBase(ABC):
|
|||||||
"LoRA adapter is set, but not effective. Please make sure the LoRA weights are merged"
|
"LoRA adapter is set, but not effective. Please make sure the LoRA weights are merged"
|
||||||
)
|
)
|
||||||
|
|
||||||
batch.log(server_args=server_args)
|
|
||||||
|
|
||||||
# Execute each stage
|
# Execute each stage
|
||||||
if not batch.is_warmup and not batch.suppress_logs:
|
if not batch.is_warmup and not batch.suppress_logs:
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|||||||
@@ -48,10 +48,8 @@ class LatentPreparationStage(PipelineStage):
|
|||||||
The batch with prepared latent variables.
|
The batch with prepared latent variables.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
latent_num_frames = None
|
|
||||||
# Adjust video length based on VAE version if needed
|
# 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
|
batch_size = batch.batch_size
|
||||||
|
|
||||||
@@ -108,14 +106,10 @@ class LatentPreparationStage(PipelineStage):
|
|||||||
def adjust_video_length(self, batch: Req, server_args: ServerArgs) -> int:
|
def adjust_video_length(self, batch: Req, server_args: ServerArgs) -> int:
|
||||||
"""
|
"""
|
||||||
Adjust video length based on VAE version.
|
Adjust video length based on VAE version.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
The batch with adjusted video length.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
video_length = batch.num_frames
|
video_length = batch.num_frames
|
||||||
|
latent_num_frames = video_length
|
||||||
use_temporal_scaling_frames = (
|
use_temporal_scaling_frames = (
|
||||||
server_args.pipeline_config.vae_config.use_temporal_scaling_frames
|
server_args.pipeline_config.vae_config.use_temporal_scaling_frames
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -68,21 +68,7 @@ DEFAULT_LOGGING_CONFIG = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class NewLineFormatter(logging.Formatter):
|
class ColoredFormatter(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):
|
|
||||||
"""A logging formatter that adds color to log levels."""
|
"""A logging formatter that adds color to log levels."""
|
||||||
|
|
||||||
LEVEL_COLORS = {
|
LEVEL_COLORS = {
|
||||||
@@ -91,16 +77,13 @@ class ColoredFormatter(NewLineFormatter):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def format(self, record: logging.LogRecord) -> str:
|
def format(self, record: logging.LogRecord) -> str:
|
||||||
"""Adds color to the log level name."""
|
"""Adds color to the log"""
|
||||||
original_levelname = record.levelname
|
|
||||||
color = self.LEVEL_COLORS.get(record.levelno)
|
|
||||||
if color:
|
|
||||||
record.levelname = f"{color}{original_levelname}{RESET}"
|
|
||||||
|
|
||||||
formatted_message = super().format(record)
|
formatted_message = super().format(record)
|
||||||
|
|
||||||
|
color = self.LEVEL_COLORS.get(record.levelno)
|
||||||
if color:
|
if color:
|
||||||
record.levelname = original_levelname
|
formatted_message = f"{color}{formatted_message}{RESET}"
|
||||||
|
|
||||||
return formatted_message
|
return formatted_message
|
||||||
|
|
||||||
@@ -376,12 +359,15 @@ def set_uvicorn_logging_configs():
|
|||||||
def configure_logger(server_args, prefix: str = ""):
|
def configure_logger(server_args, prefix: str = ""):
|
||||||
log_format = f"[%(asctime)s{prefix}] %(message)s"
|
log_format = f"[%(asctime)s{prefix}] %(message)s"
|
||||||
datefmt = "%m-%d %H:%M:%S"
|
datefmt = "%m-%d %H:%M:%S"
|
||||||
logging.basicConfig(
|
|
||||||
level=getattr(logging, server_args.log_level.upper()),
|
formatter = ColoredFormatter(log_format, datefmt=datefmt)
|
||||||
format=log_format,
|
handler = logging.StreamHandler(sys.stdout)
|
||||||
datefmt=datefmt,
|
handler.setFormatter(formatter)
|
||||||
force=True,
|
|
||||||
)
|
root = logging.getLogger()
|
||||||
|
root.handlers.clear()
|
||||||
|
root.addHandler(handler)
|
||||||
|
root.setLevel(getattr(logging, server_args.log_level.upper()))
|
||||||
|
|
||||||
set_uvicorn_logging_configs()
|
set_uvicorn_logging_configs()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user