[None][perf] Overlap DSA heuristic prev_topk write-back on the aux stream - #16666
Conversation
767b036 to
90c4b5c
Compare
|
/bot run |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
Included review availability: Your plan includes up to 12 reviews per rolling hour; 10 remain after this review. WalkthroughThe change adds asynchronous heuristic TopK write-back coordination to ChangesDSA TopK write-back
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This change moves a per-layer feedback copy onto an auxiliary stream only when multi-stream execution is enabled, while preserving the eager path and matching each fork with a same-layer join; no actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant SparseAttention
participant Indexer
participant aux_stream
participant CUDA_events
SparseAttention->>Indexer: Schedule heuristic TopK write-back
Indexer->>aux_stream: Fork asynchronous copy
aux_stream->>CUDA_events: Record copy completion
SparseAttention->>Indexer: maybe_join_prev_topk_copy()
Indexer->>CUDA_events: Wait for pending copy
CUDA_events-->>Indexer: Signal completion
Indexer-->>SparseAttention: Clear pending state
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
PR_Github #64192 [ run ] triggered by Bot. Commit: |
|
PR_Github #64192 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #64243 [ run ] triggered by Bot. Commit: |
|
PR_Github #64243 [ run ] completed with state
|
90c4b5c to
4d90b7b
Compare
|
/bot run --disable-fail-fast |
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
PR_Github #64444 [ run ] triggered by Bot. Commit: |
|
PR_Github #64444 [ run ] completed with state
|
4d90b7b to
52d3f9b
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Rebased/ported onto the sparse-attention framework refactor (#12733), new head 52d3f9b: the Indexer fork moved from |
|
/bot run --disable-fail-fast |
|
PR_Github #64772 [ run ] triggered by Bot. Commit: |
|
PR_Github #64772 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #65523 [ run ] triggered by Bot. Commit: |
|
PR_Github #65523 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #66682 [ run ] triggered by Bot. Commit: |
|
PR_Github #66682 [ run ] completed with state
|
…ream The per-layer heuristic top-k feedback copy (this step's decode top-k -> next step's pre_idx hint) is a strided gather sitting on the main stream's critical path, once per indexer layer per decode step. Nothing in the current step consumes it, so fork it onto the Indexer's existing aux stream right after the top-k kernel and join it in the same layer's MLA forward once core sparse attention is enqueued -- the copy overlaps with the layer's heaviest decode work. Same-layer fork/join keeps CUDA graph capture free of unjoined forks (cudaStreamEndCapture rejects them) and restores ordering before the next layer overwrites the shared topk_indices_buffer rows the copy reads. Source and destination are persistent stable-address buffers, so replays stay valid with no record_stream bookkeeping. The fork engages only under do_multi_stream() (i.e. inside CUDA graph capture, where replay makes the stream/event host overhead free); eager execution keeps the original inline copy unchanged. Validated with a pattern-level CUDA graph smoke test: capture with the join succeeds, replayed feedback values are step-correct, and capture without the join fails with cudaErrorStreamCaptureUnjoined. Ported onto the sparse-attention framework refactor (NVIDIA#12733): the Indexer changes moved from sparse/dsa.py to sparse/dsa/indexer.py, and the two MLA join sites moved from modules/mla.py to sparse/dsa/module.py (_forward_dsa_attn) and sparse/deepseek_v4/module.py (forward_sparse_attn). Made-with: Claude Code (Fable 5) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: longcheng-nv <243710427+longcheng-nv@users.noreply.github.com>
Trim the fork-site comment and maybe_join_prev_topk_copy docstring to their essentials, as requested in review. Made-with: Claude Code (Fable 5) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: longcheng-nv <243710427+longcheng-nv@users.noreply.github.com>
366e531 to
842357f
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
/bot run --disable-fail-fast |
|
PR_Github #67019 [ run ] triggered by Bot. Commit: |
|
PR_Github #67019 [ run ] completed with state |
Made-with: Claude Code (Fable 5) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: longcheng-nv <243710427+longcheng-nv@users.noreply.github.com>
|
/bot reuse-pipeline |
|
PR_Github #67623 [ reuse-pipeline ] triggered by Bot. Commit: |
|
PR_Github #67623 [ reuse-pipeline ] completed with state |
Description
Indexer.sparse_attn_indexerwrites each decode step's top-k back tometadata.heuristic_prev_topk(the next step'spre_idxhint). This copy is a strided gather on the main stream, once per indexer layer per decode step, and nothing in the current step reads it. This PR forks the copy onto the indexer's existing aux stream right after the top-k kernel and joins it in the same layer's MLA forward after core sparse attention is enqueued, so the copy overlaps with the layer's heaviest decode work instead of delaying it.Notes:
topk_indices_bufferrows the copy reads.record_streamneeded.do_multi_stream(), same policy asmaybe_execute_in_parallel. Eager execution keeps the original inline copy.forward_dsa_attn(V3.2) andforward_impl_with_deepseek_v4. Shared DSA indexer layers (indexer is None) are unchanged.Test Coverage
cudaErrorStreamCaptureUnjoined.test_fp8_blockscale[heuristic_topk_mtp1](TestDeepSeekV32,cuda_graph=True) exercises the forked path on Blackwell.Performance
nsys per-iteration A/B: DeepSeek-V4 Pro FP4, 8xB200, TEP8, BS=1, ISL 64K, OSL 2048, MTP=0,
enable_heuristic_topk: true, CUDA graphs ON. Arms differ only in this PR's files on the same C++ build; ABBA run order; nsys window = decode iters 500-550 (49 per-iteration deltas per run).Mann-Whitney U z = -4.60 (p ≈ 4e-6); all four runs direction-consistent. In the base traces 0/300 feedback copies overlap other-stream work; with this PR 300/300 overlap core sparse attention and the join adds no main-stream bubble.
-15 µs/iter over 30 indexer layers ≈ 0.5 µs/layer, i.e. the copy-kernel duration leaving the critical path. That is 0.14-0.23% of TPOT for this config and ≤ ~0.4% for any realistic config, below what e2e timing can resolve. A matching e2e TPOT A/B (DeepSeek-V3.2-Exp FP4, 8xB200, TEP8, BS=1, MTP=3, ISL ~68.7K, 10 warm pairs) reads -0.42% mean / -0.16% median, SE ≈ 0.7% — statistically zero, consistent with the per-iteration bound.
Note (2026-08-12): an earlier revision reported +2-4% e2e TPOT gains (MTP=0/1/2). Those numbers are retracted as measurement artifacts — their baselines are inconsistent with later same-node reruns, and the magnitude is 10-20x above the per-iteration bound above.
PR Checklist
Dev Engineer Review
do_multi_stream()is disabled.Indexer.maybe_join_prev_topk_copy()with pending-state cleanup.#17416initializesin_mtp_draft_loopin the synthetic metadata stub.#65523succeeded after the rebase and inclusion of fix#17416.QA Engineer Review
No test changes.