Skip to content

[Refactor] custom-ar-v2: Single-word push epoch and consume-style pull semaphores - #48217

Closed
DarkSharpness wants to merge 6 commits into
sgl-project:mainfrom
DarkSharpness:comm-push-epoch-protocol
Closed

DarkSharpness wants to merge 6 commits into
sgl-project:mainfrom
DarkSharpness:comm-push-epoch-protocol

Conversation

@DarkSharpness

@DarkSharpness DarkSharpness commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

(auto generated by Claude)
(auto generated by MyGO (Make your GPU-kernel Optimal) agent)

What

Simplifies the synchronization state shared by the CustomAllReduceV2 push/pull planes and every kernel that borrows them, so that resource sizes no longer depend on launch widths.

  • Push plane: the per-block phase counter array is replaced by one u64 EpochCounter. Each grid participant does one fire-and-forget red.add at exit (participant 0 adds 2^32 - (N - 1), the others add 1), so any grid size advances the phase exactly once. All "bumper" / cleanup blocks that flipped unused counters are removed, and push kernels may launch any grid size.
  • Pull plane: Semaphore keeps one arrival counter per ordering class (relaxed / release). The owner takes world_size arrivals with one atom.add(-W) and spins only while the balance is negative. Barrier / McBarrier are stateless (num_arrives, the window reservation and McBarrier::arrive_at are gone), and the semaphore index defaults to blockIdx.x. Separate counters make the release/acquire barrier well-defined under the PTX memory model even when a peer's next-round arrival lands first.
  • PushPlane takes a default_blocks launch width; PullPlane has capacity (allocated as max(num_sm, num_pull_blocks)) and default_blocks.
  • Migrated kernels: custom AR (push/pull), all_reduce_fusion, beam, tp_qknorm, nvlink_comm, K3 ar_fusion / sp_collective / gemm_ag / attn_res fused TMA, Muse Spark all-gather kernels and the CuTe DSL finalize all-reduce.

Validation

  • 2x B300: test_custom_all_reduce, test_all_reduce_residual_norm, test_collectives, test_beam_all_reduce, test_tp_qknorm, test_muse_spark_moe_finalize_all_reduce and test_custom_all_reduce_v2_capability all pass. A 2-GPU check of the CuTe DSL finalize all-reduce (1-shot / 2-shot push, with and without multicast, eager and CUDA graph, interleaved with JIT push all-reduces on the same plane) matches NCCL and is bitwise identical across ranks.
  • 2x B300, CUDA graph, bf16, vs main: 1shot/2shot push (8 KB - 1 MB), forced 1shot/2shot pull (256 KB - 4 MB) and fused AR + residual + norm are all within +-0.8 % (run-to-run noise).
  • SASS (sm_100a, nvcc 13.4) for every migrated kernel: no stack frame or spills; the push exit is a single REDG.E.ADD.64.STRONG.GPU, the pull barrier is ATOMG + optional poll with no constructor-time atomic.

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ✅ Run #42362024893
Latest PR Test (Extra): ❌ Run #42362025135
Latest PR Test (AMD ROCm 10): ✅ Run #42362024923

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@DarkSharpness

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/kernels/ops/communication/test_custom_all_reduce.py test/registered/kernels/ops/communication/test_all_reduce_residual_norm.py test/registered/kernels/ops/communication/test_collectives.py test/registered/kernels/ops/communication/test_beam_all_reduce.py test/registered/kernels/ops/communication/test_tp_qknorm.py test/registered/kernels/ops/communication/test_muse_spark_moe_finalize_all_reduce.py test/registered/kernels/ops/communication/test_ar_fusion.py test/registered/unit/distributed/test_custom_all_reduce_v2_capability.py

@DarkSharpness

Copy link
Copy Markdown
Collaborator Author

@BBuf for review

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🚀 8-gpu-h200 (4 tests): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/communication/test_custom_all_reduce.py
cd test/ && python3 registered/kernels/ops/communication/test_beam_all_reduce.py
cd test/ && python3 registered/kernels/ops/communication/test_tp_qknorm.py
cd test/ && python3 registered/kernels/ops/communication/test_ar_fusion.py

🚀 4-gpu-b200 (3 tests): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/communication/test_all_reduce_residual_norm.py
cd test/ && python3 registered/kernels/ops/communication/test_collectives.py
cd test/ && python3 registered/kernels/ops/communication/test_muse_spark_moe_finalize_all_reduce.py

🚀 8-gpu-b200 (1 test): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/communication/test_collectives.py

🚀 ubuntu-latest (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/distributed/test_custom_all_reduce_v2_capability.py

@DarkSharpness DarkSharpness changed the title [Refactor] custom AR v2: Single-word push epoch and consume-style pull semaphores [Refactor] custom-ar-v2: Single-word push epoch and consume-style pull semaphores Nov 3, 2026

@BBuf BBuf 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.

[BBuf Review Agent] One thing to fix before this can go in.

@DarkSharpness

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/kernels/ops/communication/test_all_reduce_residual_norm.py test/registered/kernels/ops/communication/test_muse_spark_moe_finalize_all_reduce.py test/registered/kernels/ops/communication/test_ar_fusion.py test/registered/kernels/ops/communication/test_beam_all_reduce.py

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🚀 4-gpu-b200 (2 tests): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/communication/test_all_reduce_residual_norm.py
cd test/ && python3 registered/kernels/ops/communication/test_muse_spark_moe_finalize_all_reduce.py

🚀 8-gpu-h200 (2 tests): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/communication/test_ar_fusion.py
cd test/ && python3 registered/kernels/ops/communication/test_beam_all_reduce.py

@DarkSharpness

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/kernels/ops/communication/test_ar_fusion.py

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🚀 8-gpu-h200 (1 test): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/communication/test_ar_fusion.py

@BBuf

BBuf commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@BBuf

BBuf commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

3 similar comments
@BBuf

BBuf commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@BBuf

BBuf commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@BBuf

BBuf commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

DarkSharpness and others added 4 commits November 7, 2026 01:22
…l semaphores

Replace the per-block push phase counters with one u64 EpochCounter committed by every grid participant, and make the pull semaphores consume arrivals (one counter per ordering class), so neither resource is tied to a launch width. Removes the bumper/cleanup blocks and the barrier window state.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The cluster leader commits for its whole cluster, so the other CTAs (and the leader's own warps) must have read the phase first. Restore the cluster barrier on the no-norm all_reduce_fusion path, add one before the K3 push_norm commit, and restore the CTA barrier before the CuTe DSL commit. Document the rule on EpochCounter.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Clusters that own a normed row already pass a cluster.sync in the row loop; only the others need ordering, so they arrive right after the phase load and the leader waits before committing, instead of a full cluster.sync on every cluster.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@DarkSharpness
DarkSharpness force-pushed the comm-push-epoch-protocol branch from 0926ab3 to 3fbd0e6 Compare November 7, 2026 09:36
@github-actions github-actions Bot added the Beam Mark PRs related to Reflection's Beam Model label Nov 7, 2026
@DarkSharpness

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/kernels/ops/communication/test_collectives.py test/registered/kernels/ops/communication/test_moe_front_ag.py

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

🚀 4-gpu-b200 (2 tests): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/communication/test_collectives.py  # base-c
cd test/ && python3 registered/kernels/ops/communication/test_moe_front_ag.py  # base-c

🚀 8-gpu-b200 (2 tests): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/communication/test_collectives.py  # nightly
cd test/ && python3 registered/kernels/ops/communication/test_moe_front_ag.py  # nightly

…ombine

The communicator header is compiled on ROCm too, so give red_add_relaxed_gpu (u32/u64), atomic_add_relaxed_sys and atomic_add_acquire_sys their __hip_atomic_fetch_add forms. Port the two push/pull users that landed on main since the rebase base: gemma4's ar_fusion to the stateless McBarrier, and dcp_push_combine to the single phase word.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@BBuf BBuf 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.

[BBuf Review Agent] One thing to fix before this can go in.

@DarkSharpness

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/kernels/ops/communication/test_collectives.py test/registered/kernels/ops/communication/test_moe_front_ag.py test/registered/kernels/ops/attention/test_dcp_push_combine.py test/registered/kernels/ops/communication/test_gemma4_ar_fusion.py

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

🚀 4-gpu-b200 (3 tests): ❌ View workflow run

cd test/ && python3 registered/kernels/ops/communication/test_collectives.py  # base-c
cd test/ && python3 registered/kernels/ops/communication/test_moe_front_ag.py  # base-c
cd test/ && python3 registered/kernels/ops/communication/test_gemma4_ar_fusion.py  # extra-b

🚀 8-gpu-b200 (2 tests): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/communication/test_collectives.py  # nightly
cd test/ && python3 registered/kernels/ops/communication/test_moe_front_ag.py  # nightly

🚀 8-gpu-h200 (1 test): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/attention/test_dcp_push_combine.py  # extra-b

gemm_ag_supported no longer requires two push blocks: every push kernel shares the plane's single phase word, so the grid is not bound to a counter array.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@DarkSharpness

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/kernels/ops/communication/test_gemma4_ar_fusion.py

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

🚀 4-gpu-b200 (1 test): ❌ View workflow run

cd test/ && python3 registered/kernels/ops/communication/test_gemma4_ar_fusion.py  # extra-b

@DarkSharpness

Copy link
Copy Markdown
Collaborator Author

(auto generated by Claude)

@BBuf FYI on the test_gemma4_ar_fusion.py 4-rank failure/hang seen on this PR: it is not caused by this change. We reproduced it on 4x GB300 with seeded inputs, and main (043cfc4) and this PR fail identically: same cases, same ranks, same elements, and never a cross-rank out/scales mismatch. The fused kernel and its barriers are fine; the test's fp32 reference does not model multimem.ld_reduce's non-round-to-nearest bf16 output, so the round_a=True residual check can miss by up to two bf16 ulps of the first norm. #49160 already stops it from hanging and covers the observed 0.0234 misses; #49346 widens the residual tolerance to the full two-ulp bound (0.047).

@DarkSharpness

Copy link
Copy Markdown
Collaborator Author

(auto generated by Claude)

Moved to #49365 (an in-repo branch, so follow-up PRs can stack on it). It carries the same commits, rebased onto main with #49205's DPX pair stages ported to the single-word epoch. Closing this one.

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

Labels

Beam Mark PRs related to Reflection's Beam Model jit-kernel run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants