Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🟡 Changes recommended
The tests use an incorrect a16w4 scale layout, share an activation implementation that can mask errors, and leave floating-point input and reference dtypes dependent on global defaults.
7 open issues
Set the floating-point table dtype explicitly · New Set the reference buffer dtype explicitly · New Set router logits dtype explicitly · New Use scale_kwidth=8 for the a16w4 layout · New Validate against an independent SwiGLU reference · New Set router logits dtype explicitly · New Set router logits dtype explicitly · New
What changed in this PR
This PR addresses SwiGLU output corruption in gfx1250 Gluon MoE prefill kernels at block_m=128. It replaces inline-assembly clipping on this path while leaving the shared Triton activation unchanged.
Changes:
- Add a Gluon-native SwiGLU helper and use it across a4w4, a8w4, and a16w4 kernels.
- Add shared quantization, routing, and reference helpers for regression tests.
- Test a4w4/a8w4 against PyTorch references and compare a16w4 gather modes.
| File | Description |
|---|---|
op_tests/triton_tests/moe/test_moe_gemm_a8w4.py |
Add SwiGLU reference checks for both gather modes. |
op_tests/triton_tests/moe/test_moe_gemm_a4w4.py |
Add SwiGLU reference checks and remove an unused helper. |
op_tests/triton_tests/moe/test_moe_gemm_a16w4.py |
Add a SwiGLU gather-versus-pregathered comparison. |
op_tests/triton_tests/moe/moe_test_utils.py |
Add shared data preparation and reference helpers. |
aiter/ops/triton/_gluon_kernels/gfx1250/moe/moe_op_gemm_a8w4.py |
Import the new Gluon SwiGLU helper. |
aiter/ops/triton/_gluon_kernels/gfx1250/moe/moe_op_gemm_a4w4.py |
Implement SwiGLU with native minimum and maximum operations. |
aiter/ops/triton/_gluon_kernels/gfx1250/moe/moe_op_gemm_a16w4.py |
Import the new Gluon SwiGLU helper. |
Review effort: Balanced
lburzawa
left a comment
There was a problem hiding this comment.
It seems like the inline assembly was inserted based on some old llvm commit producing suboptimal code. Given it has large spills and accuracy issues I think we can just revert the swiglu clip function to use triton again instead of inline asm.
The changes here are for mi450. But on mi350, it is a different story, we still need the inline asm to avoid VGPR spilling. Detailed info is below. The clip() function used to do tl.minimum(x, limit). The LLVM SLP vectorizer (commit 86aaf7b55ef5bfe4f96c8d58ce6addfe5e85967b) folds the element-wise minimum into a packed vector v_min_f32. AMDGPU then scalarizes that packed instruction during lowering, but the intermediate vector copies are kept alive, raising register pressure and causing spills in the A16W4 MoE GEMM kernel. The fix replaced tl.minimum with tl.inline_asm_elementwise("v_min_f32 $0, $1, $2", ...) using pack=1, which forces a scalar (single-element) instruction What changed in Triton since the PR landed:
The key question — is the LLVM SLP issue fixed in Triton 3.9? The workaround targets an LLVM backend lowering behavior (v_min_f32 scalarization), not a Triton-level bug. The LLVM commit There's nothing in the Triton 3.9 bump commit or the git history between the two Triton pins that suggests the LLVM SLP/AMDGPU lowering path was fixed. The bump is primarily CI/channel changes (release_tmp, version string 3.9.0). Conclusion: Reverting to tl.minimum would very likely reintroduce the register spill regression on the current Triton 3.9 pin, because the root cause is in Tried some examples, here are what we got: |
9cfa61e to
d2876f5
Compare
|
@scxiao thanks for checking on gfx950. Could you quickly also check if using min/max like this helps to resolve any of the vgpr spill issues on gfx950? In case it doesnt we can just go ahead with your specific fix for gfx1250 only. |
d2876f5 to
77fcec6
Compare
77fcec6 to
0f39f4f
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The reported SwiGLU regression tests and reference helpers are missing, leaving gfx1250 block_m=128 coverage across all three precisions and both gather modes unreproducible.
1 open issue
7 resolved since last review
Review effort: Balanced
| # apply activation function | ||
| if APPLY_SWIGLU: | ||
| out = _swiglu(acc, alpha, limit, ADD_RESIDUAL) | ||
| out = _swiglu_gfx1250(acc, alpha, limit, ADD_RESIDUAL) |
| assert_close(ref_y, tri_y, maxtol=4e-1, rmstol=4e-2) | ||
|
|
||
|
|
||
| def test_op_expert_parallel_rejects_bad_inputs(): |
There was a problem hiding this comment.
Can we remove this UT? We generally dont add API checks to moe UTs, only precision checks.
There was a problem hiding this comment.
hmm I still see it in "files changed" section on github.
| m, n_expts_tot, n_expts_act, do_gather, do_scatter, device="cuda" | ||
| ): | ||
| logits = torch.randn((m, n_expts_tot), dtype=torch.float16, device=device) | ||
| logits = torch.randn((m, n_expts_tot), dtype=torch.float32, device=device) |
There was a problem hiding this comment.
Any reason for changing precision to fp32 here and in other UTs? It has been float16 for a long time.
- Sort imports (ruff I001) in moe_op_gemm_a16w4, a4w4, a8w4
- Remove unused triton import (ruff F401) in moe_test_utils
- Replace dict() with literal {} (ruff C408) in test files
- Add explicit dtype to floating-point tensors per test rules
- Move misplaced triton import to correct position in test_moe_gemm_a8w4
Co-Authored-By: Claude <[email protected]>
- Rename _swiglu -> _swiglu_gfx1250 in moe_op_gemm_a4w4.py and update all callers in a8w4 and a16w4 kernels (lburzawa request) - Remove duplicate fast_dividef import and stale _swiglu import from activations in moe_op_gemm_a4w4.py (ruff F811, I001) - Fix router logits dtype float16 -> float32 in init_routing_data across all three test files (README rule: explicit dtype on float tensors) - Remove unused make_mxfp4_weight import in test_moe_gemm_a8w4.py (ruff F401) - Remove dedicated swiglu test functions and helpers added in this PR (test_a4w4/a8w4/a16w4_gluon_swiglu_*); the existing test_op cases with apply_swiglu=True on large-M gfx1250 shapes already cover this via the independent moe_gemm_torch reference (lburzawa review) - Remove shared helpers added to moe_test_utils.py that were only used by the removed tests
The helpers (ep_routing, gemm1_swiglu_torch_ref, swiglu_ref, make_mxfp4_weight, dequant_e2m1, upcast_fp8, E2M1) were added for the dedicated SwiGLU test functions that were removed per reviewer feedback. No test file imports them any longer.
c4af6f3 to
15bac9f
Compare
|
|
||
|
|
||
| @gluon.jit | ||
| def _swiglu_gfx1250(input, alpha, limit, ADD_RESIDUAL: gl.constexpr): |
There was a problem hiding this comment.
Can we put this under aiter/ops/triton/_triton_kernels/moe/activations.py?

