-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[None][fix] Agree the KVCacheManagerV2 rebalance trigger across TP ranks #17391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thorjohnsen
wants to merge
6
commits into
NVIDIA:main
Choose a base branch
from
thorjohnsen:thor/kvcmv2-tp-rebalance-agreement
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,800
−12
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9236b8f
[None][fix] Agree the KVCacheManagerV2 rebalance trigger across TP ranks
thorjohnsen f688ad7
[None][fix] Extend the rebalance trigger agreement to context paralle…
thorjohnsen 29417dc
[None][fix] Address review on the rebalance trigger agreement
thorjohnsen 1f1cb52
[None][fix] Keep the CP broadcast under attention DP
thorjohnsen ef96782
[None][feat] Extend the KVCacheManagerV2 rebalance to pipeline parall…
thorjohnsen c21efaa
[None][test] Unit-test the pipeline-parallel rebalance drain wiring
thorjohnsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This early return skips the CP broadcast too, but the scheduler propagation cited as the precedent gates only the TP hop on attention DP —
cp_broadcastat[py_executor.py:2475](https://github.com/NVIDIA/TensorRT-LLM/pull/17391/files#diff-f0b4c3c02708916fd189f863c48b982a55f34ae94996089b23aa0a6f0571fe19R2475)runs unconditionally, ADP or not. That's because ADP gives each TP rank its own request stream, but CP ranks within a DP group still split the same requests and must admit them together. Under ADP + CP (nothing inMappingorllm_argsrejects the combination), CP ranks would decide the rebalance trigger independently here — the same divergence class this PR fixes.Suggested structure, mirroring
[py_executor.py:2471](https://github.com/NVIDIA/TensorRT-LLM/pull/17391/files#diff-f0b4c3c02708916fd189f863c48b982a55f34ae94996089b23aa0a6f0571fe19R2471)-2478:If ADP + CP + rebalance is instead considered unreachable today, a comment saying so (and why) would do — but
test_attention_dp_skips_cp_broadcast_tooandtest_attention_dp_ranks_decide_independentlycurrently bake the skip in as intended behavior, so either the code or the tests should change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch — you're right, and I had the precedent backwards. Fixed in ba6fff1.
I cited the scheduler's
tp_broadcastas justification for excluding ADP outright and missed that thecp_broadcastimmediately below it (py_executor.py:2474) runs unconditionally. That asymmetry is the whole answer, and the reasoning you give for it is the same one this PR already makes for pure CP — I just failed to carry it into the ADP branch.Confirmed reachable: nothing in
MappingorLlmArgsrejectsenable_attention_dpwithcp_size > 1.Mapping.__init__'s only ADP-related assert isenable_lm_head_tp_in_adp requires enable_attention_dp(mapping.py:190), anddp_size = tp_size if enable_attention_dp else 1(:296) makes CP orthogonal to the DP dimension rather than folded into it.Took your structure verbatim:
The CP-then-TP order differs from the scheduler's TP-then-CP, but the two agree in both regimes: without ADP, TP-then-CP gives
rank(t,c) <- V(0,c) <- V(0,0)and CP-then-TP givesrank(t,c) <- V(t,0) <- V(0,0); with the TP hop suppressed both reduce torank(t,c) <- V(t,0), i.e. each replica decides on its owncp_rank-0 reading.On tests — you were right that they baked the skip in, so I inverted rather than extended:
test_attention_dp_skips_cp_broadcast_too->test_attention_dp_still_broadcasts_over_cp(asserts the CP result overrides the local reading and thattp_broadcaststays uncalled).test_attention_dp_without_cp_touches_no_collectiveso the genuine no-collective case keeps coverage.test_attention_dp_agrees_over_cp_but_not_tp(world_size=4, cp_size=2, tp_size=2). Flags are[True, False, False, True]so it fails in both directions: ranks 1 and 3 are overridden by their CP root (proving the CP hop ran) while the two replicas end on different answers (proving the TP hop did not).Mutation-verified — restoring the early return gives:
which is exactly the raw local flags, i.e. no broadcast at all. The pure-TP, pure-CP and CP-x-TP cases all stay green under that mutation, which is your point that nothing covered this topology.
One note for precision: the propagation you cite lives in
_pp_schedule_and_propagate, the PP scheduling path, and rebalance is gated off forpp_size > 1. So it's a semantic precedent rather than an operative one — in the non-PP loops_schedule()runs per rank with no broadcast at all, which is this PR's premise. Doesn't change the conclusion; the ADP+CP semantics stand on their own.Suites after the fix: 30 mock tests, 20 real-MPI tests, pre-commit clean.