Repository navigation
[None][perf] Attention DP: KV-balanced admission of generation-only requests - #21073
Conversation
…equests Attention-DP ranks step in lockstep, so a decode step waits for the slowest rank. On a disaggregated generation worker that is set by two maxima over the ranks: the most KV tokens on one rank and the most requests on one rank. The worker admitted queued requests in FIFO order and spread them with the request-count heap. ADPRouter now owns attention-DP admission (ADPRouter.pop_requests; the default stays FIFO, so the KV-cache-aware and conversation-aware routers are unchanged). DefaultADPRouter admits generation-only requests (no child requests, no strict attention_dp_rank) by planning admission and placement together over the first KV_BALANCE_WINDOW (32) queued requests (plan_kv_balanced_admission): - No placement raises the largest per-rank request count while another rank can take the request. - When the whole window fits in the free slots, requests go largest first, each to the rank that raises neither the request-count nor the KV maximum and, among those, to the rank it leaves closest below the KV maximum (best fit), so the lightest ranks stay free for long requests. - Otherwise each slot takes the (request, rank) pair that brings the rank closest to the mean load once all free slots hold an average request. - A request passed over in KV_BALANCE_MAX_SKIPPED_ROUNDS (64) admitting rounds while in the window is admitted next. The queue bounds the reordering through WaitingQueue.admission_groups: the FCFS queue is one group; the priority queue has one group per priority, so a lower-priority request is never admitted while a higher-priority one waits; GEN admission ordering has one group per request, so its order is kept and only the rank is chosen. A single-rank group, warmup and the disaggregated-benchmark fill phase admit in queue order (in the fill phase every request must fit at once and none leaves, so placement by KV could strand the last ones; GB300 dep16 gen-only failed with "Insufficient KV cache for gen-only benchmark mode" without this). The window is read with WaitingQueue.peek_requests(k) (deque slice for FCFS, heapq.nsmallest for the priority queue, the admission order for the GEN admission queue), so the priority heap is never sorted as a whole, and a round without capacity does not look at the queue. Admission pops the window, puts the other requests back in queue order and reports the admitted ones through mark_admitted, as get_from_waiting_queue does. route_requests places the requests where the plan put them; generation-only requests that did not come through pop_requests keep the request-count heap. Evidence. Step time on the K3 dep16 b16 mtp5 GEN worker, fitted over 31k iterations of ten c600 runs (per-rank numGenKvTokens / numGenRequests from the ADP iteration stats, per-run intercepts): 21.6 ms + 3.48 ms per 1M KV tokens on the max-KV rank + 0.535 ms per request on the max-count rank (b24 c850: 3.26 / 0.70). A replay of the real request traces of those runs with this model reproduces the measured imbalance (KV max/mean 1.23 vs 1.26 at c600, 1.076 vs 1.073 at b24 c850) and the +4.1% tok/s/user the TRTLLM_ADP_KV_BALANCE prototype measured over FIFO on Rubin dep16 b8 mtp7 c383 (92.0 -> 95.79). Simulated mean step time, 3 seeds, main vs this change: c600 39.11 -> 38.60 ms (-1.3%), 0.8x load 34.44 -> 34.12 (-0.9%), 1.15x load 42.98 -> 40.73 (-5.2%), b8 near saturation 43.69 -> 40.40 (-7.5%), b24 saturated 53.40 -> 51.38 (-3.8%). Tests: tests/unittest/_torch/executor/test_adp_router.py (planner rules, admission groups, forced requests, window bound, single rank, priority order, GEN admission order and report, queue order after admission, no queue scan without capacity, no full sort of a large priority queue, routing by the plan, FIFO fallbacks, a gen-only trickle fill keeping per-rank request counts within one); peek_requests and admission_groups tests in test_waiting_queue.py and test_gen_admission_queue.py; test_benchmark_disagg.py checks that the fill phase and warmup admit in FIFO order. Signed-off-by: Lanyu Liao <[email protected]>
Shorter docstrings and comments; the planner tests become one parametrized table and overlapping router tests are merged (FIFO fallbacks, heap routing). Behavior is unchanged. Signed-off-by: Lanyu Liao <[email protected]>
…flag KV-balanced admission is now off by default. Enable it with attention_dp_config.enable_kv_balanced_admission (prototype). ADPRouter.create passes the flag to DefaultADPRouter; with the flag off, pop_requests admits in queue order, as on main. Also adds the field to the LLM-args golden manifest and the trtllm-serve config schemas. Signed-off-by: Lanyu Liao <[email protected]>
…explicitly ADPRouter.pop_requests now returns the admitted requests together with the ranks it planned for them (request id -> rank), and the executor passes that plan to route_requests. DefaultADPRouter no longer keeps the plan in an attribute between the two calls. Routers that plan no ranks return an empty plan and ignore it in route_requests. Signed-off-by: Lanyu Liao <[email protected]>
…ether Three changes to plan_kv_balanced_admission and DefaultADPRouter.pop_requests: - Admission groups only pick which requests are admitted. Requests of whole groups are placed together, largest first: best fit when the whole window is admitted, otherwise on the least-loaded rank. Placing them group by group in queue order made GEN admission ordering (one group per request) slower than FIFO admission once GEN saturates. - The request-count limit covers the whole round: a rank may take up to max(largest count, ceil((requests + admitted this round) / ranks)). With one admission per round this is the previous rule; for a burst it no longer forces ranks to fill layer by layer. - When there are more free slots than KV_BALANCE_WINDOW, the window grows to everything that fits, so a burst is admitted in one iteration. Signed-off-by: Lanyu Liao <[email protected]>
Conflict in adp_router.py: main added ADPRouter._use_max_load_across_cp (helix CP) right where this branch added ADPRouter.pop_requests; both are kept. Main's other changes in the same files (helix CP fallback for KV-cache-aware routing, uncached-prefill estimate, merge_requests is_disagg) merged cleanly and do not interact with the admission plan. Signed-off-by: Lanyu Liao <[email protected]>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Configuration and queue inspection tensorrt_llm/llmapi/llm_args.py, tensorrt_llm/schemas/*, tensorrt_llm/usage/llm_args_golden_manifest.json, tensorrt_llm/_torch/pyexecutor/scheduler/{waiting_queue.py,gen_admission_queue.py}, tests/unittest/_torch/executor/test_{waiting_queue,gen_admission_queue}.py |
Adds the default-disabled enable_kv_balanced_admission option and records it in both serving schemas and the usage manifest. Queue implementations expose candidate peeking and admission groups without removing requests. |
Router admission planning and placement tensorrt_llm/_torch/pyexecutor/scheduler/adp_router.py, tests/unittest/_torch/executor/test_adp_router.py |
The default router can plan admission and rank placement for eligible generation-only requests within a 32-request window. It observes capacity, request counts, KV load, admission groups, and skipped-round aging. Other cases use FIFO admission; routers that do not plan placement accept but ignore the optional placement argument. |
Executor integration and validation tensorrt_llm/_torch/pyexecutor/py_executor.py, tests/unittest/_torch/disaggregation/test_benchmark_disagg.py, tests/unittest/_torch/executor/test_{multimodal_scheduler,py_executor}.py |
The executor passes gathered rank states to admission and forwards the returned placement map to routing. It disables KV balancing during warmup and benchmark-disaggregation fill. Tests now check the router admission cap, balancing flag, and updated return shape. |
Priority:
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Feature
Sequence Diagram(s)
sequenceDiagram
participant PyExecutor
participant DefaultADPRouter
participant WaitingQueue
participant AdmissionPlanner
PyExecutor->>DefaultADPRouter: pop_requests with rank states and admission cap
DefaultADPRouter->>WaitingQueue: peek candidate window
DefaultADPRouter->>AdmissionPlanner: candidate and rank load data
AdmissionPlanner-->>DefaultADPRouter: admitted requests and rank placements
DefaultADPRouter-->>PyExecutor: requests and placement map
PyExecutor->>DefaultADPRouter: route_requests with placement map
DefaultADPRouter-->>PyExecutor: per-rank request assignments
Merge Risk: 
Minimal · up to d471f
-
No actionable merge-blocking issue was established; the change is mergeable after normal validation.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The pull request provides a detailed Description and Test Coverage section. It explains the motivation, implementation, configuration, fallbacks, testing, measured results, and known pending items. The PR Checklist section and its final confirmation checkbox are not included, but the description addresses most checklist topics and identifies pending telemetry/privacy approval and GPU A/B testing.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 34.25% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 73 functions across 11 files. (3 skipped: 3 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches: 💡 1
-
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
|
/bot run --disable-fail-fast |
|
PR_Github #80853 [ run ] triggered by Bot. Commit: |
|
/bot run --disable-fail-fast |
|
PR_Github #80857 [ run ] triggered by Bot. Commit: |
|
PR_Github #80853 [ run ] completed with state |
|
PR_Github #80857 [ run ] completed with state
|
Mgluhovskoi
left a comment
There was a problem hiding this comment.
LGTM from a telemetry POV.
|
/bot run --disable-fail-fast |
|
PR_Github #81025 [ run ] triggered by Bot. Commit: |
|
PR_Github #81025 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #81149 [ run ] triggered by Bot. Commit: |
|
PR_Github #81149 [ run ] completed with state |
Description
Attention-DP ranks step in lockstep, so a decode step waits for the slowest rank. On a disaggregated generation worker the slowest rank is set by two maxima: the most KV tokens on one rank, and the most requests on one rank. Today the worker admits queued requests in FIFO order and spreads them with the request-count heap, without regard to the KV each rank already holds.
This PR adds KV-balanced admission of generation-only requests to
DefaultADPRouter. It is off by default; turn it on with a newAttentionDpConfigfield (statusprototype):ADPRouternow owns attention-DP admission:pop_requestsreturns the requests to admit together with the rank planned for each, and the executor passes that plan toroute_requests. The baseADPRouter.pop_requestsstays FIFO and plans no ranks, so with the flag off, and for the KV-cache-aware and conversation-aware routers, admission and routing are the same as on main. With the flag on,DefaultADPRouteradmits generation-only requests (no child requests, no strictattention_dp_rank) by planning admission and placement together (plan_kv_balanced_admission) over the first 32 queued requests, or over all that fit when there are more free slots:Queue order is respected through
WaitingQueue.admission_groups.PRIORITYTLLM_GEN_ADMISSION_TTFT_PERCENTILE)Admission also falls back to queue order:
Cost of the window
WaitingQueue.peek_requests(k): a deque slice for FCFS,heapq.nsmallestfor the priority queue, and the admission order for the GEN admission queue. The priority heap is never sorted as a whole, and a round without capacity does not touch the queue.mark_admitted, asget_from_waiting_queuedoes.Relation to #20938. This is the generation-side ADP admission part of #20938, ported to main as a standalone change, with four differences:
ceil((requests + 1) / ranks)and fills the least-loaded rank. That blocks ranks holding little KV but more than an even share of requests, so the KV maximum stays high when GEN is not saturated. This PR replaces it with the rule above.PRIORITYpolicy and GEN admission ordering keep their order through admission groups (open review comment on [None][perf] Serving runtime: disagg/KV-transfer/ADP fixes, KV cache manager V2 prefix wait, ConversationRouter prefix placement, KV-balanced ADP admission #20938).DefaultADPRouter; here it is behindattention_dp_config.enable_kv_balanced_admission, off by default.The two earlier review points on #20938 (bounded window read, scope of the 64-round bound) are already part of the ported code.
Evidence (measured data + simulation; no GPU A/B of this PR yet)
Step-time model. I fit 31k iterations of ten Kimi-K3 dep16 b16 MTP5 c600 runs (Rubin), using the per-rank
numGenKvTokens/numGenRequestsfrom the ADP iteration stats with per-run intercepts:How unbalanced the real runs were. At c600, GEN is mostly not saturated (median 201 of 256 slots decoding) and KV max/mean is 1.26. Saturated at b24 c850, KV max/mean is 1.07.
Simulation. A replay of the real request traces of those runs (GEN arrival time, ISL, OSL from the aiperf exports) with the fitted model:
TRTLLM_ADP_KV_BALANCEprototype from [None][perf] Serving runtime: disagg/KV-transfer/ADP fixes, KV cache manager V2 prefix wait, ConversationRouter prefix placement, KV-balanced ADP admission #20938 measured over FIFO on Rubin dep16 b8 MTP7 c383 (simulated −4.6% step time).Mean step time, 3 seeds:
GEN admission ordering. With one admission group per request (approximated in the replay by GEN arrival order), the planner only chooses ranks: −1.5%, −0.9%, −0.1%, −1.6% and −0.1% vs main in the five scenarios. It cannot pick requests, which is where most of the saturated gain comes from. Placing those requests one by one in queue order, as an earlier revision of this PR did, was 2.2–3.3% slower than main once GEN saturated.
Bursts. In 30 random bursts of 50–150 requests into 16 ranks × 16 slots (empty or partly loaded), everything is admitted in one iteration, and KV max/mean right after admission is at most 0.05 above main's. Per-window planning with a strict count rule took 2–5 iterations and was 0.17–0.58 worse.
Caveats
Test Coverage
tests/unittest/_torch/executor/test_adp_router.py:plan_kv_balanced_admission: request-count rule (including a burst round), best fit, largest first, forced, admission groups, requests of several groups placed together, budget;ADPRouter.createreads it; off keeps FIFO), aging, window bound, FIFO fallbacks (KV balancing off, a non-generation request in the window, single rank), routing by the plan, priority order and displacement, GEN admission order and report, queue order after admission, no queue access without capacity, no full sort of a large priority queue, equal priorities admitting like FCFS, a burst admitted in one round, gen-only trickle fill keeping the largest request count at the fair share.test_waiting_queue.py,test_gen_admission_queue.py:peek_requestsandadmission_groups.tests/unittest/_torch/disaggregation/test_benchmark_disagg.py: warmup and the fill phase admit in FIFO order.test_multimodal_scheduler.py,test_py_executor.py: follow_pop_from_waiting_queuenow returning the plan.Status
_pop_from_waiting_queueand_fetch_new_requests, extracted withast) was run on a stub executor with the real router and queues: with the flag on, the planned rank gets the request; with it off, admission is FIFO.pre-commitpasses.test_adp_router.py,test_waiting_queue.py,test_gen_admission_queue.py,test_benchmark_disagg.py,test_multimodal_scheduler.py,test_py_executor.py,test_trtllm_serve_config_schemas.py,test_llmapi_config_telemetry_docs.py,api_stability/test_llm_api.pyandllmapi/test_llm_args.py.tensorrt_llm/usage/llm_args_golden_manifest.jsonand the twotrtllm-serveconfig schemas by hand, with the same serialization as their generators;test_build_capture_manifest_matches_committed_goldenandtest_checked_in_schemas_are_currentpass.AttentionDpConfigfield needs telemetry/privacy CODEOWNER approval.