Skip to content

[Feat] scheduler: Size pipeline-parallel prefill chunks by pending load - #48779

Closed
hnyls2002 wants to merge 7 commits into
mainfrom
lsyin/pp-chunk-by-pending
Closed

hnyls2002 wants to merge 7 commits into
mainfrom
lsyin/pp-chunk-by-pending

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Port of #48414

Takes the pipeline-parallel prefill chunk sizing from the Kimi-K3.1 Day-0 branch as a model-independent feature behind two new flags, both off by default, with its read-only prefix probe for the Python and the Rust tree cores.

Against the branch:

  • The sizing logic lives in scheduler_components/pp_chunk_sizer.py (PPChunkSizer) instead of Scheduler methods; PrefillAdder.grow_chunk_budget owns the budget change.
  • The load rule's last step reaches --chunked-prefill-size for any ratio of the two chunk sizes (the branch stopped at the largest power-of-two multiple of the small chunk), and neither rule exceeds the dynamic chunk size when --enable-dynamic-chunking is on.
  • peek_uncached_tokens limits the key the way admission does, so it agrees with admission when the page size is above 1.
  • A waiting request is probed again only after the prefix cache changed (prefix_cache_version, bumped on insert, eviction, load-back, prefetch, reset, and splits on multi-component caches).
  • The hybrid-cache, DFlash, CP, and stage-metric hunks that share files with this feature are left out.

Summary

A pipeline-parallel prefill batch with few uncached tokens (for example many requests with long cached prefixes) makes too few chunks to keep every stage busy.

  • --pp-min-chunked-prefill-size N: such a batch uses chunks of N tokens; the full --chunked-prefill-size is used when any pending request has at least that many uncached tokens.
  • --pp-chunk-overhead-tokens T (requires the first flag): the chunk is sized from the total pending uncached tokens U instead. Starting at N, it grows to the next size B (double, capped at the full chunk) while U * T >= (pp_size - 1) * C * B, and holds through short dips in load.
  • Waiting requests are probed through peek_prefix_len, which reads the prefix cache without changing it (no node splits, LRU, lock refs, or hit counts), on both the Python and the Rust tree cores.

Changes to existing code

  • Off unless --pp-min-chunked-prefill-size is set and --pp-size > 1; a warning says so when the flags are set but the feature cannot act (--pp-size 1, chunked prefill off, or a cache without the probe).
  • Startup rejects --pp-min-chunked-prefill-size < 1, --pp-chunk-overhead-tokens < 1, and the overhead flag without the min flag.
  • Req gains pp_uncached_hint and pp_uncached_hint_version, reset on retraction.
  • BasePrefixCache.peek_prefix_len and UnifiedTreeCoreInterface.peek_prefix_len default to None (no probe); BasePrefixCache.prefix_cache_version defaults to None (untracked). UnifiedRadixCache implements both.
  • UnifiedRadixCache bumps prefix_cache_version at its existing insert, eviction, load-back, prefetch, reset, and multi-component match funnels; nothing else in the cache changes.

Verification

  • Unit tests: registered/unit/managers/test_pp_chunk_by_pending.py (8), the probe and version tests in registered/unit/mem_cache/unified_radix_cache/test_unified_radix_cache_core.py; cargo test in rust/sglang-radix-tree (967 passed, incl. 2 probe tests).
  • Randomized differential checks: the extracted sizer against the branch's scheduler methods (3000 seeds; identical except the two caps above), and the version skip against probing every step (200 seeds x 400 steps x 2 pipeline sizes; identical chunks and hints, 21-39% fewer probes).
  • Every file under registered/unit/managers/, registered/unit/mem_cache/unified_radix_cache/, and registered/unit/server_args/ fails no test that passes on main (local macOS, CPU).
  • Not yet measured on GPUs: the end-to-end speedup.

CI States

Latest PR Test (Base): ❌ Run #42935552444
Latest PR Test (Extra): ❌ Run #42935552332
Latest PR Test (AMD ROCm 10): ❌ Run #42935552364

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@claude claude Bot 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.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@mintlify

mintlify Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
sglang-doc 🟢 Ready View Preview Nov 11, 2026, 12:56 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

# Conflicts:
#	python/sglang/srt/managers/scheduler.py
…estore arg validation; skip probes while the prefix cache is unchanged
# Conflicts:
#	python/sglang/srt/arg_groups/field_order.py
@hnyls2002
hnyls2002 requested a review from Jialin as a code owner November 11, 2026 00:43
@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_pp_chunk_by_pending.py test_unified_radix_cache_core.py registered/unit/server_args/test_server_args.py test_server_args_migration.py test_scheduler_held_row_admission.py test_scheduler_running_reqs.py test_prefill_adder.py test_schedule_policy.py

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (7 tests): ✅ View workflow run

cd test/ && python3 registered/unit/managers/test_pp_chunk_by_pending.py  # base-a
cd test/ && python3 registered/unit/server_args/test_server_args.py  # base-a
cd test/ && python3 registered/unit/test_server_args_migration.py  # base-a
cd test/ && python3 registered/unit/managers/test_scheduler_held_row_admission.py  # base-a
cd test/ && python3 registered/unit/managers/test_scheduler_running_reqs.py  # base-a
cd test/ && python3 registered/unit/managers/test_prefill_adder.py  # base-a
cd test/ && python3 registered/unit/managers/test_schedule_policy.py  # base-a

🚀 1-gpu-5090 (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/mem_cache/unified_radix_cache/test_unified_radix_cache_core.py  # base-b

@hnyls2002 hnyls2002 closed this Nov 11, 2026
@hnyls2002
hnyls2002 deleted the lsyin/pp-chunk-by-pending branch November 11, 2026 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation unified-radix-cache

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant