Skip to content

[None][fix] AllReduce fusion two-shot: write the barrier's own flag slot last - #19905

Open
yekerr wants to merge 1 commit into
NVIDIA:mainfrom
yekerr:fix/allreduce-fusion-twoshot-barrier-aba
Open

yekerr wants to merge 1 commit into
NVIDIA:mainfrom
yekerr:fix/allreduce-fusion-twoshot-barrier-aba

Conversation

@yekerr

@yekerr yekerr commented Oct 6, 2026 •

Copy link
Copy Markdown

Dev Engineer Review

Barrier::sync now writes flags for CTAs not launched in the current grid with relaxed system-scope stores, then writes the current block’s slot with a release store. This preserves ordering for the slot that peer CTAs poll while reducing release stores. The change targets stale-flag reads when a larger-grid call follows a smaller-grid call. The reported correctness and latency results are author-reported; no independent test results or review findings were supplied.

QA Engineer Review

No test changes.

Per-File QA Perspective

  • cpp/tensorrt_llm/kernels/communicationKernels/allReduceFusionKernels.cu: Verify two-shot AllReduce when a larger grid follows a smaller grid, including the flag ordering and output correctness. Also check small-grid latency and confirm latency remains stable at larger grids.

Description

The two-shot AllReduce-fusion kernel can return wrong results, with no error, when a two-shot call is followed by one that launches more CTAs.

Barrier::sync writes the new flag to all kBarrierFlagCount slots of the peer, so that CTAs that are not launched now also see the current flag. It writes the block's own slot first. The peer block waits only until its slot is != prev_flag. The flag cycles 0/1/2, so in a later launch with a larger grid, a block can find its slot still holding the flag from two barriers ago. That value is also != prev_flag, so the block passes the barrier before the peer has written its data, and it reads stale data.

The fix writes the slots of the CTAs that are not launched now first, with relaxed stores, and the block's own slot last, with st.release.sys. The peer acquires that slot, so the one release store orders all of the earlier stores. One file changes: cpp/tensorrt_llm/kernels/communicationKernels/allReduceFusionKernels.cu (+13/-3).

A side effect is that each block now issues one release store per barrier instead of one per slot, which makes the two-shot kernel faster for small grids.

Test Coverage

The kernel was built standalone from main (687af96) before and after the change, on 8x B200. The workspace comes from CustomAllReduceHelper.allocate_allreduce_fusion_workspace. Pattern kAllReduce, bf16, two-shot forced. Each trial runs two back-to-back two-shot calls with different token counts, with no injected delay, and compares both outputs exactly to the expected sum (the inputs are small integers, so the sum is exact in bf16).

GPUs tokens (1st -> 2nd call) hidden trials with wrong output, before after
4 (GPUs 0-3 and 4-7) 5 -> 64 7168 196/200 0/200
2 3 -> 512 4096 99/100 0/100
4, TRTLLM_ENABLE_PDL=0 5 -> 64 7168 99/100 0/100
8 5 -> 64, 64 -> 5, 300 -> 1200 7168 0 0
2 / 4 / 8 129 -> 1024/2048, 200 -> 2048 4096/7168 0 0
4 1000 -> 1000 7168 0/50 0/50

The failure needs a small two-shot grid followed by a larger one. It did not show up without an injected delay on 8 GPUs, or when both calls have more than 128 tokens. After the change, no configuration gave a wrong output.

Two-shot latency, bf16, hidden 7168, CUDA graph of 500 calls, slowest rank, best of 3 (us/call):

GPUs T=8 T=64 T=256 T=1024 T=4096
2 113.3 -> 16.3 20.5 -> 17.6 24.6 -> 19.8 44.0 -> 41.1 150.5 -> 148.3
4 222.9 -> 21.9 37.1 -> 20.0 29.0 -> 25.9 57.9 -> 53.1 193.4 -> 191.9
8 298.5 -> 30.1 75.0 -> 25.2 34.8 -> 31.6 77.4 -> 69.9 227.1 -> 226.2

Through the production op: in the nvcr.io/nvidia/tensorrt-llm/release:1.3.0rc29 container (its allReduceFusionKernels.{cu,h} are identical to main), allreduce_fusion_op was replaced through LD_PRELOAD by a build of this file before and after the change. The same 5 -> 64 sequence, run through tensorrt_llm._torch.distributed.AllReduce(strategy=AllReduceStrategy.TWOSHOT) on 4x B200, 50 trials each:

fusion_op stock 1.3.0rc29 before after
NONE 49/50 wrong 49/50 wrong 0/50
RESIDUAL_RMS_NORM (checks residual_out) 0/50 9/50 wrong 0/50

Existing tests, with the same before / after builds:

  • tests/unittest/_torch/multi_gpu/test_allreduce.py and test_ar_residual_norm.py on 8 GPUs: 46 passed, 10 skipped for stock, before and after. The skips are the 8 test_row_linear_residual_norm_fusion cases that are skipped in-tree and the 2 cases that need exactly 4 GPUs.
  • With 4 GPUs visible, test_minimax_allreduce_rms_qk: 2/2 passed before and after.

None of the existing tests changes the token count between two-shot calls, so they do not catch this bug.

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)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • 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.


@yilin-void @hyukn could you take a look? This changes the two-shot Barrier::sync from #3064. cc @kaiyux since #18834 discusses the two-shot barrier and grid size.

🤖 Generated with Claude Code

@yekerr
yekerr requested a review from a team as a code owner October 6, 2026 22:18
@yekerr
yekerr requested a review from zongfeijing October 6, 2026 22:18
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
Commits

Reviewing files that changed from the base of the PR and between c811e46 and e8bcab1.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/TensorRT-LLM/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 1b20cedb-3c72-4801-a586-2278eabfd4b5
📥 Commits

Reviewing files that changed from the base of the PR and between 46473dc and b37b7a0.

📒 Files selected for processing (1)
  • cpp/tensorrt_llm/kernels/communicationKernels/allReduceFusionKernels.cu

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Walkthrough

Barrier::sync now uses relaxed stores for CTA flag slots not launched in the current grid. It uses a release store for the current block’s flag. A relaxed system-scope store helper supports this ordering.

Changes

Barrier flag ordering

Layer / File(s) Summary
Relaxed store helper and barrier ordering
cpp/tensorrt_llm/kernels/communicationKernels/allReduceFusionKernels.cu
Barrier::st_flag_relaxed performs a relaxed system-scope store. Barrier::sync uses it for future CTA slots and release-stores the current block’s flag.

Priority: High

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: bowenfu, farazkh80

Merge Risk: Minimal · previous review b37b7

No merge-blocking issue was identified in the barrier-ordering change; proceed with normal validation.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the repository format and clearly describes the barrier flag ordering fix.
Description check ✅ Passed The description explains the bug and fix, provides detailed test coverage and results, and completes the PR checklist.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@yekerr
yekerr force-pushed the fix/allreduce-fusion-twoshot-barrier-aba branch from b37b7a0 to c811e46 Compare October 14, 2026 21:00

@yilin-void yilin-void left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the fix!

@yilin-void

Copy link
Copy Markdown
Collaborator

/bot run

@yilin-void
yilin-void enabled auto-merge (squash) October 28, 2026 12:00
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81177 [ run ] triggered by Bot. Commit: c811e46 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81177 [ run ] completed with state SUCCESS. Commit: c811e46
/LLM/main/L0_MergeRequest_PR pipeline #66872 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

…lot last

Barrier::sync writes the new flag to all kBarrierFlagCount slots, starting
with the block's own slot, and the peer block waits only until its slot is
!= prev_flag. The flag cycles 0/1/2, so when the next two-shot launch has a
larger grid, a block that is not launched now can find its slot still
holding the flag from two barriers ago, which is also != prev_flag, and pass
before the peer has written its data.

Write the slots of the blocks that are not launched first, relaxed, and the
block's own slot last with st.release.sys, so that the one release store
orders all of them.

Two-shot at T=5 then T=64 (hidden 7168, bf16) on 4xB200, no injected delay:
196/200 calls wrong before, 0/200 after; 2 GPUs (T=3 -> 512) 99/100 -> 0/100.
The fix also drops one release store per slot: two-shot latency at
hidden 7168 is unchanged at T=4096 and up to 66% lower at T=64 on 8 GPUs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Zixin Huang <zixinh@nvidia.com>
@yilin-void
yilin-void force-pushed the fix/allreduce-fusion-twoshot-barrier-aba branch from c811e46 to e8bcab1 Compare October 29, 2026 06:45
@yilin-void

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81375 [ run ] triggered by Bot. Commit: e8bcab1 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81375 [ run ] completed with state FAILURE. Commit: e8bcab1
/LLM/main/L0_MergeRequest_PR pipeline #67050 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants