[TLERaw] Add NVSHMEM allreduce RMSNorm tutorial - #1122
Open
Fucov wants to merge 1 commit into
Open
Conversation
Fucov
requested review from
Galaxy1458,
menchunlei,
sunnycase and
zhzhcookie
as code owners
September 7, 2026 09:32
|
root seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a TLE-Raw NVSHMEM tutorial for a fused distributed operator with the following contract:
The tutorial demonstrates how to integrate a CUDA/NVSHMEM device-side collective into FlagTree through TLE-Raw, followed by a Triton residual + RMSNorm epilogue.
The implementation is added under:
Motivation
The existing NVSHMEM TLE-Raw tutorials demonstrate lower-level communication primitives such as CUDA-IPC AllReduce.
This tutorial extends that path to a representative LLM distributed fusion pattern:
The goal is to provide a compact example showing how TLE-Raw can be used to combine:
CUDA/NVSHMEM device functions,
symmetric communication workspace,
distributed synchronization,
Triton-side tensor computation,
correctness validation, and
reproducible operator benchmarking.
This PR is intended as a TLE-Raw integration and optimization example rather than as a universal replacement for an existing production collective implementation.
Implementation
1. TLE-Raw NVSHMEM AllReduce
allreduce-device.cuimplements the device-side BF16 collective path used by the tutorial.The native CUDA functions are registered from Python through the current TLE-Raw
@dialect(...)interface and invoked from the Triton path withtle_raw.call(...).The implementation uses rank-visible communication buffers and explicit synchronization required by the NVSHMEM communication path.
2. Row-parallel execution
The collective stage maps token rows to independent CTAs.
Instead of serializing multiple token rows through one CTA, the implementation uses approximately:
so the available parallelism scales with the token dimension.
This is especially important when moving from decode-sized inputs to larger token counts.
3. Residual + RMSNorm epilogue
After the distributed reduction completes, the epilogue computes:
with FP32 accumulation where required for normalization.
4. Host-side NVSHMEM lifecycle
allreduce-host.cucontains the host/runtime integration required by the tutorial, including:NVSHMEM initialization,
distributed bootstrap,
symmetric workspace management,
host-side C ABI, and
resource cleanup.
5. Python API and correctness test
allreduce.pyprovides:TLE-Raw CUDA function registration,
the reusable operator/communicator wrapper,
distributed initialization,
a PyTorch reference implementation, and
standalone correctness validation through
torchrun.6. Benchmark harness
benchmark.pyprovides a standalone distributed benchmark with:configurable token shapes,
warmup iterations,
repeated timing,
per-rank synchronization,
rank-max latency aggregation,
percentile statistics, and
JSON result output.
The benchmark implementation reuses the operator from
allreduce.pyrather than maintaining a second implementation.Correctness
Validated on NVIDIA H20 GPUs with:
Token counts:
Tokens | Max absolute error | Status -- | -- | -- 1 | 0.03125 | PASS 16 | 0.03125 | PASS 64 | 0.06250 | PASS 128 | 0.06250 | PASS 256 | 0.06250 | PASS 1024 | 0.06250 | PASS 4096 | 0.06250 | PASSIn these serving workloads, the current NVSHMEM route remains behind the mature FlashInfer production path, corresponding to roughly a 12–15% decode-throughput gap.
This framework result is included as an engineering boundary rather than as a performance-win claim. The tutorial contribution itself focuses on making the TLE-Raw NVSHMEM fusion path correct, reusable, and reproducibly benchmarkable.
Files changed
Only the new tutorial directory is added:
with four source files:
allreduce-device.cuallreduce-host.cuallreduce.pybenchmark.pyNo framework-specific integration code, generated benchmark artifacts, or machine-specific paths are included in the PR.
Validation
Local validation performed:
TLE-Raw import/runtime validation
NVSHMEM distributed correctness
TP4 / H2048 / BF16 correctness across T=1...4096
standalone benchmark execution
git diff --checkcopyright notice audit
third-party source provenance audit
no generated benchmark/profile artifacts included
no machine-specific absolute paths included
Repository CI is expected to provide the final formatting/build validation.
License / copyright
All newly added source files contain the FlagOS copyright notice.
The final tutorial code was written against the current FlagTree TLE-Raw APIs. No GPL/LGPL/AGPL-derived implementation code or third-party source text is included in the added files.