Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
change
sglang
Commits
0305c505
Unverified
Commit
0305c505
authored
Aug 03, 2025
by
Wenxuan Tan
Committed by
GitHub
Aug 03, 2025
Browse files
Reduce memory accumulation in long-running server (#8306)
Co-authored-by:
Liangsheng Yin
<
hnyls2002@gmail.com
>
parent
8675bdf2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
1 deletion
+13
-1
python/sglang/global_config.py
python/sglang/global_config.py
+5
-1
python/sglang/srt/managers/scheduler.py
python/sglang/srt/managers/scheduler.py
+8
-0
No files found.
python/sglang/global_config.py
View file @
0305c505
...
@@ -30,7 +30,11 @@ class GlobalConfig:
...
@@ -30,7 +30,11 @@ class GlobalConfig:
self
.
default_new_token_ratio_decay_steps
=
float
(
self
.
default_new_token_ratio_decay_steps
=
float
(
os
.
environ
.
get
(
"SGLANG_NEW_TOKEN_RATIO_DECAY_STEPS"
,
600
)
os
.
environ
.
get
(
"SGLANG_NEW_TOKEN_RATIO_DECAY_STEPS"
,
600
)
)
)
self
.
torch_empty_cache_interval
=
float
(
os
.
environ
.
get
(
"SGLANG_EMPTY_CACHE_INTERVAL"
,
-
1
)
# in seconds. Set if you observe high memory accumulation over a long serving period.
)
# Runtime constants: others
# Runtime constants: others
self
.
retract_decode_steps
=
20
self
.
retract_decode_steps
=
20
self
.
flashinfer_workspace_size
=
os
.
environ
.
get
(
self
.
flashinfer_workspace_size
=
os
.
environ
.
get
(
...
...
python/sglang/srt/managers/scheduler.py
View file @
0305c505
...
@@ -2362,11 +2362,19 @@ class IdleSleeper:
...
@@ -2362,11 +2362,19 @@ class IdleSleeper:
def
__init__
(
self
,
sockets
):
def
__init__
(
self
,
sockets
):
self
.
poller
=
zmq
.
Poller
()
self
.
poller
=
zmq
.
Poller
()
self
.
last_empty_time
=
time
.
time
()
for
s
in
sockets
:
for
s
in
sockets
:
self
.
poller
.
register
(
s
,
zmq
.
POLLIN
)
self
.
poller
.
register
(
s
,
zmq
.
POLLIN
)
def
maybe_sleep
(
self
):
def
maybe_sleep
(
self
):
self
.
poller
.
poll
(
1000
)
self
.
poller
.
poll
(
1000
)
if
(
global_config
.
torch_empty_cache_interval
>
0
and
time
.
time
()
-
self
.
last_empty_time
>
global_config
.
torch_empty_cache_interval
):
self
.
last_empty_time
=
time
.
time
()
torch
.
cuda
.
empty_cache
()
def
is_health_check_generate_req
(
recv_req
):
def
is_health_check_generate_req
(
recv_req
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment