Repository navigation
[Feat] dsa: Kernel prerequisites for a DCP-sharded indexer - #48501
Conversation
There was a problem hiding this comment.
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
BBuf
left a comment
There was a problem hiding this comment.
[BBuf Review Agent] One thing to fix before this can go in.
| uint32_t n_gt = 0, n_eq = 0; | ||
| for_each_input<N>(problem.in, problem.seq_len, [&](float val, uint32_t) { | ||
| n_gt += val >= v_hi ? 1u : 0u; | ||
| n_eq += (val < v_hi && val >= v_lo) ? 1u : 0u; |
There was a problem hiding this comment.
[BBuf Review Agent] For a 32768-element row with the last 2048 scores set to 70000 and the rest zero, v_hi is NaN, so this counts no ties and the cluster path returns the first 2048 positions even with deterministic=True. Could we use !(val >= v_hi) here, matching the staging pass, and add this case?
There was a problem hiding this comment.
Thanks, confirmed: with v_hi NaN the counting pass dropped every tie, and your row returned the first 2048 positions on the old head. Rather than patch the count, the cluster candidates now run the shared TopKCluster from #47960, so this code is gone (68d97b2). Your case is in test_topk_v2_candidates_cluster_matches_one_block as top_bin; it fails on the old head and passes now.
There was a problem hiding this comment.
[BBuf Review Agent] The NaN case is covered now, but transform_candidates still lacks the shared selector's 20-bit index guard: with length 2^20+64, k=32 and the first and last 64 scores tied at 1, deterministic cluster selection picks the tail. Could we fall back to one block for longer rows or add the same guard as the paged entry point?
There was a problem hiding this comment.
Confirmed: on the old head your row picked the tail. In mode 2, rows past 2^20 now take the one-block path, which has no index limit (50c4d24). Your case is test_topk_v2_candidates_cluster_long_row_ties; it fails on the old head and passes now. Could you take another look?
There was a problem hiding this comment.
[BBuf Review Agent] Checked this head: mode 2 routes rows longer than 2^20 through candidates_one_block, and the regression checks the smallest 32 indices for both cluster sizes. This addresses the index-limit concern.
Co-authored-by: Xiaoyu Zhang <[email protected]> Co-authored-by: Po-Han Huang <[email protected]> Co-authored-by: Khoa Pham <[email protected]>
…istently, take one schedule argument
a3d6e73 to
8d55c44
Compare
This comment has been minimized.
This comment has been minimized.
|
/rerun-test test_topk_v2.py test_flashmla_sched_meta.py test_fused_store_index_cache.py |
|
🚀 🚀 |
Original authors: @yhyang201, @BBuf, @nvpohanh, @kpham-sgl
Port of #48414
The Kimi-K3.1 Day-0 branch (#48414) shards the DSA indexer's index-K cache across the DCP ranks (
dsa_dcp_sharded.py); on main, Kimi-K3.1 still rejects--dcp-size > 1. This PR ports the kernels that path needs, with tests and no caller yet:Against the raw port, tie order and the cluster path reuse #47960 instead of the branch's own versions (whose cluster path missed ties in the top coarse bin), and
schedule/dcp_size/dcp_rankreplace the branch's flags and names. Left for the sharded indexer PR: the schedule tests that need its backend code.Modifications
topk_v2.cuh,topk.py)topk_transform_candidates_v2: a ragged top-k that writes(fp32 score bits, local * dcp_size + dcp_rank)per selected position,(0, -1)padded, so the ranks' candidates merge into the global top-k. It shares the ragged selection (ragged_window_topk); rows pastcluster_floorrun the shared cluster top-k (TopKCluster), each rank emitting the candidates it selects. The cluster size is picked from the row count on SM90 / SM100, where the cluster path is built.deterministic=Trueon the ragged, paged, packed and candidates entry points builds that call in top-k mode 2 ([Perf] [NVIDIA] dsv4/topk_v2: Exactness modes (fast / exact / deterministic) and an exact cluster path #47960), whateverSGLANG_TOPK_V2_MODEis: equal scores at the k-th place resolve to the smallest indices, which the merge relies on. The module name carries the mode, so both builds load in one process.flashmla_sched_meta.cuh/.py)schedule="parallel": the partition walk by pointer doubling across the block, giving the same schedule as the serial walk.schedule="windowed"(sparse only): request costs cut into equal windows; a valid schedule with the same bound on the costliest partition, computed in a few microseconds."serial"; either alternative falls back to it when it does not fit in shared memory.fused_store_index_cache.cuh,dsa_fused_store_index_cache.py)dcp_size/dcp_rank: with widened slots, a rank stores only its own slots, at rowslot // dcp_size. Defaults keep the current behavior.Tests
test_topk_v2.py: candidates against the ragged top-k, with and without row starts; cluster against one block, including rows whose threshold lands in the highest coarse bin; index-ordered ties on the paged, ragged and packed paths in a process whose default mode is exact.test_flashmla_sched_meta.py: the parallel walk reproduces the serial one bit for bit, and a replay whose lengths outgrow its workspace falls back; the windowed schedule covers every request's blocks exactly once, and FlashMLA gives the same attention on it as on its own schedule.test_fused_store_index_cache.py: under DCP, owned, foreign and negative slots mixed; the buffer equals a plain store of the owned tokens atslot // dcp_size.On one B300 GPU at this head:
test_topk_v2.py400 passed, 14 skipped;test_flashmla_sched_meta.py242 passed;test_fused_store_index_cache.py16 passed.Speed
B300, each call replayed 50 times in a CUDA graph, best of 5 (us per call).
flashmla_sched_meta, 148 partitions, top-k 2048, block 64, overhead 5. Per-request lengths uniform in [1, 512] (a DCP8 rank) or all 2048:Below
kMinParallelBatch = 8the parallel schedule is the serial one; at b = 8 it is slower on short lengths and faster on full ones, and from b = 16 it is faster on both. At b = 256 with full lengths its tables do not fit, so it falls back to serial.topk_transform_candidates_v2, top-k 2048, deterministic, randn scores,cluster_floor=0:The cluster path loses at 8192 and wins from 16384 on, which
_CANDIDATES_CLUSTER_FLOOR = 16384follows (rows up to it take one block).CI States
Latest PR Test (Base): 🚫 Run #41982168957
Latest PR Test (Extra): ❌ Run #41982168861
Latest PR Test (AMD ROCm 10): 🚫 Run #41982168914
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: