Repository navigation
[None][fix] kdaDecode legacy: __syncwarp before the lane-0 block-reduce stores - #19830
Conversation
…ce stores In block_reduce_sum2_for and block_reduce_sum2_active_for, lanes of warp 0 read the per-warp partials scratch[lane] / scratch[kReduceWarps + lane], reduce them with shuffles, and lane 0 then stores the block totals into scratch[0] and scratch[1], which lane 1 read. Shuffles do not order shared memory, so the store and lane 1's read were unordered (compute-sanitizer racecheck: 32 warnings per run of test_k3_kda_decode_attn, all in kda_decode_fusion_compact_heads_kernel). Lane 0's totals depend on lane 1's loaded value, so the results were not affected; __syncwarp() makes the order explicit. Signed-off-by: Vasanth Sabavat <vsabavat@nvidia.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 4 remain after this review. WalkthroughBoth ChangesWarp reduction synchronization
Priority: ➖ Normal Estimated code review effort: 1 (Trivial) | ~3 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The added barriers order the shared-memory accesses, and the inspected call paths show no remaining actionable merge risk. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements. |
|
/bot run --disable-fail-fast |
|
PR_Github #76326 [ run ] triggered by Bot. Commit: |
|
PR_Github #76326 [ run ] completed with state |
Conflicts: - tests/integration/test_lists/test-db/l0_b200.yml: both sides appended to the same B200 pre-merge block (main a MiniMax-H3 visual_gen case, this branch the Kimi K3 KDA / MLA decode kernel tests). Both are kept, main's line first. Also: - cpp/tensorrt_llm/kernels/kdaDecode/kdaDecodeLegacy.cu: main already has this branch's two __syncwarp() calls (NVIDIA#19830), so the file now equals main's. Signed-off-by: Vasanth Sabavat <vsabavat@nvidia.com>
This branch carries NVIDIA#19816's content at 546e567. The conflicts and semantic fixes below are the ones NVIDIA#19816 resolved in its published merges 0c9ab14 (main 70193ec) and 44a06db (main a1f562a), applied to this branch's copies of those files. Conflicts: - model_engine.py: main's NVIDIA#19696 moved the engine decoder buffers and state into _allocate_decoder_buffers() and _init_decoder_state(). Kept main's layout with this branch's __init__ changes ported into it (_staged_previous_batch_indices / _staged_previous_pos_indices next to _encoder_decoder_staged_request_ids, _step_input_stage next to _prepare_inputs_event, no num_accepted_draft_tokens_cuda). The gather_ids upload stays copy_to_device_if_changed, under main's enable_spec_decode argument. - cuda_graph_runner.py: main's NVIDIA#19306 strict-buffer snapshot now follows the captured forward directly; the post-capture postprocess_fn call stays removed. - test_cuda_graph_capture_replay.py: both sides' test classes kept. - l0_b200.yml: both sides appended to the same B200 pre-merge block; main's MiniMax-H3 line first, then the Kimi K3 kernel tests. Semantic fixes: - model_engine.py: the step-copy selection reads the enable_spec_decode argument that NVIDIA#19696 passes to _prepare_tp_inputs. - kv_cache_manager_v2.py: stage_batch_block_offsets builds its copy index as main's copy_batch_block_offsets now does (NVIDIA#17306: beam width up to max_copy_beam_width, beam 0 replicated for cross KV). - test_pytorch_model_engine.py: the staged-step test passes _prepare_tp_inputs' keyword-only enable_spec_decode, runtime_draft_len and is_dummy arguments. - test_cuda_graph_capture_replay.py: the postprocess_fn case of main's test_replay_rejects_rebound_graph_attr needs the post-capture call and is dropped; test_postprocess_fn_follows_only_the_warmup_forwards pins that postprocess_fn runs only after the warmup forward. Also: cpp/tensorrt_llm/kernels/kdaDecode/kdaDecodeLegacy.cu now equals main's (NVIDIA#19830 is this branch's two __syncwarp() calls). Signed-off-by: Vasanth Sabavat <vsabavat@nvidia.com>
Description
In
block_reduce_sum2_forandblock_reduce_sum2_active_for(
cpp/tensorrt_llm/kernels/kdaDecode/kdaDecodeLegacy.cu, used bykda_decode_fusion_compact_heads_kernel):scratch[lane]/scratch[kReduceWarps + lane]and reduce them withshuffles;
scratch[0]andscratch[1], which lane 1 read.Shuffles do not order shared memory, so lane 0's stores and lane 1's reads were unordered. compute-sanitizer racecheck
reports 32 warnings per run. Lane 0's totals depend on lane 1's loaded value, so results were not affected.
__syncwarp()before the stores makes the order explicit.Test Coverage
No new test: the outputs do not change, and the order is a racecheck finding.
tests/unittest/_torch/modules/kimi_kda/test_kda_decode_op.pycovers the kernel's outputs.PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions) (No new code path; existing tests cover the outputs, and the evidence is racecheck's.)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title. (No API change.)Any new dependencies have been scanned for license and vulnerabilities (No new dependencies.)
CODEOWNERS updated if ownership changes (No ownership change.)
Documentation updated as needed (No user-facing change.)
Update tava architecture diagram if there is a significant design change in PR. (No design change.)
The reviewers assigned automatically/manually are appropriate for the PR. (To check once the PR is open.)
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.Dev Engineer Review
__syncwarp()was added after the shuffle reductions in bothblock_reduce_sum2_forandblock_reduce_sum2_active_for. It makes warp synchronization explicit before lane 0 stores the block totals in shared memory. No public API changes are reported.QA Engineer Review
No test changes.
Per-File QA Perspective
cpp/tensorrt_llm/kernels/kdaDecode/kdaDecodeLegacy.cu: Verify both reduction paths produce correct outputs and that racecheck no longer reports the described shared-memory race. The PR reports no output-bit differences in 99 runs, but this result was not independently verified here.