Summary
Fix non-deterministic corruption in gfx1250 Gluon MOE prefill kernels (a4w4, a8w4, a16w4) at
block_m 128by replacing the shared Triton_swigluwith a Gluon-native version that avoidsv_min_f32inline asm.Motivation
The
clip()function in _triton_kernels/moe/activations.py usestl.inline_asm_elementwise("v_min_f32 $0, $1, $2", "=v,v,v", ...). The"=v,v,v"constraint tells the register allocator the output is a fresh VGPR, butv_min_f32on gfx1250 writes to a fixed register (v1). The allocator does not model this clobber, so it keeps live values in v1 that get silently overwritten. This forces 658 scratch spill operations (1288 bytes) and creates a non-deterministic race that corrupts rows 0-31 of eachblock_m=128tile.AMDGCN comparison (block_m=128 a4w4 prefill, gather variant):
Changes
Performance (if applicable)
No performance regression expected. The Gluon-native _swiglu uses more VGPRs (990 vs 602) but eliminates all scratch spills (658 → 0), which should improve or maintain performance.
Testing
Test results (gfx1250, M=4096, block_m=128)
test_a4w4_gluon_swiglu_vs_torch_ref[gather-4096] PASSED
test_a4w4_gluon_swiglu_vs_torch_ref[gather-8192] PASSED
test_a4w4_gluon_swiglu_vs_torch_ref[pregathered-4096] PASSED
test_a4w4_gluon_swiglu_vs_torch_ref[pregathered-8192] PASSED
test_a8w4_gluon_swiglu_vs_torch_ref[gather-4096] PASSED
test_a8w4_gluon_swiglu_vs_torch_ref[gather-8192] PASSED
test_a8w4_gluon_swiglu_vs_torch_ref[pregathered-4096] PASSED
test_a8w4_gluon_swiglu_vs_torch_ref[pregathered-8192] PASSED
test_a16w4_gluon_swiglu_gather_vs_pregathered[4096] PASSED
test_a16w4_gluon_swiglu_gather_vs_pregathered[8192] PASSED
With inline-asm _swiglu reverted: 8/10 FAIL (cos ~0.996, ~4700 bad rows).
Documentation
Dependencies
Breaking Changes
None. The shared Triton _swiglu is unchanged. Only gfx1250 Gluon kernels are affected.
PR Self-Review
Behavior and intent
The gfx1250 Gluon MOE prefill kernels (a4w4, a8w4, a16w4) produced non-deterministic wrong output (rows 0-31 corrupted) at block_m 128. The root cause was v_min_f32 inline asm in the clip() function called by _swiglu, whose register constraints did not model the actual hardware clobber. Replacing with gl.minimum gives the Gluon compiler full visibility into the data flow, eliminating scratch spills and the corruption.
Validation and unverified scope
Validated on gfx1250 with scripts/repro_row12_gemm1.py (a4w4/a8w4, 9b/t5 shapes, block_m 32/64/128, both gather modes) and the new unit tests. Not tested on gfx942/gfx950 (those backends use the shared Triton _swiglu which is unchanged).
Changed op tests