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
f144ecfd
Commit
f144ecfd
authored
Nov 26, 2025
by
change
Browse files
Merge branch 'v0.5.4_dev_changhl' into 'v0.5.4_dev'
修复pp并行+chunked-prefill时kvcache memory leak See merge request
!1
parents
8e942125
1cc52a50
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
15 deletions
+32
-15
python/sglang/srt/disaggregation/prefill.py
python/sglang/srt/disaggregation/prefill.py
+32
-15
No files found.
python/sglang/srt/disaggregation/prefill.py
View file @
f144ecfd
...
...
@@ -580,23 +580,40 @@ class SchedulerDisaggregationPrefillMixin:
return
transferred_rids
# fix bug:merge pr:13144,修复了pp+chunked prefill的 kv_cache memory leak
def
process_prefill_chunk
(
self
:
Scheduler
)
->
None
:
if
self
.
last_batch
and
self
.
last_batch
.
forward_mode
.
is_extend
():
if
self
.
chunked_req
:
# Move the chunked request out of the batch so that we can merge
# only finished requests to running_batch.
self
.
last_batch
.
filter_batch
(
chunked_req_to_exclude
=
self
.
chunked_req
)
self
.
tree_cache
.
cache_unfinished_req
(
self
.
chunked_req
,
chunked
=
True
)
if
self
.
enable_overlap
:
# Delay KV transfer to process_batch_result_disagg_prefill when overlap is enabled to ensure results are resolved
self
.
chunked_req
.
tmp_end_idx
=
min
(
len
(
self
.
chunked_req
.
fill_ids
),
len
(
self
.
chunked_req
.
origin_input_ids
),
)
else
:
self
.
send_kv_chunk
(
self
.
chunked_req
)
# chunked request keeps its rid but will get a new req_pool_idx
chunked_req_to_exclude
=
set
()
if
self
.
chunked_req
:
chunked_req_to_exclude
.
add
(
self
.
chunked_req
)
self
.
tree_cache
.
cache_unfinished_req
(
self
.
chunked_req
,
chunked
=
True
)
if
self
.
enable_overlap
:
# Delay KV transfer to process_batch_result_disagg_prefill when overlap is enabled to ensure results are resolved
self
.
chunked_req
.
tmp_end_idx
=
min
(
len
(
self
.
chunked_req
.
fill_ids
),
len
(
self
.
chunked_req
.
origin_input_ids
),
)
else
:
self
.
send_kv_chunk
(
self
.
chunked_req
)
# chunked request keeps its rid but will get a new req_pool_idx
if
self
.
tp_worker
.
model_runner
.
mambaish_config
is
not
None
:
self
.
req_to_token_pool
.
free
(
self
.
chunked_req
.
req_pool_idx
,
free_mamba_cache
=
False
)
else
:
self
.
req_to_token_pool
.
free
(
self
.
chunked_req
.
req_pool_idx
)
self
.
running_batch
.
batch_is_full
=
False
if
self
.
last_batch
and
self
.
last_batch
.
forward_mode
.
is_extend
():
if
self
.
last_batch
.
chunked_req
:
# In the context pipeline parallelism, after the last chunk, the current microbatch still track outdated chunked_req.
# We need to discard it.
chunked_req_to_exclude
.
add
(
self
.
last_batch
.
chunked_req
)
last_bs
=
self
.
last_batch
.
batch_size
()
self
.
last_batch
.
filter_batch
(
chunked_req_to_exclude
=
list
(
chunked_req_to_exclude
)
)
if
self
.
last_batch
.
batch_size
()
<
last_bs
:
self
.
running_batch
.
batch_is_full
=
False
def
send_kv_chunk
(
...
...
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