[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

@@ -1,7 +1,4 @@
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo
from sglang.multimodal_gen.runtime.utils.logging_utils import (
global_suppress_loggers,
suppress_loggers,
)
from sglang.multimodal_gen.runtime.utils.logging_utils import globally_suppress_loggers
global_suppress_loggers()
globally_suppress_loggers()

View File

@@ -13,11 +13,7 @@ from sglang.multimodal_gen.runtime.server_args import (
prepare_server_args,
set_global_server_args,
)
from sglang.multimodal_gen.runtime.utils.logging_utils import (
configure_logger,
logger,
suppress_other_loggers,
)
from sglang.multimodal_gen.runtime.utils.logging_utils import configure_logger, logger
from sglang.srt.utils import kill_process_tree
@@ -27,7 +23,6 @@ def launch_server(server_args: ServerArgs, launch_http_server: bool = True):
launch_http_server: False for offline local mode
"""
configure_logger(server_args)
suppress_other_loggers()
# Start a new server with multiple worker processes
logger.info("Starting server...")

View File

@@ -23,8 +23,8 @@ from sglang.multimodal_gen.runtime.server_args import PortArgs, ServerArgs
from sglang.multimodal_gen.runtime.utils.common import set_cuda_arch
from sglang.multimodal_gen.runtime.utils.logging_utils import (
configure_logger,
globally_suppress_loggers,
init_logger,
suppress_other_loggers,
)
from sglang.multimodal_gen.runtime.utils.perf_logger import (
PerformanceLogger,
@@ -174,7 +174,7 @@ def run_scheduler_process(
Ranks > 0 act as slaves, waiting for tasks from the master.
"""
configure_logger(server_args)
suppress_other_loggers()
globally_suppress_loggers()
set_cuda_arch()
port_args = PortArgs.from_server_args(server_args)

View File

@@ -15,8 +15,6 @@ import requests
import torch
from packaging import version
from sglang.multimodal_gen.runtime.utils.logging_utils import suppress_other_loggers
if version.parse(version.parse(PIL.__version__).base_version) >= version.parse("9.1.0"):
PIL_INTERPOLATION = {
"linear": PIL.Image.Resampling.BILINEAR,
@@ -110,8 +108,7 @@ def load_image(
"""
if isinstance(image, str):
if image.startswith("http://") or image.startswith("https://"):
with suppress_other_loggers(not_suppress_on_main_rank=True):
image = PIL.Image.open(requests.get(image, stream=True).raw)
image = PIL.Image.open(requests.get(image, stream=True).raw)
elif os.path.isfile(image):
image = PIL.Image.open(image)
else:

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

View File

@@ -23,7 +23,7 @@ from openai import Client, OpenAI
from sglang.multimodal_gen.benchmarks.compare_perf import calculate_upper_bound
from sglang.multimodal_gen.runtime.utils.common import is_hip, kill_process_tree
from sglang.multimodal_gen.runtime.utils.logging_utils import (
global_suppress_loggers,
globally_suppress_loggers,
init_logger,
)
from sglang.multimodal_gen.runtime.utils.perf_logger import RequestPerfRecord
@@ -43,7 +43,7 @@ from sglang.multimodal_gen.test.test_utils import (
logger = init_logger(__name__)
global_suppress_loggers()
globally_suppress_loggers()
def download_image_from_url(url: str) -> Path: