Repository navigation
[Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MoE router + top-k + moe_sorting for TP decode on gfx950 - #7832
Conversation
… TP decode on gfx950 Add fused_all_reduce_rmsnorm_mxfp8 and its buffer class AllReduceRmsnormMxfp8. One Gluon kernel does the bf16 all-reduce of the partial sums over 2, 4 or 8 ranks, the residual add, the RMSNorm (standard or Gemma) and the MXFP8 quant (e4m3 values, E8M0 scale for each 32 values). The all-reduce is a reduce-scatter into Lamport inboxes, then an all-gather of the bf16 sum. The owner adds the ranks in rank order in fp32, as the AITER custom all-reduce does. Each rank then norms and quantizes all rows, so all ranks get the same bits. The sum of squares has a fixed order, and the test checks all outputs bitwise against a CPU reference. Each wait has a time limit. A wait that times out writes an error record into the buffer of each rank, and reset() clears it. HIP graphs are supported. Add a multi-GPU test (2, 4 and 8 ranks) and a benchmark. Signed-off-by: Vinayak Gokhale <[email protected]>
…p-k + moe_sorting for TP decode on gfx950 Add fused_all_reduce_rmsnorm_moe_route and its buffer class AllReduceRmsnormMoeRoute. One persistent Gluon kernel goes from the partial sums of a row-parallel layer to the inputs of the routed MoE: the all-reduce over 2, 4 or 8 ranks, the residual add, the RMSNorm (standard or Gemma) and its optional MXFP8 copy, the router GEMM (fp32 or bf16 weights, fp32 logits), the top-k (sigmoid + correction bias or softmax, optional group limit, renormalization, routed scaling factor), the moe_sorting outputs (any block size) and the zeroed moe_buf. The all-reduce is a one-shot push for small calls and a reduce-scatter + all-gather above, chosen by the bytes a rank sends. The ranks are added in rank order in fp32 with one bf16 rounding, as the AITER custom all-reduce does. In the two-shot protocol each rank routes its own rows and the top-k picks go to every rank. All ranks get the same bits. The sort keeps the tokens of each expert in ascending order, as moe_sorting. The row count is a runtime value; the kernel variants are power-of-2 row buckets. Experts, top-k, hidden size and the router layout are compile-time values. Each wait has a time limit. A wait that times out writes an error record into the buffer of each rank, and reset() clears it. HIP graphs are supported. Signed-off-by: Vinayak Gokhale <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
Signed-off-by: Vinayak Gokhale <[email protected]>
Signed-off-by: Vinayak Gokhale <[email protected]>
Move the Gluon device helpers of the gfx950 comms kernels into one module, aiter/ops/triton/_gluon_kernels/gfx950/comms/common.py: the Lamport poll (_lpoll, _poll_slots), the error record (_errec, _fail_record), the 16-byte vector loads and stores, the bf16 and e4m3 packing, the lane butterfly and the quad exchange. The kernel imports them from there. The fused all-reduce + RMSNorm + MXFP8 kernel uses the same module. Use triton.next_power_of_2 in place of the local _next_pow2 (kernel) and _pow2 (wrapper). They are equal for all n >= 1, and the kernel and the wrapper give them no other values. Remove _BFLY_MAX and _BFLY_MINI, which nothing used. The kernel name (repr), the wrapper results and the AMDGCN of the kernel do not change. Signed-off-by: Vinayak Gokhale <[email protected]>
Move the Gluon device helpers of the gfx950 comms kernels into one
module, aiter/ops/triton/_gluon_kernels/gfx950/comms/common.py: the
Lamport poll (_lpoll, _poll_slots), the error record (_errec,
_fail_record), the 16-byte vector loads and stores, the bf16 and e4m3
packing, the lane butterfly and the quad exchange. The kernel imports
them from there. The fused all-reduce + MoE route kernel uses the same
module.
Two helpers get the names of the shared copies: _poll is _poll_slots,
and _bfly_sum(x) is _bfly_op(x, _BFLY_ADD). _st4 gets an optional CACHE
argument. Its default ("") gives the same store as before.
The kernel name (repr), the wrapper and the AMDGCN of the kernel do not
change.
Signed-off-by: Vinayak Gokhale <[email protected]>
Use the shared gfx950 comms helpers (common.py, the same file as in #7792 and #7832) for _pack_bf16, _bf_lo, _bf_hi, _errec_asm and _errec_cons. The error record asm and constraints are the same strings for 1 to 8 buffers. _fail_record and _drain stay here: their arguments differ. Signed-off-by: Vinayak Gokhale <[email protected]>
… no free CTA A call takes one reduce CTA for each row of its power-of-2 routed bucket, and the pushes need a free CTA. At 2 ranks and 256 CTAs, max_tokens 257 to 510 passed the constructor, but a call with more than 256 tokens (a 512-row bucket, 256 reduce CTAs) failed with ZeroDivisionError in _constexprs. The constructor now rejects such a max_tokens. The test checks max_tokens 300 and 512: a rejected value, or a correct call with that many tokens. Signed-off-by: Vinayak Gokhale <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Accepted inputs can exceed device shared-memory limits, produce duplicate or missing expert selections, generate NaN weights, or silently use incorrect values from strided correction biases.
5 open issues
What changed in this PR
Adds fused_all_reduce_rmsnorm_moe_route for tensor-parallel MoE decode on gfx950. It combines communication, normalization, routing and sorting in one persistent Gluon kernel, with a new API alongside existing operations.
Changes:
- Fuses all-reduce, residual add, RMSNorm, optional MXFP8 quantization, router GEMM, top-k and MoE sorting.
- Adds collective buffer management, shared communication helpers and JSON launch settings.
- Adds multi-GPU correctness tests and a synchronized benchmark.
| File | Description |
|---|---|
op_tests/op_benchmarks/triton/bench_all_reduce_rmsnorm_moe_route.py |
Benchmarks latency across ranks and token counts. |
op_tests/multigpu_tests/triton_test/test_all_reduce_rmsnorm_moe_route.py |
Tests numerical outputs, sorting, graph replay and timeout recovery. |
aiter/ops/triton/configs/gfx950/gluon/fusions/all_reduce_rmsnorm_moe_route/DEFAULT.json |
Defines launch settings, protocol thresholds and router parameters. |
aiter/ops/triton/comms/fused/all_reduce_rmsnorm_moe_route.py |
Provides the public wrapper, buffer lifecycle and launch planning. |
aiter/ops/triton/_gluon_kernels/gfx950/comms/fused/all_reduce_rmsnorm_moe_route.py |
Implements the fused communication-to-routing kernel. |
aiter/ops/triton/_gluon_kernels/gfx950/comms/common.py |
Adds shared polling, error reporting, memory-access and packing helpers. |
Review effort: Balanced
TennyWang1223
left a comment
There was a problem hiding this comment.
Blocking issues
- The multi-GPU test never ran in CI.
The PR has no multigpu label, so "Multi-GPU Tests (8 GPU)" was skipped. The only evidence of correctness is the author's local run.
→ Add the multigpu label and get a green run on MI350X before merging. - Softmax plus correction_bias picks different experts than vLLM.
The kernel ranks experts by logit + bias. vLLM's grouped_topk ranks by softmax(logit) + bias. For example, with logits [0, 1] and bias [0.5, 0], the kernel picks expert 1 and vLLM picks expert 0. The test can't catch this: its reference copies the kernel's formula, and the softmax cases have no bias.
→ Either assert correction_bias is None for softmax, or add the bias after softmax. Then add a test for this combination. - The documented limits exceed gfx950 LDS.
The host accepts up to E=2048, topk=64 and max_tokens=512. Compiled for gfx950 (Triton 3.8.0), those edge configs need 196–344 KB of LDS, but the limit is 160 KB. The constructor accepts them, then the 257–512 token bucket fails at launch. Real model configs (E=256/384/512) use 70–107 KB and are fine.
→ Check LDS use in the constructor, or lower the documented limits.
Boss2002n
left a comment
There was a problem hiding this comment.
Must fix before merge
- Some allowed shapes need too much LDS (kernel): 2048 experts at hidden 8192 need 304 KiB, and top-64 at 512 tokens needs 266 KiB, but the limit is 160 KiB. Fix: check the LDS size in the constructor, or lower the documented limits.
- Very small values get a wrong scale (kernel): when the largest value in a group of 32 is between 2.6e-36 and 5.3e-36, the scale becomes 0, and values up to 896 go into fp8, which holds at most 448. #7792 has the same bug. Fix: use
mx_e8m0_scale(am, 8), and a test reference that does not copy the kernel code. - Softmax with a bias picks the wrong experts (kernel): the kernel ranks experts by logit + bias, not by softmax + bias, so it picks different experts than vLLM. It also gives NaN weights when the chosen logits are far apart. Fix: reject a bias with softmax, or add the bias after the softmax.
- Some inputs give a wrong top-k with no error (wrapper): a strided bias, fewer experts in the kept groups than top-k, or one expert per group with a bias. Fix: add asserts for these cases.
- Code copied from #7792 and from main (kernel): the reduce, norm and quant steps repeat #7792, and
_sigmoid,_add_i32, the e8m0 scale and_tpollrepeat existing helpers. Fix: share them in_gluon_kernels/common/, not in a newcommon.py. - Some branches have no test (test): block_size 32, 64 and 128, more than 256 experts, and
residual=None. Fix: add them to the existing test shapes. - The kernel is not in the tuner (DEFAULT.json): the tuner cannot tune this kernel. Fix: add an
@kernel(...)entry, theSEARCH_SPACEkeys and aconfig=argument.
Nice to fix
Signed-off-by: Vinayak Gokhale <[email protected]>
…too much LDS Some shapes in the documented limits need more LDS than a gfx950 CU has (160 KiB). For example, 2048 experts at hidden 8192 need 304 KiB (the partial logits of the route step), and top-64 at 512 tokens needs 266 KiB (the picks of the sort step). The constructor accepted these shapes, and the launch failed. The constructor now computes the LDS of each kernel variant (one for each token bucket and protocol up to max_tokens) and rejects the shape when one variant needs more than the LDS of a CU. The compiler reuses LDS between the router, route and sort steps, so the largest step sets the size. The formula assumes a correction bias. It gives the same size as the compiled kernels (shared-memory size in the Triton metadata) for each variant of the shapes that we compiled, and it is larger by the size of the bias buffer when a call has no bias and more than 256 experts. The test checks that the constructor rejects 2048 experts at hidden 8192. Signed-off-by: Vinayak Gokhale <[email protected]>
… with softmax With softmax scoring and a correction bias, the kernel ranked the experts by logit + bias. vLLM ranks them by softmax(logit) + bias, so the picks were different. Example: logits [0, 1] and bias [0.5, 0] give expert 1 in the kernel and expert 0 in vLLM. The wrapper now rejects a correction bias with softmax. Sigmoid with a bias does not change. The same input could also give NaN weights. The renormalized softmax subtracted the logit of the first pick, and with a bias the first pick does not always have the largest logit. When a picked logit was 88.7 or more above the first one, exp overflowed to inf and the weights were inf / inf = NaN. The kernel now subtracts the largest picked logit. Without a bias, this is the logit of the first pick, so the results do not change. The test checks softmax routing (renormalized and not) with picked logits up to 300 apart, and that the wrapper rejects softmax with a bias. Signed-off-by: Vinayak Gokhale <[email protected]>
Shorten the docstrings of the kernel module, the kernel, the comm class and the wrapper. The detail of the sum of squares, the Lamport slots and the MXFP8 scale is now in the docstrings of the shared helpers. The sorted_ids format is the moe_sorting format. Signed-off-by: Vinayak Gokhale <[email protected]>
…16x3 optional The bf16x3 kernel needed the terms (3, N, K) from split_bf16x3, so callers kept a second copy of the weight, 1.5 times its size. Now the kernel can read the fp32 weight and split each loaded tile into the three bf16 terms, with the rounding of split_bf16x3 (as the router of #7832 splits its fp32 weight). The kernel picks the path from the dtype of the weight pointer. w_bf16x3 is now optional, so gemm_a16w32(x, w) works. vLLM calls gemm_a16w32(x, weight, weight_split): that call still works, and the kernel reads the given terms, because that is faster. Both paths give the same bits: same terms, same order of the dots. A test checks it at M 1, 33, 256, 2048 and 4096. Bench (graph timing, cold weights, N=128, K=6144, gfx950, median of 3 runs in one session, us): M before given terms split in kernel 1-32 fp32 FMA kernel, not changed: within 1% (2.6% at M=8) 33 7.66 6.95 7.79 64 8.19 7.20 8.08 128 9.23 8.13 9.03 256 11.18 10.22 12.08 512 13.02 11.11 12.69 1024 17.97 16.13 19.71 2048 23.92 22.95 23.94 4096 48.05 44.41 45.69 8192 58.54 55.90 74.15 "before" is the head of the PR, which needs the terms. The faster column of the given terms comes from the shared split-K of the earlier commit. The split in the kernel loads 4 bytes for each weight value, not 6, but the warps that share a weight tile all split it, and the configs are tuned for the given terms. So the kernel reads the terms when it gets them. Without w_bf16x3, the bf16x3 kernel has the limits of split_bf16x3: exact for 2**-110 <= |w| < 2**128 - 2**119, inf or NaN at or above that limit. A probe with one-hot rows showed the same exact range for both paths. Signed-off-by: Vinayak Gokhale <[email protected]>
Compute the e8m0 scale byte with integer operations only. The helper adds 0x200000 to the fp32 bits of |amax| and takes the exponent field. Then it subtracts EXP_OFFSET and clamps the result at 0. Inf and NaN give 254. The old helper used log2, floor and a float-to-int conversion. On gfx950 this is v_log_f32 and approximately 15 instructions for each scale. The new helper gives the same byte as the old helper for all 2^32 fp32 inputs that are not NaN, for EXP_OFFSET 0 to 15 (exhaustive check on gfx950). This includes negative inputs: they give 254, or 0 when they round to -0. A NaN amax now always gives 254. The old helper gave 254 or 0, as a function of the NaN payload. Add a unit test with edge values for EXP_OFFSET 2 and 8. Signed-off-by: Vinayak Gokhale <[email protected]>
…-topk-sort Bring in the integer-only mx_e8m0_scale of #7792 (9f2d547). The shared store_rmsnorm_row calls it for the MXFP8 output of this op. The scale bytes do not change for inputs that are not NaN. Signed-off-by: Vinayak Gokhale <[email protected]>
Make the integer helper give the same byte as the former log2 formula for all 2^32 fp32 inputs, NaN included. Then no caller output changes. The callers are the comms kernels and the gfx950 and gfx1250 Gluon quant kernels. The helper now adds 0x200000 to the raw bits (mod 2^32), as the log2 formula did. For some NaNs this add sets the sign bit or wraps to an exponent field of 0. These NaNs give 0, and the other NaNs give 254. An exhaustive check on gfx950 finds no difference for all 2^32 inputs, for EXP_OFFSET 0 to 15. The unit test checks NaNs on both sides of the wrap and passes with the log2 formula and with the integer helper. Signed-off-by: Vinayak Gokhale <[email protected]>
…router-topk-sort Bring in a1f8263 of #7792. The integer mx_e8m0_scale now gives the same byte as the former log2 formula for every fp32 input, NaN included. The outputs of this op do not change. Signed-off-by: Vinayak Gokhale <[email protected]>
|
Thank you for the reviews. This PR is now stacked on #7792 (merges ed4086f, 81177b4 and a38f737). The changes are in 5003a0c to a38f737. Boss2002n — must fix
Boss2002n — nice to fix
TennyWang1223
On the M3.1 shape (hidden 6144, 4 ranks, 1 to 256 tokens), the time is within noise of the previous head. |
The test compared all output bytes. In the CI image (other Triton and PyTorch builds) 1 or 2 bf16 or e4m3 values of 1.5M changed by one rounding step, and the test failed. Now a bf16 or e4m3 value can be one rounding step from the reference, in at most 1 of 10,000 values (at least 8). The scale bytes must be equal. A failure gives the output name, the number of values that differ and the largest step. Signed-off-by: Vinayak Gokhale <[email protected]>
…m-router-topk-sort Bring in c58e694 of #7792. Its multi-GPU test now allows a bf16 or e4m3 value one rounding step from the reference. The kernels do not change. Signed-off-by: Vinayak Gokhale <[email protected]>
…step The test compared all bytes of the norm outputs, and it made the router reference from the reference norm output. In the CI image (other Triton and PyTorch builds) 1 to 3 bf16 values of a call changed by one rounding step. Then the norm bytes and the top-k weights did not agree, and the test failed. Now residual_out and normed can be one rounding step from the reference, in at most 1 of 10,000 values (at least 8). x_q, x_scale and the routing are compared with a reference made from the normed output of the kernel, which is the input of the router. These checks stay exact (top-k ids, MXFP8 bytes) or tight (top-k weights). The edge-scale check also compares x_scale with the expected bytes. Signed-off-by: Vinayak Gokhale <[email protected]>
Bring in main 008d53c. It has #8313, the fix of tests/test_ar_rmsnorm_routing.py that failed in the 1-GPU CI job. There are no conflicts. Signed-off-by: Vinayak Gokhale <[email protected]>
Bring in 74c83bc of #7792, which merges main 008d53c. Main has #8313, the fix of tests/test_ar_rmsnorm_routing.py that failed in the 1-GPU CI job. There are no conflicts. Signed-off-by: Vinayak Gokhale <[email protected]>
…router-topk-sort Bring in 68890e6 of #7792. Its multi-GPU test reuses the first shape's kernel in the time-out check and runs less at 8 ranks. The kernels do not change. Signed-off-by: Vinayak Gokhale <[email protected]>
…trim 8 ranks In the CI 8-GPU job, the launch after reset timed out on all ranks at 8 ranks. The time-out check made a comm with another max_tokens, so it launched a new kernel variant. The rank that skipped the first launch loaded this variant only after reset, and the other ranks waited only 50 ms for it. Now the sentinel and time-out checks use the comm size of the first shape, so they launch a kernel that each rank has already compiled. The 50 ms limit applies only to the launch that the last rank skips. The launch after reset has the default limit. At 8 ranks the test runs only the first shape, the sentinel check and the time-out check. Each other kernel variant compiles on all 8 ranks, which took most of the CI time. 2 and 4 ranks run all checks. At 8 ranks a run from an empty kernel cache takes 71 s, not 123 s (MI355X). Signed-off-by: Vinayak Gokhale <[email protected]>
…ce, trim 8 ranks In the CI 8-GPU job, the launch after reset timed out on all ranks at 8 ranks. The time-out check made a comm with another max_tokens, so it launched a new kernel variant. The rank that skipped the first launch loaded this variant only after reset, and the other ranks waited only 50 ms for it. Now the time-out check uses the comm size of the first shape, so it launches kernels that each rank has already compiled. The 50 ms limit applies only to the launch that the last rank skips. The launch after reset has the default limit. At 8 ranks the test runs only the first shape and the time-out check. Each other kernel variant compiles on all 8 ranks, which took most of the CI time. 2 and 4 ranks run all checks. At 8 ranks a run from an empty kernel cache takes 82 s, not 230 s (MI355X). Signed-off-by: Vinayak Gokhale <[email protected]>
Bring in main 35df6ef. It has the Triton 3.9.0 bump (#8266), whose fp4_utils.py fix the 1-GPU CI job needs: that job installs Triton 3.9.0. Signed-off-by: Vinayak Gokhale <[email protected]>
… gfx950 (#7771) * [Triton/Gluon] [Feature] Fused MoE top-k combine + reduce-scatter (gfx950) Add fused_moe_combine_reduce_scatter: one Gluon kernel for gfx950 does the MoE top-k combine and the reduce-scatter over 4 ranks (push mode). Each rank combines the top-k rows of a token as mxfp4_moe_scatter_reduce does and writes the row into the IPC inbox of the owner rank. The owner adds the 4 ranks in rank order in fp32 and rounds once to bf16. The combined [M, hidden] tensor is not written to memory. Add the stage-2 keyword scatter_intermediate to _mxfp4_a4w4_stage2_fw and _flydsl_v2_stage2_wrapper. With a dict and the bf16 scatter epilogue, stage 2 returns the intermediate, reverse_sorted and sorted_weights instead of the combine. With None, nothing changes. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] Support 2, 4 and 8 ranks in the MoE combine + reduce-scatter Make the world size a constexpr (WORLD in 2, 4, 8). The peer buffers come as a tuple and the per-peer code uses static loops. The inbox and the flags are (WORLD - 1) x ceil(max_rows / WORLD) rows. Add PARTS: PARTS CTAs share a row, one column part each, with a flag for each (row, part). At 8 ranks the prefetch of 7 peer rows spills registers with one CTA a row; PARTS 3 (hidden 6144) and 2 (hidden 3072, 5120) keep it in registers. The JSON config selects BLOCKS and PARTS by world size and hidden size. The 4-rank build (PARTS 1) has the same gfx950 instruction stream as before (2779 instructions). The multi-GPU test runs at 2, 4 and 8 ranks. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MXFP8 quant for TP decode on gfx950 Add fused_all_reduce_rmsnorm_mxfp8 and its buffer class AllReduceRmsnormMxfp8. One Gluon kernel does the bf16 all-reduce of the partial sums over 2, 4 or 8 ranks, the residual add, the RMSNorm (standard or Gemma) and the MXFP8 quant (e4m3 values, E8M0 scale for each 32 values). The all-reduce is a reduce-scatter into Lamport inboxes, then an all-gather of the bf16 sum. The owner adds the ranks in rank order in fp32, as the AITER custom all-reduce does. Each rank then norms and quantizes all rows, so all ranks get the same bits. The sum of squares has a fixed order, and the test checks all outputs bitwise against a CPU reference. Each wait has a time limit. A wait that times out writes an error record into the buffer of each rank, and reset() clears it. HIP graphs are supported. Add a multi-GPU test (2, 4 and 8 ranks) and a benchmark. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] MoE combine + reduce-scatter: clear the stage-2 dict, reject empty weights - _mxfp4_a4w4_stage2_fw and _flydsl_v2_stage2_wrapper clear the scatter_intermediate dict first. Before, a dict from an earlier scatter call kept its items when a later call wrote the complete output with another epilogue. - fused_moe_combine_reduce_scatter rejects an empty sorted_weights. The kernel loads a weight for each (token, k), also for a skipped position. - Test: one dict for a scatter call and then a reduce call, and the empty sorted_weights check. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] Share gfx950 comms Gluon helpers Move the Gluon device helpers of the gfx950 comms kernels into one module, aiter/ops/triton/_gluon_kernels/gfx950/comms/common.py: the Lamport poll (_lpoll, _poll_slots), the error record (_errec, _fail_record), the 16-byte vector loads and stores, the bf16 and e4m3 packing, the lane butterfly and the quad exchange. The kernel imports them from there. The fused all-reduce + MoE route kernel uses the same module. Two helpers get the names of the shared copies: _poll is _poll_slots, and _bfly_sum(x) is _bfly_op(x, _BFLY_ADD). _st4 gets an optional CACHE argument. Its default ("") gives the same store as before. The kernel name (repr), the wrapper and the AMDGCN of the kernel do not change. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] Share gfx950 comms Gluon helpers Use the shared gfx950 comms helpers (common.py, the same file as in #7792 and #7832) for _pack_bf16, _bf_lo, _bf_hi, _errec_asm and _errec_cons. The error record asm and constraints are the same strings for 1 to 8 buffers. _fail_record and _drain stay here: their arguments differ. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8: use mx_e8m0_scale for the MXFP8 scale The scale of a group whose amax was 2.6e-36 to 5.3e-36 was 2^-127. Then values up to 896 went into e4m3, which holds at most 448. At an amax of exactly 1.75 x 2^k, the scale was one step lower than the scale of the other AITER MXFP8 ops. The kernel now gets the scale from mx_e8m0_scale(amax, 8) in _gluon_kernels/common/utils.py. It divides by the scale with ldexp, because 2^-127 (scale byte 254) is not a normal fp32 value. The test reference does not copy the kernel code: it rounds the amax with frexp and computes in fp64. A new case has groups at the edges of the rule (tiny amax, 1.75 x 2^k, the largest bf16 values) and checks the reference against hand-computed scale bytes. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8: move the comms helpers to _gluon_kernels/common Move _gluon_kernels/gfx950/comms/common.py to _gluon_kernels/common/comms_gfx950.py, next to the other shared Gluon helpers. The module docstring says that the helpers are for gfx950 only. The helpers that kernels import get names without a leading underscore, for example poll_slots, fail_record, st4, bf_lo. _k4 is now dword_idx: the kernels use k4 as a variable name. The asm builders stay private. The README table of shared helpers and the Copilot reuse rule list the module. The AMDGCN of the kernel does not change. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8: share the sum, norm and quant steps The rank sum, the RMSNorm and the MXFP8 quant of a row are now shared helpers in _gluon_kernels/common/comms_gfx950.py: row_sum, rmsnorm_row and store_rmsnorm_row. They have the arguments of _row_sum, _norm_row and _store_rest of the fused all-reduce + MoE route kernel (#7832), so that kernel can call them without other changes. HAS_RES and QUANT select the residual add and the quant. One builder, _poll, now makes the Lamport poll and the tagged-word poll of #7832 (_tpoll). For each poll size and scope, its asm and its constraints are the same strings as before. poll_tags is the tagged poll of #7832. The kernel calls the shared helpers. The AMDGCN has the same instructions in a different order (3 or 4 fewer s_nop) and the same register counts. The outputs do not change. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8: share the IPC buffer code The comm classes of the three gfx950 Gluon multi-GPU ops had copies of the same methods: the IPC buffer pool, the peer buffers, _clear, error, reset and close. These are now in one base class, IpcCommBuffers, in aiter/ops/triton/comms/ipc_buffers.py. It uses IPCBufferPool of aiter.dist, as before. A subclass calls __init__ (gfx950 and group size checks, the time limit, rank, device and CU count), sets its layout, then calls _open (buffers, peers, colours, clear, barrier). _open takes the fill byte and the number of bytes that a clear fills, so an op with zeroed flags (the MoE combine + reduce-scatter) can use it. ERROR_BYTES is shared. AllReduceRmsnormMxfp8 is now a subclass. Its constructor arguments and its attributes (peers, device, max_tokens, blocks, config) do not change. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8: trim the test, share its input generator The test no longer runs 24, 96, 128 and 192 tokens at hidden 6144: 1, 3, 64 and 256 test the same paths. The HIP graph check runs for the first shape only. generate_all_reduce_rmsnorm_mxfp8_inputs in the test makes the inputs of the test and of the benchmark. The benchmark imports it, as the benchmark rules ask. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8: add config= and a benchmark sweep AllReduceRmsnormMxfp8 takes an optional config: BLOCKS and num_warps in place of the tuned DEFAULT.json values. The config is an argument of the comm, not of a call: all launches on one comm must use the same CTAs, because each CTA keeps its own launch colour. The constructor checks that num_warps is large enough for hidden. The benchmark times the tuned config and each pair of --blocks and --num-warps, with one comm for each config. The AITER tuner cannot time this kernel: its workers time candidates one GPU at a time, and all ranks must launch a collective together. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8: shorter docstrings Shorten the docstrings of the kernel module, the kernel, the comm class and the wrapper. The detail of the sum of squares and of the Lamport slots is now in the docstrings of the shared helpers. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8: config keys and --sweep as in #7832 Make config= and the benchmark sweep the same as in the fused all-reduce + MoE route op (#7832), so that the comms ops have one interface: - config holds values that replace the values of the tuned config. An unknown key is an error. - The benchmark takes --sweep KEY=V1,V2 (repeat for more keys) and times each combination as one line. A config that the constructor rejects is skipped with a warning. add_sweep_argument and get_sweep_configs are new shared helpers in op_tests/op_benchmarks/triton/utils/argparse.py, for the benchmarks of the three comms ops. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] Keep the Copilot instructions unchanged The README's shared-helpers table lists the new modules. Leave .github out of this PR. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] moe_combine_reduce_scatter: use the shared gfx950 comms helpers Use the device helpers of #7792 in _gluon_kernels/common/comms_gfx950.py: bf_lo, bf_hi, pack_bf16 and fail_record. Delete the copy of these helpers in _gluon_kernels/gfx950/comms/common.py, and the local copy of _fail_record in the kernel file (review: "_fail_record is defined twice"). Also delete the stale comment above _thread_ids. The shared fail_record broadcasts the buffer pointers to the lanes (+ z) before the inline asm. The AMDGCN of _moe_combine_reduce_scatter_kernel does not change. The kernel keeps _drain, _thread_ids and its flag poll _poll local: their semantics are different from the shared helpers. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] moe_combine_reduce_scatter: subclass IpcCommBuffers MoeCombineReduceScatter is now a subclass of IpcCommBuffers (#7792). The base class does the gfx950, group size and time limit checks, makes the IPC buffers and the colours, and has error, reset and close. Small differences: - The constructor zeroes [0, inbox) of the buffer (the error record, the row flags and the done words) and then does a barrier. - reset zeroes the error record one more time. - The error sites are in the class docstring. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] moe_combine_reduce_scatter: limit BLOCKS to the CU count All CTAs of a launch must run at the same time, because they wait for each other. The comm now uses min(BLOCKS, CU count) CTAs, rounded down to a multiple of PARTS, as in #7792. The comm keeps the value in comm.blocks. The done words, the colours, the grid and the BLOCKS constexpr of the kernel all use it. On a 256-CU gfx950 the value is the same as before (256, or 255 with PARTS 3), so the kernel and the buffers do not change there. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] moe_combine_reduce_scatter: add config= and a benchmark sweep MoeCombineReduceScatter takes an optional config, as in #7792: values that replace the values of the tuned DEFAULT.json config (BLOCKS, PARTS, LAG, num_warps). An unknown key is an error. The config is an argument of the comm, not of a call: the buffer layout and the colours depend on BLOCKS and PARTS. The constructor checks the limits of the kernel (PARTS divides hidden / 2, LAG >= 2, num_warps a power of 2 that is large enough for the done words), so that a sweep skips a bad config. The benchmark takes --sweep KEY=V1,V2 (the shared helpers of #7792) and times each combination as one line. A config that the constructor rejects is skipped with a warning. The AITER tuner cannot time this kernel: each tuner worker times candidates alone on one GPU, and all ranks must launch a collective together. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] moe_combine_reduce_scatter: test fewer token counts Remove the token counts 5857, 8192 and 14394 from the test. They test the same paths as 2343 and 4096 (padding rows, more than LAG rows for each CTA). Only the number of loop steps is larger. 16383 stays as the largest count, so the buffer layout of the test does not change. The benchmark still times 5857 and 14394. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] mx_e8m0_scale: integer-only scale byte Compute the e8m0 scale byte with integer operations only. The helper adds 0x200000 to the fp32 bits of |amax| and takes the exponent field. Then it subtracts EXP_OFFSET and clamps the result at 0. Inf and NaN give 254. The old helper used log2, floor and a float-to-int conversion. On gfx950 this is v_log_f32 and approximately 15 instructions for each scale. The new helper gives the same byte as the old helper for all 2^32 fp32 inputs that are not NaN, for EXP_OFFSET 0 to 15 (exhaustive check on gfx950). This includes negative inputs: they give 254, or 0 when they round to -0. A NaN amax now always gives 254. The old helper gave 254 or 0, as a function of the NaN payload. Add a unit test with edge values for EXP_OFFSET 2 and 8. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] mx_e8m0_scale: same byte as the log2 formula for NaN Make the integer helper give the same byte as the former log2 formula for all 2^32 fp32 inputs, NaN included. Then no caller output changes. The callers are the comms kernels and the gfx950 and gfx1250 Gluon quant kernels. The helper now adds 0x200000 to the raw bits (mod 2^32), as the log2 formula did. For some NaNs this add sets the sign bit or wraps to an exponent field of 0. These NaNs give 0, and the other NaNs give 254. An exhaustive check on gfx950 finds no difference for all 2^32 inputs, for EXP_OFFSET 0 to 15. The unit test checks NaNs on both sides of the wrap and passes with the log2 formula and with the integer helper. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8 test: allow one rounding step The test compared all output bytes. In the CI image (other Triton and PyTorch builds) 1 or 2 bf16 or e4m3 values of 1.5M changed by one rounding step, and the test failed. Now a bf16 or e4m3 value can be one rounding step from the reference, in at most 1 of 10,000 values (at least 8). The scale bytes must be equal. A failure gives the output name, the number of values that differ and the largest step. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8 test: fix the time-out race, trim 8 ranks In the CI 8-GPU job, the launch after reset timed out on all ranks at 8 ranks. The time-out check made a comm with another max_tokens, so it launched a new kernel variant. The rank that skipped the first launch loaded this variant only after reset, and the other ranks waited only 50 ms for it. Now the sentinel and time-out checks use the comm size of the first shape, so they launch a kernel that each rank has already compiled. The 50 ms limit applies only to the launch that the last rank skips. The launch after reset has the default limit. At 8 ranks the test runs only the first shape, the sentinel check and the time-out check. Each other kernel variant compiles on all 8 ranks, which took most of the CI time. 2 and 4 ranks run all checks. At 8 ranks a run from an empty kernel cache takes 71 s, not 123 s (MI355X). Signed-off-by: Vinayak Gokhale <[email protected]> --------- Signed-off-by: Vinayak Gokhale <[email protected]> Co-authored-by: Satya Nikhil Kodukula <[email protected]> Co-authored-by: azaidy <[email protected]>
… TP decode on gfx950 (#7792) * [Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MXFP8 quant for TP decode on gfx950 Add fused_all_reduce_rmsnorm_mxfp8 and its buffer class AllReduceRmsnormMxfp8. One Gluon kernel does the bf16 all-reduce of the partial sums over 2, 4 or 8 ranks, the residual add, the RMSNorm (standard or Gemma) and the MXFP8 quant (e4m3 values, E8M0 scale for each 32 values). The all-reduce is a reduce-scatter into Lamport inboxes, then an all-gather of the bf16 sum. The owner adds the ranks in rank order in fp32, as the AITER custom all-reduce does. Each rank then norms and quantizes all rows, so all ranks get the same bits. The sum of squares has a fixed order, and the test checks all outputs bitwise against a CPU reference. Each wait has a time limit. A wait that times out writes an error record into the buffer of each rank, and reset() clears it. HIP graphs are supported. Add a multi-GPU test (2, 4 and 8 ranks) and a benchmark. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] Share gfx950 comms Gluon helpers Move the Gluon device helpers of the gfx950 comms kernels into one module, aiter/ops/triton/_gluon_kernels/gfx950/comms/common.py: the Lamport poll (_lpoll, _poll_slots), the error record (_errec, _fail_record), the 16-byte vector loads and stores, the bf16 and e4m3 packing, the lane butterfly and the quad exchange. The kernel imports them from there. The fused all-reduce + MoE route kernel uses the same module. Two helpers get the names of the shared copies: _poll is _poll_slots, and _bfly_sum(x) is _bfly_op(x, _BFLY_ADD). _st4 gets an optional CACHE argument. Its default ("") gives the same store as before. The kernel name (repr), the wrapper and the AMDGCN of the kernel do not change. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8: use mx_e8m0_scale for the MXFP8 scale The scale of a group whose amax was 2.6e-36 to 5.3e-36 was 2^-127. Then values up to 896 went into e4m3, which holds at most 448. At an amax of exactly 1.75 x 2^k, the scale was one step lower than the scale of the other AITER MXFP8 ops. The kernel now gets the scale from mx_e8m0_scale(amax, 8) in _gluon_kernels/common/utils.py. It divides by the scale with ldexp, because 2^-127 (scale byte 254) is not a normal fp32 value. The test reference does not copy the kernel code: it rounds the amax with frexp and computes in fp64. A new case has groups at the edges of the rule (tiny amax, 1.75 x 2^k, the largest bf16 values) and checks the reference against hand-computed scale bytes. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8: move the comms helpers to _gluon_kernels/common Move _gluon_kernels/gfx950/comms/common.py to _gluon_kernels/common/comms_gfx950.py, next to the other shared Gluon helpers. The module docstring says that the helpers are for gfx950 only. The helpers that kernels import get names without a leading underscore, for example poll_slots, fail_record, st4, bf_lo. _k4 is now dword_idx: the kernels use k4 as a variable name. The asm builders stay private. The README table of shared helpers and the Copilot reuse rule list the module. The AMDGCN of the kernel does not change. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8: share the sum, norm and quant steps The rank sum, the RMSNorm and the MXFP8 quant of a row are now shared helpers in _gluon_kernels/common/comms_gfx950.py: row_sum, rmsnorm_row and store_rmsnorm_row. They have the arguments of _row_sum, _norm_row and _store_rest of the fused all-reduce + MoE route kernel (#7832), so that kernel can call them without other changes. HAS_RES and QUANT select the residual add and the quant. One builder, _poll, now makes the Lamport poll and the tagged-word poll of #7832 (_tpoll). For each poll size and scope, its asm and its constraints are the same strings as before. poll_tags is the tagged poll of #7832. The kernel calls the shared helpers. The AMDGCN has the same instructions in a different order (3 or 4 fewer s_nop) and the same register counts. The outputs do not change. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8: share the IPC buffer code The comm classes of the three gfx950 Gluon multi-GPU ops had copies of the same methods: the IPC buffer pool, the peer buffers, _clear, error, reset and close. These are now in one base class, IpcCommBuffers, in aiter/ops/triton/comms/ipc_buffers.py. It uses IPCBufferPool of aiter.dist, as before. A subclass calls __init__ (gfx950 and group size checks, the time limit, rank, device and CU count), sets its layout, then calls _open (buffers, peers, colours, clear, barrier). _open takes the fill byte and the number of bytes that a clear fills, so an op with zeroed flags (the MoE combine + reduce-scatter) can use it. ERROR_BYTES is shared. AllReduceRmsnormMxfp8 is now a subclass. Its constructor arguments and its attributes (peers, device, max_tokens, blocks, config) do not change. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8: trim the test, share its input generator The test no longer runs 24, 96, 128 and 192 tokens at hidden 6144: 1, 3, 64 and 256 test the same paths. The HIP graph check runs for the first shape only. generate_all_reduce_rmsnorm_mxfp8_inputs in the test makes the inputs of the test and of the benchmark. The benchmark imports it, as the benchmark rules ask. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8: add config= and a benchmark sweep AllReduceRmsnormMxfp8 takes an optional config: BLOCKS and num_warps in place of the tuned DEFAULT.json values. The config is an argument of the comm, not of a call: all launches on one comm must use the same CTAs, because each CTA keeps its own launch colour. The constructor checks that num_warps is large enough for hidden. The benchmark times the tuned config and each pair of --blocks and --num-warps, with one comm for each config. The AITER tuner cannot time this kernel: its workers time candidates one GPU at a time, and all ranks must launch a collective together. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8: shorter docstrings Shorten the docstrings of the kernel module, the kernel, the comm class and the wrapper. The detail of the sum of squares and of the Lamport slots is now in the docstrings of the shared helpers. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8: config keys and --sweep as in #7832 Make config= and the benchmark sweep the same as in the fused all-reduce + MoE route op (#7832), so that the comms ops have one interface: - config holds values that replace the values of the tuned config. An unknown key is an error. - The benchmark takes --sweep KEY=V1,V2 (repeat for more keys) and times each combination as one line. A config that the constructor rejects is skipped with a warning. add_sweep_argument and get_sweep_configs are new shared helpers in op_tests/op_benchmarks/triton/utils/argparse.py, for the benchmarks of the three comms ops. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] Keep the Copilot instructions unchanged The README's shared-helpers table lists the new modules. Leave .github out of this PR. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] mx_e8m0_scale: integer-only scale byte Compute the e8m0 scale byte with integer operations only. The helper adds 0x200000 to the fp32 bits of |amax| and takes the exponent field. Then it subtracts EXP_OFFSET and clamps the result at 0. Inf and NaN give 254. The old helper used log2, floor and a float-to-int conversion. On gfx950 this is v_log_f32 and approximately 15 instructions for each scale. The new helper gives the same byte as the old helper for all 2^32 fp32 inputs that are not NaN, for EXP_OFFSET 0 to 15 (exhaustive check on gfx950). This includes negative inputs: they give 254, or 0 when they round to -0. A NaN amax now always gives 254. The old helper gave 254 or 0, as a function of the NaN payload. Add a unit test with edge values for EXP_OFFSET 2 and 8. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] mx_e8m0_scale: same byte as the log2 formula for NaN Make the integer helper give the same byte as the former log2 formula for all 2^32 fp32 inputs, NaN included. Then no caller output changes. The callers are the comms kernels and the gfx950 and gfx1250 Gluon quant kernels. The helper now adds 0x200000 to the raw bits (mod 2^32), as the log2 formula did. For some NaNs this add sets the sign bit or wraps to an exponent field of 0. These NaNs give 0, and the other NaNs give 254. An exhaustive check on gfx950 finds no difference for all 2^32 inputs, for EXP_OFFSET 0 to 15. The unit test checks NaNs on both sides of the wrap and passes with the log2 formula and with the integer helper. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8 test: allow one rounding step The test compared all output bytes. In the CI image (other Triton and PyTorch builds) 1 or 2 bf16 or e4m3 values of 1.5M changed by one rounding step, and the test failed. Now a bf16 or e4m3 value can be one rounding step from the reference, in at most 1 of 10,000 values (at least 8). The scale bytes must be equal. A failure gives the output name, the number of values that differ and the largest step. Signed-off-by: Vinayak Gokhale <[email protected]> * [Triton/Gluon] all_reduce_rmsnorm_mxfp8 test: fix the time-out race, trim 8 ranks In the CI 8-GPU job, the launch after reset timed out on all ranks at 8 ranks. The time-out check made a comm with another max_tokens, so it launched a new kernel variant. The rank that skipped the first launch loaded this variant only after reset, and the other ranks waited only 50 ms for it. Now the sentinel and time-out checks use the comm size of the first shape, so they launch a kernel that each rank has already compiled. The 50 ms limit applies only to the launch that the last rank skips. The launch after reset has the default limit. At 8 ranks the test runs only the first shape, the sentinel check and the time-out check. Each other kernel variant compiles on all 8 ranks, which took most of the CI time. 2 and 4 ranks run all checks. At 8 ranks a run from an empty kernel cache takes 71 s, not 123 s (MI355X). Signed-off-by: Vinayak Gokhale <[email protected]> --------- Signed-off-by: Vinayak Gokhale <[email protected]> Co-authored-by: Satya Nikhil Kodukula <[email protected]>


Summary
This PR adds
fused_all_reduce_rmsnorm_moe_routefor TP decode on gfx950. One persistent Gluon kernel goes from the partial sums of a row-parallel layer to the inputs of the routed MoE:moe_sortingoutputs (any block size) and the zeroedmoe_buf.Before, these steps were 5 or more kernels.
Stacked on #7792. This PR uses the shared gfx950 comms code of #7792 (
_gluon_kernels/common/comms_gfx950.py,comms/ipc_buffers.pyand the integermx_e8m0_scale). Review #7792 first. On top of #7792 this PR changes 5 files: the kernel, the wrapper, the config, the test and the benchmark. The PR targetsmain, because the CI runs only for PRs tomain.For small calls, the all-reduce is a one-shot push. For larger calls, it is a reduce-scatter and an all-gather. The bytes that a rank sends select the protocol. The ranks are added in rank order in fp32 with one bf16 rounding, as the AITER custom all-reduce does. All ranks get the same bits. The sort keeps the tokens of each expert in ascending order, as
moe_sortingdoes.The token count is a runtime value. The kernel variants are power-of-2 token buckets. The hidden size, the number of experts, top-k and the router layout are compile-time values. The register use of the top-k does not grow with top-k or with the number of experts.
API
comm = AllReduceRmsnormMoeRoute(cpu_group, max_tokens, hidden, num_experts, topk, router_fp32=True, timeout_s=60.0, config=None)makes the IPC buffers (collective). It is a subclass ofIpcCommBuffers([Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MXFP8 quant for TP decode on gfx950 #7792). It rejects a shape when a kernel variant up tomax_tokensneeds more LDS than gfx950 has (160 KiB).configreplaces keys of the tuned config; an unknown key is an error.out = fused_all_reduce_rmsnorm_moe_route(x, residual, norm_weight, eps, router_weight, comm, correction_bias=None, scoring="sigmoid", renormalize=True, routed_scaling_factor=1.0, num_expert_group=1, topk_group=1, gemma=False, quant=True, block_size=16).outhasnormed,residual_out,x_qandx_scale(whenquant),topk_ids,topk_weights,sorted_ids,sorted_weights,sorted_expert_ids,num_valid_idsandmoe_buf, asaiter.moe_sortingreturns them. Every rank gets all rows.out=writes into given tensors.comm.warmup_tokens()gives one token count for each kernel variant, so that a caller can compile all variants before graph capture.comm.error()andcomm.reset()find and clear a timed-out wait.Results
MI355X, TP4, hidden 6144, 128 experts, top-4 sigmoid + bias, routed scaling factor 2.0, Gemma norm, MXFP8 copy, fp32 router weights. The value is the time in us for each layer: the maximum of the ranks, then the median of 30 rounds. A HIP graph has 8 calls. A small all-reduce before each replay starts the GPUs together. The routing is uniform. With skewed routing (16 to 116 experts hit), the results are almost the same.
Before: the AITER custom all-reduce, a fused add + RMSNorm + MXFP8 kernel, the router GEMM,
biased_grouped_topkandmoe_sorting. At 1 to 16 tokens, the first two kernels are the AITER fused all-reduce + RMSNorm and a separate MXFP8 quant. After: this op.Tests
op_tests/multigpu_tests/triton_test/test_all_reduce_rmsnorm_moe_route.py. At head 56d3ee4, it passes at 2, 4 and 8 ranks on MI355X. At 8 ranks it runs only the first shape and the time-out check, because each other kernel variant compiles on all 8 ranks and took most of the CI time. 2 and 4 ranks run all checks.aiter.moe_sortingon the kernel's top-k. The test also checks thatmoe_bufis zero.residual=None, softmax with picked logits up to 300 apart, the MXFP8 scale at the edges (tiny maxima, exactly 1.75 x 2^k, up to the largest bf16 value), the rejected inputs and an LDS-rejected shape.op_tests/op_benchmarks/triton/bench_all_reduce_rmsnorm_moe_route.py.--sweep KEY=V1,V2times other config values.Limitations
max_tokensis 512 or less, because all CTAs of the launch must run at the same time. Each row of a call's power-of-2 routed bucket takes one CTA, and one CTA must stay free: at 2 ranks (256 CTAs),max_tokensis 256 or less. The constructor rejects a larger value.PR Self-Review
Reviewed revision
2143c23
Behavior and intent
This PR adds a new op,
fused_all_reduce_rmsnorm_moe_route, for TP decode on gfx950. One persistent Gluon kernel does the bf16 all-reduce, the residual add, the RMSNorm with MXFP8 quant, the MoE router, the top-k andmoe_sorting. Before, these steps were separate kernels. It uses the shared gfx950 comms code of #7792. No existing op changes.Validation and unverified scope
op_tests/multigpu_tests/triton_test/test_all_reduce_rmsnorm_moe_route.pyat head 56d3ee4 (MI355X): passed at 2, 4 and 8 ranks. 2143c23 merges [Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MXFP8 quant for TP decode on gfx950 #7792 and main. On Triton 3.9.0 (the CI wheel3.9.0+amd.rocm7.2.0.git24d5394c, after the main bump [Triton/Gluon] [CI] [Build] Bump triton 7cb7b059 -> 24d5394c (3.9.0) with gfx950 fixes and config retune #8266),test_all_reduce_rmsnorm_mxfp8.pyandtest_all_reduce_rmsnorm_moe_route.pypass at 2, 4 and 8 ranks at 2143c23 (MI355X). With the local image, the residual, normed rows, MXFP8 copy and sort are bitwise equal to the references (the byte-exact test passed at a38f737. The later commits change only the tests and merge [Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MXFP8 quant for TP decode on gfx950 #7792 and main).resettimed out on all ranks. The check made a comm with anothermax_tokens, so it launched a new kernel variant. The rank that skipped the first launch loaded this variant only afterreset, and the other ranks waited only 50 ms for it. In 56d3ee4 the check uses the kernel of the first shape, and the launch afterresethas the default limit. When the last rank waits 0.3 s afterreset, the old test fails and the new test passes. From an empty kernel cache, the 8-rank run takes 82 s, not 230 s.residual_out, the top-k and the sort outputs are bitwise equal to 5df15ef (39 cases at 2 and 4 ranks, including the M3.1 shape at 1 to 256 tokens). The M3.1 AMDGCN at TP2, TP4 and TP8 is unchanged except the scale code.mx_e8m0_scaleof [Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MXFP8 quant for TP decode on gfx950 #7792 keeps 192 to 256 tokens at the old time).PR-specific question
Only the new op reads the new config
configs/gfx950/gluon/fusions/all_reduce_rmsnorm_moe_route/DEFAULT.json. It has oneanyentry: 256 CTAs, 8 warps, the one-shot limits (ONESHOT_MAX_ROWS,ONESHOT_MAX_BYTES) and the router steps for fp32 and bf16 weights. No existing op reads this file, so other ops and shapes keep their previous selection. The shared code of #7792 is used only by the gfx950 comms ops, andmx_e8m0_scalegives the same byte as before for every input.Changed op tests
op_tests/multigpu_tests/triton_test/test_all_reduce_rmsnorm_moe_route.py: new. It tests the op at 2, 4 and 8 ranks (at 8 ranks, the first shape and the time-out check) against CPU references (one bf16 rounding step in at most 1 of 10,000 values; MXFP8 bytes, top-k ids and sort exact) andmoe_sorting, the MXFP8 scale edges, the rejected inputs and the LDS check. No other test covers this op.op_tests/op_benchmarks/triton/bench_all_reduce_rmsnorm_moe_route.py: new. It is the benchmark that the AITER Triton rules require for a new op.--sweeptimes other config values.op_tests/multigpu_tests/triton_test/test_all_reduce_rmsnorm_mxfp8.py,op_tests/op_benchmarks/triton/bench_all_reduce_rmsnorm_mxfp8.py,op_tests/op_benchmarks/triton/utils/argparse.pyandop_tests/triton_tests/utils/test_gluon_mx_e8m0_scale.py: from [Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MXFP8 quant for TP decode on gfx950 #7792, which this PR is stacked on. See [Triton/Gluon] [Feature] Fused all-reduce + RMSNorm + MXFP8 quant for TP decode on gfx950 #7792 for them.