Skip to content

feat: add round-robin scheduling for chunked PD prefill - #26

Merged
Zhangmj0621 merged 20 commits into
online_base_0914from
feat/chunked-prefill-round-robin-0908
Sep 17, 2026
Merged

Zhangmj0621 merged 20 commits into
online_base_0914from
feat/chunked-prefill-round-robin-0908

Conversation

@weiweisss

@weiweisss weiweisss commented Sep 11, 2026 •

Copy link
Copy Markdown

Summary

Long requests can occupy consecutive prefill chunks, delaying shorter requests. Add optional round-robin scheduling between chunks so other ready requests can make progress.

  • Enable with --enable-chunked-prefill-round-robin (disabled by default).
  • Keep unfinished prefills in a suspended queue and reuse existing continuation and KV release paths.
  • Reserve KV capacity for unfinished prefills when admitting new requests.
  • With overlap, defer cleanup and retries until pending results and source-buffer transfers have drained across the attention TP group.
  • Support DSPARK through its existing prefill and draft-KV paths.

Based on online_base_0914 (75a9980f84). The rebase preserves the base branch's arrival-token accounting on the retry path. Design documents are excluded.

Supported configurations

PD prefill with PP1, one attention TP group, FCFS without priority scheduling, fixed chunks, and an independent paged full-KV allocator. Both non-overlap and overlap scheduling are supported; overlap requires Mooncake or the fake transfer backend. Speculation is supported for DSPARK only. TP size and page size are not hardcoded.

Startup validation excludes LoRA, DLLM, PDMux, dynamic/mixed chunks, hybrid SWA, unified memory, and MLX overlap.

Validation

  • Consolidated new feature tests into test/manual/chunked_prefill/test_prefill_round_robin.py: 14 passing CPU checks covering FIFO rotation, a single unfinished chunk per batch, KV/row pressure, reservation accounting, disabled behavior, cancellation, deferred retry, and source-transfer release ordering.
  • These tests execute production method bodies with doubles for GPU/TP/transport operations; they do not replace GPU integration testing.
  • Python syntax, lint, formatting, and diff checks passed locally.
  • Before this rebase, the Kimi K3 TP8 deployment with overlap and DSPARK completed all 40 mixed-length requests; all shorter requests completed before the first 100k request. Six client-disconnect cases left survivor and probe requests successful. Load testing was also reported successful.
  • GPU regression testing of the rebased 0914 version remains pending. Client disconnect tests alone do not establish server-side resource reclamation.

Run the core checks with Python 3.10+:

python3 test/manual/chunked_prefill/test_prefill_round_robin.py

CI States

Latest PR Test (Base): ❌ Run #35104878866
Latest PR Test (Extra): ❌ Run #35104878395
Latest PR Test (AMD ROCm 10): ➖ No AMD PR run found for this commit.

enable_chunked_prefill_round_robin: A[
bool,
"Round-robin chunked prefill for non-overlap PD prefill (TP8, page size 64).",
] = False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it should be placed below chunked_prefill_size?

@@ -68,6 +68,7 @@ class SchedulerInvariantChecker:
# The chunked-prefill request parked between chunks is in neither batch;
# its uncached tokens must still be counted.
get_chunked_req: Callable = field(default=lambda: None)
get_rr_requests: Callable = field(default=lambda: ())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rr maybe means round_robin? Need better varaible name or left comments here.

Comment thread python/sglang/srt/managers/scheduler.py Outdated

supported = (
get_disagg().disaggregation_mode == "prefill"
and not self.enable_overlap

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P0] why not suppot enable overlap?It should be enable unless set --disable-overlap-scheduler, which shouldn't be set since it can introduce CPU overhead.

@Zhangmj0621 Zhangmj0621 left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation may have a better substitude.

if not self.enable_overlap:
if (
not self.enable_overlap
or self.enable_chunked_prefill_round_robin

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need this here? it makes the logic completly complex than it should be. it seems the whole diffs for source_transfers is caused by here.
Maybe can just change it back and only retry the not success bootstrap req like without round-robin prefill scheduling. So the code should be much clean.

@@ -1194,7 +1266,11 @@ def process_prefill_chunk(
elif self.has_bootstrapped_waiting_req():
# optimistic request yields to waiting requests
self.chunked_req = None
if not self.enable_overlap:
if not self.enable_overlap or (
self.enable_chunked_prefill_round_robin

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still wonder why make enable_chunked_prefill_round_robin to behave different from merely enable_overlap.

@@ -507,7 +510,7 @@ def set_buf(self, req: Req):
top_logprobs_len = len(req.logprob.output_top_logprobs_val[0])
max_top_logprobs_len = self.output_top_logprobs_val.shape[1]
if top_logprobs_len > max_top_logprobs_len:
raise RuntimeError(
raise InvalidDisaggregationMetadata(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this?

@@ -539,7 +542,7 @@ def set_buf(self, req: Req):
mask_len = len(sampling_mask)
max_mask_len = self.output_token_sampling_mask_idx.shape[1]
if mask_len > max_mask_len:
raise RuntimeError(
raise InvalidDisaggregationMetadata(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same. Not introduce new InvalidDisaggregationMetadata

@@ -333,7 +338,7 @@ def __init__(
hidden_size: int,
hidden_states_dtype: torch.dtype,
max_sampling_mask_tokens: int,
max_top_logprobs_num: int = 128,
max_top_logprobs_num: int = MAX_DISAGGREGATION_TOP_LOGPROBS,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need here. Just maintain 128 and the comment below.

@@ -563,6 +567,8 @@ def resolve_waiting_queue_bootstrap(self: Scheduler) -> None:
failed = set()
for req, poll in zip(candidates, polls):
if poll == KVPoll.Failed:
if not self.enable_overlap:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe need enable round robin prefill scheduling?

@weiweisss

weiweisss commented Sep 16, 2026 •

Copy link
Copy Markdown
Author

Under a mixed workload of approximately 8k-token requests at 3 QPS and 80k-token requests at 0.1 QPS, each generating 512 tokens, the round-robin run showed substantially lower TTFT than the baseline. The dashboard’s time-averaged p50, p90, and p99 TTFT values decreased from 8.79 s to 428 ms, 15.4 s to 756 ms, and 19.8 s to 1.16 s, respectively—approximately 95%, 95%, and 94% reductions. Average prefill queue depth also dropped from 6.44 to 0.067. These observations are consistent with reduced blocking of short requests by long prefills; attributing the full improvement to scheduling requires matching cache state, deployment settings, and measurement windows between runs.

round robin chunked prefill
image

baseline
image

@weiweisss
weiweisss force-pushed the feat/chunked-prefill-round-robin-0908 branch from 3afda06 to f208483 Compare September 16, 2026 07:47

@Zhangmj0621 Zhangmj0621 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now.

@Zhangmj0621
Zhangmj0621 merged commit fa5caa1 into online_base_0914 Sep 17, 2026
77 of 87 checks passed
Zhangmj0621 pushed a commit that referenced this pull request Oct 8, 2026
* feat: add round-robin scheduling for chunked PD prefill

* fix: relax round-robin TP and page size restrictions

* refactor: clarify round-robin names and group prefill options

* feat: support overlap and DSPARK in chunked prefill round robin

* test: consolidate core prefill round-robin regressions

* refactor: reuse native overlap prefill retry flow

* refactor: reuse Mooncake transfer drain accounting for prefill abort

* refactor: route round-robin client abort through prefill retirement

* refactor: restore native transfer handling for prefill round robin

* test: simplify prefill round-robin test helpers

* refactor: preserve native overlap bootstrap retry behavior

* fix: gate bootstrap detachment on prefill round robin

* fix: skip prefill sequence reset when round robin is disabled

* perf: batch queue removal for failed prefill bootstrap requests

* Revert "perf: batch queue removal for failed prefill bootstrap requests"

This reverts commit bcfddbfb9be1aa3ca2025722932c85f9f7ddc3ee.

* refactor: batch prefill ready queue removal

* fix: validate required prefill round robin configuration

* fix: handle prefill resume rejection, paused aborts and suspended timeouts

* fix: read resolved disaggregation config during prefill initialization

* fix: complete round robin abort tracing and cache cleanup

---------

Co-authored-by: yifei she <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants