Clean up noisy startup log messages and refactor loader.py (#18531)

This commit is contained in:
Lianmin Zheng
2026-02-11 16:12:57 -08:00
committed by GitHub
parent ded068a76e
commit 5875ef0a34
7 changed files with 60 additions and 43 deletions

View File

@@ -6,6 +6,9 @@ import sys
from sglang.srt.server_args import prepare_server_args
from sglang.srt.utils import kill_process_tree
from sglang.srt.utils.common import suppress_noisy_warnings
suppress_noisy_warnings()
def run_server(server_args):

View File

@@ -87,6 +87,8 @@ def _extract_max_dynamic_patch(request: ChatCompletionRequest):
class OpenAIServingChat(OpenAIServingBase):
"""Handler for /v1/chat/completions requests"""
_default_sampling_params_logged = False
def __init__(
self,
tokenizer_manager: TokenizerManager,
@@ -101,10 +103,14 @@ class OpenAIServingChat(OpenAIServingBase):
self.default_sampling_params = (
self.tokenizer_manager.model_config.get_default_sampling_params()
)
if self.default_sampling_params:
if (
self.default_sampling_params
and not OpenAIServingChat._default_sampling_params_logged
):
logger.info(
f"Using default chat sampling params from model generation config: {self.default_sampling_params}",
)
OpenAIServingChat._default_sampling_params_logged = True
# Check if the model is a GPT-OSS model
self.is_gpt_oss = (

View File

@@ -10,7 +10,6 @@ from sglang.srt.layers.dp_attention import (
get_attention_dp_size,
is_dp_attention_enabled,
)
from sglang.srt.utils import log_info_on_rank0
if TYPE_CHECKING:
from sglang.srt.server_args import ServerArgs
@@ -189,10 +188,6 @@ def get_moe_a2a_backend() -> MoeA2ABackend:
def get_moe_runner_backend() -> MoeRunnerBackend:
global MOE_RUNNER_BACKEND
if MOE_RUNNER_BACKEND is None:
log_info_on_rank0(
logger,
"MOE_RUNNER_BACKEND is not initialized, the backend will be automatically selected",
)
MOE_RUNNER_BACKEND = MoeRunnerBackend.AUTO
return MOE_RUNNER_BACKEND

View File

@@ -384,8 +384,6 @@ class MambaRadixCache(BasePrefixCache):
assert (
self.page_size == 1
), f"Page size must be 1 for MambaRadixCache v1, got {self.page_size}"
else:
logger.info(f"Mamba extra_buffer is enabled.")
if self.token_to_kv_pool_allocator:
self.device = self.token_to_kv_pool_allocator.device

View File

@@ -1684,8 +1684,6 @@ class ModelRunner(ModelRunnerKVCacheMixin):
def init_attention_backend(self):
"""Init attention kernel backend."""
tic = time.perf_counter()
logger.info("Init attention backend begin.")
if self.server_args.enable_pdmux:
self.attn_backend = self._get_attention_backend(init_new_workspace=True)
self.decode_attn_backend_group = []
@@ -1696,9 +1694,6 @@ class ModelRunner(ModelRunnerKVCacheMixin):
self.attn_backend = TboAttnBackend.init_new(self._get_attention_backend)
else:
self.attn_backend = self._get_attention_backend()
logger.info(
f"Init attention backend end. elapsed={time.perf_counter() - tic:.2f} s"
)
def _get_attention_backend(self, init_new_workspace: bool = False):
"""Init attention kernel backend."""

View File

@@ -12,6 +12,7 @@ import json
import logging
import math
import os
import re
import socket
import threading
import time
@@ -304,6 +305,8 @@ class DefaultModelLoader(BaseModelLoader):
# default number of thread when enable multithread weight loading
DEFAULT_NUM_THREADS = 8
_MTP_PATTERN = re.compile(r"model\.mtp\.layers\.(\d+)\.")
@dataclasses.dataclass
class Source:
"""A source for weights."""
@@ -351,11 +354,11 @@ class DefaultModelLoader(BaseModelLoader):
def _maybe_download_from_modelscope(
self, model: str, revision: Optional[str]
) -> Optional[str]:
) -> str:
"""Download model from ModelScope hub if SGLANG_USE_MODELSCOPE is True.
Returns the path to the downloaded model, or None if the model is not
downloaded from ModelScope."""
Returns the path to the downloaded model, or the original model path if
not downloaded from ModelScope."""
if get_bool_env_var("SGLANG_USE_MODELSCOPE"):
# download model from ModelScope hub,
# lazy import so that modelscope is not required for normal use.
@@ -373,7 +376,7 @@ class DefaultModelLoader(BaseModelLoader):
else:
model_path = model
return model_path
return None
return model
def _prepare_weights(
self, model_name_or_path: str, revision: Optional[str], fall_back_to_pt: bool
@@ -381,9 +384,8 @@ class DefaultModelLoader(BaseModelLoader):
"""Prepare weights for the model.
If the model is not local, it will be downloaded."""
model_name_or_path = (
self._maybe_download_from_modelscope(model_name_or_path, revision)
or model_name_or_path
model_name_or_path = self._maybe_download_from_modelscope(
model_name_or_path, revision
)
is_local = os.path.isdir(model_name_or_path)
@@ -474,6 +476,7 @@ class DefaultModelLoader(BaseModelLoader):
) -> Generator[Tuple[str, torch.Tensor], None, None]:
"""Get an iterator for the model weights based on the load format."""
extra_config = self.load_config.model_loader_extra_config
use_multithread = extra_config.get("enable_multithread_load", False)
hf_folder, hf_weights_files, use_safetensors = self._prepare_weights(
source.model_or_path, source.revision, source.fall_back_to_pt
)
@@ -504,7 +507,7 @@ class DefaultModelLoader(BaseModelLoader):
weights_iterator = fastsafetensors_weights_iterator(
hf_weights_files,
)
elif extra_config.get("enable_multithread_load"):
elif use_multithread:
weights_iterator = multi_thread_safetensors_weights_iterator(
hf_weights_files,
max_workers=extra_config.get(
@@ -518,7 +521,7 @@ class DefaultModelLoader(BaseModelLoader):
)
else:
if extra_config.get("enable_multithread_load"):
if use_multithread:
weights_iterator = multi_thread_pt_weights_iterator(
hf_weights_files,
max_workers=extra_config.get(
@@ -529,28 +532,34 @@ class DefaultModelLoader(BaseModelLoader):
weights_iterator = pt_weights_iterator(hf_weights_files)
if self.load_config.draft_model_idx is not None:
import re
pattern = r"model.mtp.layers.(\d+)."
filtered_weights = []
for name, tensor in weights_iterator:
group = re.match(pattern, name)
if group is not None:
idx = int(group.group(1))
if idx != self.load_config.draft_model_idx:
continue
new_name = name.replace(group.group(), "model.mtp.layers.0.")
else:
new_name = name
filtered_weights.append((source.prefix + new_name, tensor))
return tuple(filtered_weights)
return self._filter_mtp_weights(
weights_iterator, source.prefix, self.load_config.draft_model_idx
)
if self.counter_before_loading_weights == 0.0:
logger.info("Beginning to load weights")
self.counter_before_loading_weights = time.perf_counter()
# Apply the prefix.
return ((source.prefix + name, tensor) for (name, tensor) in weights_iterator)
@classmethod
def _filter_mtp_weights(
cls, weights_iterator, prefix: str, draft_model_idx: int
) -> Tuple[Tuple[str, torch.Tensor], ...]:
"""Filter MTP (Multi-Token Prediction) weights to keep only the
specified draft model layer and remap it to layer 0."""
filtered_weights = []
for name, tensor in weights_iterator:
match = cls._MTP_PATTERN.match(name)
if match is not None:
idx = int(match.group(1))
if idx != draft_model_idx:
continue
new_name = name.replace(match.group(), "model.mtp.layers.0.")
else:
new_name = name
filtered_weights.append((prefix + new_name, tensor))
return tuple(filtered_weights)
def _get_all_weights(
self,
model_config: ModelConfig,
@@ -670,10 +679,6 @@ class DefaultModelLoader(BaseModelLoader):
)
self.counter_after_loading_weights = time.perf_counter()
logger.info(
"Loading weights took %.2f seconds",
self.counter_after_loading_weights - self.counter_before_loading_weights,
)
return model.eval()
@staticmethod

View File

@@ -1057,10 +1057,25 @@ def encode_video(video_path, frame_count_limit=None):
return frames
def suppress_other_loggers():
def suppress_noisy_warnings():
"""Suppress known noisy warnings from third-party libraries."""
warnings.filterwarnings(
"ignore", category=UserWarning, message="The given NumPy array is not writable"
)
warnings.filterwarnings(
"ignore",
message="The cuda.cudart module is deprecated",
category=FutureWarning,
)
warnings.filterwarnings(
"ignore",
message="The cuda.nvrtc module is deprecated",
category=FutureWarning,
)
def suppress_other_loggers():
suppress_noisy_warnings()
try:
from vllm.logger import logger as vllm_default_logger