[Misc] Suppress log outputs when constructing the default vllm config. (#29291)

Signed-off-by: wang.yuqi <yuqi.wang@daocloud.io>
Signed-off-by: wang.yuqi <noooop@126.com>
Signed-off-by: Cyrus Leung <cyrus.tl.leung@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Cyrus Leung <cyrus.tl.leung@gmail.com>
Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
wang.yuqi
2025-11-25 19:00:44 +08:00
committed by GitHub
parent 7a80b01889
commit de6889946b
2 changed files with 18 additions and 7 deletions

View File

@@ -77,7 +77,7 @@ from vllm.config.observability import DetailedTraceModules
from vllm.config.parallel import DistributedExecutorBackend, ExpertPlacementStrategy from vllm.config.parallel import DistributedExecutorBackend, ExpertPlacementStrategy
from vllm.config.scheduler import SchedulerPolicy from vllm.config.scheduler import SchedulerPolicy
from vllm.config.utils import get_field from vllm.config.utils import get_field
from vllm.logger import init_logger from vllm.logger import init_logger, suppress_logging
from vllm.platforms import CpuArchEnum, current_platform from vllm.platforms import CpuArchEnum, current_platform
from vllm.plugins import load_general_plugins from vllm.plugins import load_general_plugins
from vllm.ray.lazy_utils import is_in_ray_actor, is_ray_initialized from vllm.ray.lazy_utils import is_in_ray_actor, is_ray_initialized
@@ -247,11 +247,13 @@ def _compute_kwargs(cls: ConfigType) -> dict[str, dict[str, Any]]:
default = field.default default = field.default
# Handle pydantic.Field defaults # Handle pydantic.Field defaults
if isinstance(default, FieldInfo): if isinstance(default, FieldInfo):
default = ( if default.default_factory is None:
default.default default = default.default
if default.default_factory is None else:
else default.default_factory() # VllmConfig's Fields have default_factory set to config classes.
) # These could emit logs on init, which would be confusing.
with suppress_logging():
default = default.default_factory()
elif field.default_factory is not MISSING: elif field.default_factory is not MISSING:
default = field.default_factory() default = field.default_factory()

View File

@@ -7,7 +7,8 @@ import json
import logging import logging
import os import os
import sys import sys
from collections.abc import Hashable from collections.abc import Generator, Hashable
from contextlib import contextmanager
from functools import lru_cache, partial from functools import lru_cache, partial
from logging import Logger from logging import Logger
from logging.config import dictConfig from logging.config import dictConfig
@@ -212,6 +213,14 @@ def init_logger(name: str) -> _VllmLogger:
return cast(_VllmLogger, logger) return cast(_VllmLogger, logger)
@contextmanager
def suppress_logging(level: int = logging.INFO) -> Generator[None, Any, None]:
current_level = logging.root.manager.disable
logging.disable(level)
yield
logging.disable(current_level)
# The root logger is initialized when the module is imported. # The root logger is initialized when the module is imported.
# This is thread-safe as the module is only imported once, # This is thread-safe as the module is only imported once,
# guaranteed by the Python GIL. # guaranteed by the Python GIL.