Add SGLANG_ENABLE_REQ_POOL_LEAK_STRICT_CHECK to bypass mem leak check (#13339)

This commit is contained in:
Zilin Zhu
2025-11-16 22:02:22 +08:00
committed by GitHub
parent 95f43669b5
commit 9edb0e0da3
3 changed files with 29 additions and 3 deletions

View File

@@ -136,6 +136,7 @@ class Envs:
SGLANG_LOG_GC = EnvBool(False)
SGLANG_LOG_FORWARD_ITERS = EnvBool(False)
SGLANG_DISABLE_REQUEST_LOGGING = EnvBool(False)
SGLANG_ENABLE_STRICT_MEM_CHECK_DURING_IDLE = EnvBool(True)
# Test & Debug
SGLANG_IS_IN_CI = EnvBool(False)

View File

@@ -7,10 +7,15 @@ import time
from typing import TYPE_CHECKING
from sglang.srt.disaggregation.utils import DisaggregationMode
from sglang.srt.environ import envs
from sglang.srt.managers.schedule_batch import ScheduleBatch
from sglang.srt.mem_cache.mamba_radix_cache import MambaRadixCache
from sglang.srt.mem_cache.swa_radix_cache import SWARadixCache
from sglang.srt.utils.common import disable_request_logging, pyspy_dump_schedulers
from sglang.srt.utils.common import (
disable_request_logging,
pyspy_dump_schedulers,
raise_error_or_warn,
)
if TYPE_CHECKING:
from sglang.srt.managers.scheduler import Scheduler
@@ -138,7 +143,12 @@ class SchedulerRuntimeCheckerMixin:
f"available_size={len(self.req_to_token_pool.free_slots)}, "
f"total_size={self.req_to_token_pool.size}\n"
)
raise ValueError(msg)
raise_error_or_warn(
self,
envs.SGLANG_ENABLE_STRICT_MEM_CHECK_DURING_IDLE,
"count_req_pool_leak_warnings",
msg,
)
def check_memory(self: Scheduler):
if self.is_hybrid:
@@ -150,7 +160,12 @@ class SchedulerRuntimeCheckerMixin:
if memory_leak:
msg = "token_to_kv_pool_allocator memory leak detected! " f"{token_msg}"
raise ValueError(msg)
raise_error_or_warn(
self,
envs.SGLANG_ENABLE_STRICT_MEM_CHECK_DURING_IDLE,
"count_memory_leak_warnings",
msg,
)
self._check_req_pool()

View File

@@ -3646,3 +3646,13 @@ def get_current_device_stream_fast():
if cached_device_index == -1:
cached_device_index = torch.get_device_module().current_device()
return torch.get_device_module().current_stream(cached_device_index)
def raise_error_or_warn(obj, strict, counter_name, message, log_interval=1000):
if strict:
raise ValueError(message)
else:
count = getattr(obj, counter_name, 0)
if count % log_interval == 0:
logger.warning(message)
setattr(obj, counter_name, count + 1)