feat: add topology-aware sparse MLA candidate policy#1162
feat: add topology-aware sparse MLA candidate policy#1162teerthsharma wants to merge 30 commits into
Conversation
e760e85 to
bbf4a83
Compare
Signed-off-by: Teerth Sharma <teerths57@Gmail.com>
Signed-off-by: Teerth Sharma <teerths57@Gmail.com>
Signed-off-by: Teerth Sharma <teerths57@Gmail.com>
df8f73e to
71b46fb
Compare
Signed-off-by: Teerth Sharma <teerths57@Gmail.com>
AI Code Review - PR #1162Status: BLOCKING Summary: P0/0 · P1/1 · P2/3 · P3/1 Blocking IssuesP1
Non-blocking SuggestionsP2
P3
Checklist Violations (2 fail / 56 total)General Principles Checklist
Strengths
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds a topology-aware KV candidate rewrite policy (with optional compression counters/fingerprinting) and wires it into the Hybrid Indexer behind an env-gated switch to preserve existing learned sparse top-k behavior by default.
Changes:
- Introduces
topology_kv_policy.pyimplementing topology-based candidate selection/merge modes plus stable fingerprint + counters. - Integrates policy application into
Indexer._compute_topkbehindRTP_LLM_TOPOLOGY_KV_POLICY=disableddefault. - Adds manual-only benchmark helpers and unit tests for topology scheduling and the policy helper.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| rtp_llm/models_py/modules/hybrid/topology_kv_policy.py | New helper implementing topology candidate merge/only modes plus compression counters/fingerprint. |
| rtp_llm/models_py/modules/hybrid/indexer.py | Env-gated integration hook to rewrite top-k indices and expose latest counters/fingerprint. |
| benchmark/topology_kv_candidate_schedule.py | Benchmark utility to build topology candidate schedules and compare dense vs sparse decode attention. |
| benchmark/test_topology_kv_policy.py | Tests for policy behavior, counters/fingerprint, and a CUDA sparse-attention E2E check. |
| benchmark/test_topology_kv_candidate_schedule.py | Tests for candidate schedule construction, validation, and benchmark determinism. |
| benchmark/BUILD | Adds manual Bazel py_test targets to avoid entering wildcard GPU CI. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Teerth Sharma <teerths57@Gmail.com>
b985260 to
f0285d5
Compare
Signed-off-by: Teerth Sharma <teerths57@Gmail.com>
AI Code Review - PR #1162Status: BLOCKING Summary: P0/0 · P1/0 · P2/4 · P3/0 Non-blocking SuggestionsP2
Checklist Violations (5 fail / 56 total)General Principles Checklist
Strengths
|
Signed-off-by: Teerth Sharma <teerths57@Gmail.com>
AI Code Review - PR #1162Status: BLOCKING Summary: P0/0 · P1/1 · P2/1 · P3/0 Blocking IssuesP1
Non-blocking SuggestionsP2
Checklist Violations (1 fail / 56 total)General Principles Checklist
Strengths
|
Signed-off-by: Teerth Sharma <teerths57@Gmail.com>
Signed-off-by: Teerth Sharma <teerths57@Gmail.com>
Signed-off-by: Teerth Sharma <teerths57@Gmail.com>
AI Code Review - PR #1162Status: BLOCKING Summary: P0/0 · P1/1 · P2/1 · P3/0 Blocking IssuesP1
Non-blocking SuggestionsP2
Checklist Violations (2 fail / 47 total)General Principles Checklist
Strengths
|
Signed-off-by: Teerth Sharma <teerths57@Gmail.com>
Summary
I made this a code/test/build-only stacked follow-up to #1160 for topology-aware sparse MLA candidate rewriting.
This PR is intentionally draft until #1160 lands. It includes no docs, README, plan, or spec files in the remote diff.
What changed
topology_kv_policy.pyfor opt-in topology-aware candidate merge modes.RTP_LLM_TOPOLOGY_KV_POLICY=disabled._get_topk_pagedunchanged because that path returns page-table / physical block IDs, not token offsets.torch.int32/torch.int64, so-1padding and absolute offsets remain representable.topk_indices.numel(), and top-k width.topology_onlyconsume the full structural budget so available structural tokens fillmin(topk_width, length)instead of being capped by merge-mode structural fraction.benchmark:topology_kv_policy_testand its CUDA manual variant.Policy modes
disabled: passthrough, default.topology_sparse_merge: merge topology sink/local/witness candidates with learned top-k candidates.topology_compress_sparse: sparse merge plus stable scaffold/output-contract counters.topology_only: topology candidates only, using the full structural budget.Coordinate contract
apply_topology_kv_policyrequires learned non-padding top-k indices to already be absolute token indices in the downstream sparse-attention coordinate system.For ragged and CP prefill rows:
row_startsis only a row-count alignment guard here. It is not added to returned top-k coordinates.Decode is intentionally bypassed because
_get_topk_pagedreturns page-table / physical block IDs, not token-space offsets.Validation I ran
Windows / local Python:
python -m unittest benchmark.test_topology_kv_policy -v: 35 tests run, 34 passed, 1 CUDA-manual test skipped by default.python -m unittest benchmark.test_topology_kv_candidate_schedule -v: 22 tests run, 21 passed, 1 CUDA-manual test skipped by default.benchmark:topology_kv_policy_test: passed.python -m py_compile ...: passed.python -m black --check ...: passed.Docker / Linux GPU image:
python -m unittest benchmark.test_topology_kv_policy -v: 35 tests run, 34 passed, 1 CUDA-manual test skipped by default.I cannot run Bazel in this Windows shell because neither
bazelnorbazeliskis installed here. I also cannot run final H20 validation because I do not own that GPU.Dependency
Blocked by #1160. This branch remains stacked and should be rebased after #1160 lands.