Repository navigation
[Spec][PD] Enable fused TopK for GLM-5.2 MTP IndexShare - #31477
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to remap Parallel Disaggregation (PD) DSA seeds to local slots by utilizing the decode-local page table, ensuring that fused TopK remains functional under disaggregation mode. The changes include a new utility function, logic updates in the speculative disaggregation module, and corresponding unit tests. The reviewer suggests adding type hints for the 'server_args' parameter in the utility functions and refactoring the complex conditional logic in the disaggregation module to improve code readability and maintainability.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| invalid_rows = torch.any( | ||
| (dsa_topk_indices < -1) | ||
| | (dsa_topk_indices >= batch.seq_lens[:, None]) | ||
| | (dsa_topk_indices >= table_width) | ||
| # Slot 0 is the reserved padding sink; real KV allocations | ||
| # start at 1, and untouched req-to-token entries remain 0. | ||
| | (valid_positions & (local_slots <= 0)), | ||
| dim=1, | ||
| ) |
There was a problem hiding this comment.
The calculation of invalid_rows is a bit dense and combines multiple conditions in a single torch.any call. For better readability and maintainability, consider breaking down the conditions into separate, descriptively named boolean tensors. This will make the logic easier to understand at a glance.
# A seed is invalid if it references a position that is:
# - an invalid sentinel value (only -1 is valid)
# - out of bounds for the request's sequence length
# - out of bounds for the physical page table
# - a valid position that maps to an unallocated or padding slot
is_invalid_sentinel = dsa_topk_indices < -1
is_out_of_bounds_seq = dsa_topk_indices >= batch.seq_lens[:, None]
is_out_of_bounds_table = dsa_topk_indices >= table_width
is_unallocated_slot = valid_positions & (local_slots <= 0)
invalid_mask = (
is_invalid_sentinel
| is_out_of_bounds_seq
| is_out_of_bounds_table
| is_unallocated_slot
)
invalid_rows = torch.any(invalid_mask, dim=1)|
@zRzRzRzRzRzRzR Hello, when you have time, could you please take a look and see if this modification matches your design? |
zRzRzRzRzRzRzR
left a comment
There was a problem hiding this comment.
Just to confirm, this only changes the PD Decode path with fused TopK enabled, HiSparse disabled, and dcp_size == 1, while all existing paths retain their current behavior, correct?
|
Hi @HanHan009527 — I read your PD/MTP IndexShare optimization where request-relative seeds are remapped once to decode-local KV slots, eliminating the repeated page-table transforms and 704 unfused TopK calls in the profiled run. I’m Daniel, a user researcher with a product research team studying local AI systems for inference and kernel engineers. My main question is: what observability would make allocator-identity bugs across prefill, transfer, and decode easier to isolate without a large distributed reproduction? Would you be open to a Zoom interview of up to 30 minutes at your convenience? We’re preparing a prototype and may later provide test units or invite relevant participants as early users or technical advisors. This is research, not sales. |
Yes, I ensured this in HiSparse consumes logical/request-relative positions and resolves GPU residency per layer through DCP shards KV across context ranks, while the current remap only produces a single-rank allocator-local slot and does not apply the DCP owner filter or global-to-local index conversion. |
|
/tag-and-rerun-ci extra |
|
@Fridge003 Could you please review this PR? |
|
/rerun-test test/registered/models_e2e/test_dsa_glm52_cache_layer_split.py |
|
Results for 🚀 |
Keep request-relative seed positions on the PD wire, remap them once through the Decode-local req_to_token table, and then use the existing fused DSA TopK path.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
5a05138 to
175d98b
Compare
|
/rerun-test test/registered/models_e2e/test_dsa_glm52_cache_layer_split.py |
|
Results for 🚀 |
The review feedback has been processed. Regarding the testing issue, I think we might need to build a tiny model to test with 2 or 4 GPUs? |
kpham-sgl
left a comment
There was a problem hiding this comment.
I think we can revisit the testing question later
|
/rerun-test test/registered/models_e2e/test_dsa_glm52_cache_layer_split.py |
|
Results for 🚀 |
|
/rerun-test test/registered/models_e2e/test_dsa_glm52_cache_layer_split.py |
|
Results for 🚀 |
|
Fused DSA top-k is still off on ROCm under PD: Measured on GLM-5.2-MXFP4, 8×MI355X (gfx950, ROCm 7.2.0), 1P1D at TP2, decode step time p50:
2.55×, replicated across four independent run pairs. The gap is flat in context (39.7 ms at 37k prompt tokens, 41.8 ms at 177k) and both arms replay the draft CUDA graph (eager fraction 2e-4), so it is kernel work rather than launch overhead or a fallback. Fusion itself is fine on gfx950. Enabling it by declining the seed passes needle-in-a-haystack at ~150k context (3/3 depths) with real acceptance 3.09, acceptance simulation off. Is the |
|
@tianxiaojiang4 , I meant to gate off NPU only but ROCm paths are untested. Can you submit a PR with tested results? |
Motivation
GLM-5.2 MTP reuses DSA IndexShare top-k seeds across draft-decode steps to avoid redundant indexer work. The seed-transfer path added in PR #30839 preserves allocator independence by transporting request-relative positions. Because the existing fused TopK consumes allocator-local physical KV slots, this path currently falls back to an unfused page-table transform during draft decode.
This PR optimizes GLM-5.2 MTP IndexShare specifically under PD disaggregation. It converts the transferred seed once at the Decode consumer and then uses the existing fused TopK. The wire representation remains unchanged, while the Decode-local remap is required because the Prefill and Decode allocators are independent.
Modifications
SGLANG_DSA_FUSE_TOPK=1, non-HiSparse, anddcp_size == 1), remap the seed once through the localreq_to_tokentable before it enters the EAGLE draft loop.Accuracy Tests
The real PD seed was produced on Prefill, transferred to Decode, remapped locally, and consumed by fused TopK.
66% -> 66%2.96 -> 2.9619 passed, 17 warnings, 2 subtests passedA bounded LongBench-v2
shortevaluation used the same first 64 sample IDs in both independent distributed runs, with temperature 0,reasoning_effort=none,max_tokens=1024, and concurrency 1. This is a correctness/runtime guard, not a full LongBench-v2 score.Answer choices agreed on
51/64samples. Independent distributed runs are not bitwise deterministic, so aggregate accuracy and request/runtime guardrails are used for the regression check rather than exact text equality.Speed Tests and Profiling
Hardware and topology:
Workload:
TTFT and PD transfer time were unchanged within noise, as expected for a Decode-local optimization. Target verify, draft extend, and draft decode remained on Full CUDA Graph in all measured runs.
Dataset-derived Decode operator profile
One representative request from the same bounded LongBench-v2 subset was profiled through Router -> Prefill -> Decode: sample index 24, 76,489 dataset-prompt tokens and 76,503 API prompt tokens after chat wrapping. The capture covered 32 active Decode iterations with Full CUDA Graph enabled. Only Decode TP0 is summarized below; all eight rank traces per arm were checked and retained for audit.
transform_index_page_table_prefill_kerneltransform_index_page_table_decode_kerneltopk_kerneltopk_small_batch_kernel<true>topk_planThis isolates the intended mechanism: recurring page-table conversion disappears, unfused TopK dispatch changes to the existing fused small-batch path, and indexer scoring/planning work is preserved. Raw profiler durations are intentionally not used for an A/B latency claim because capture perturbation differs between the two CUDA Graph paths; the profiler-off repeated
128K + 1.5KA/B above remains the performance evidence.Checklist
CI States
Latest PR Test (Base): 🚫 Run #30874159469
Latest PR Test (Extra): ✅ Run #30874159192