[diffusion] log: fix wrong use of suppress_other_loggers (#15534)

This commit is contained in:
Mick
2025-12-20 23:43:55 +08:00
committed by GitHub
parent c6ca1b3afc
commit 41bd76e18b
7 changed files with 17 additions and 77 deletions

View File

@@ -33,10 +33,7 @@ from transformers import AutoConfig, PretrainedConfig
from transformers.models.auto.modeling_auto import MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
from sglang.multimodal_gen.runtime.loader.weight_utils import get_lock
from sglang.multimodal_gen.runtime.utils.logging_utils import (
init_logger,
suppress_other_loggers,
)
from sglang.multimodal_gen.runtime.utils.logging_utils import init_logger
logger = init_logger(__name__)
_CONFIG_REGISTRY: dict[str, type[PretrainedConfig]] = {
@@ -394,10 +391,7 @@ def maybe_download_model(
logger.info(
"Downloading model snapshot from HF Hub for %s...", model_name_or_path
)
with (
suppress_other_loggers(not_suppress_on_main_rank=False),
get_lock(model_name_or_path).acquire(poll_interval=2),
):
with get_lock(model_name_or_path).acquire(poll_interval=2):
local_path = snapshot_download(
repo_id=model_name_or_path,
ignore_patterns=["*.onnx", "*.msgpack"],
@@ -409,10 +403,7 @@ def maybe_download_model(
"Downloaded model at %s is incomplete, retrying with force_download=True",
local_path,
)
with (
get_lock(model_name_or_path).acquire(poll_interval=2),
suppress_other_loggers(not_suppress_on_main_rank=True),
):
with get_lock(model_name_or_path).acquire(poll_interval=2):
local_path = snapshot_download(
repo_id=model_name_or_path,
ignore_patterns=["*.onnx", "*.msgpack"],

View File

@@ -10,7 +10,6 @@ import logging
import os
import sys
import time
import warnings
from contextlib import contextmanager
from functools import lru_cache, partial
from logging import Logger
@@ -396,59 +395,20 @@ def suppress_loggers(loggers_to_suppress: list[str], level: int = logging.WARNIN
return original_levels
def global_suppress_loggers():
def globally_suppress_loggers():
# globally suppress some obsessive loggers
suppress_loggers(
[
"imageio",
"imageio_ffmpeg",
"PIL",
"PIL_Image",
"multipart",
"filelock",
"urllib3",
]
)
@contextmanager
def suppress_other_loggers(not_suppress_on_main_rank: bool = False):
"""
A context manager to temporarily suppress specified loggers.
Args:
not_suppress_on_main_rank (bool): If True, loggers will not be
suppressed on the main process (rank 0).
"""
# This is a global setting that we want to apply to all ranks
warnings.filterwarnings(
"ignore", category=UserWarning, message="The given NumPy array is not writable"
)
should_suppress = True
if not_suppress_on_main_rank:
if get_is_main_process():
should_suppress = False
loggers_to_suppress = [
"urllib3",
target_names = [
"imageio",
"imageio_ffmpeg",
"PIL",
"PIL_Image",
]
filelock_loggers = [
"python_multipart.multipart",
"filelock",
"urllib3",
]
original_levels = suppress_loggers(loggers_to_suppress)
original_levels.update(suppress_loggers(filelock_loggers, level=logging.ERROR))
try:
yield
finally:
if should_suppress:
for logger_name, level in original_levels.items():
logging.getLogger(logger_name).setLevel(level)
for name in target_names:
logging.getLogger(name).setLevel(logging.ERROR)
# source: https://github.com/vllm-project/vllm/blob/a11f4a81e027efd9ef783b943489c222950ac989/vllm/utils/system_utils.py#L60