Repository navigation
[Triton/Gluon] Avoid vectorizing A16W4 upper clamp - #5636
Conversation
Use scalar AMDGPU inline assembly for the upper activation clamp. The SLP-vectorized minimum is scalarized during backend lowering, while its intermediate vector copies increase register pressure and cause spills in the A16W4 MoE GEMM.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
There was a problem hiding this comment.
🔵 Needs a closer look
The clamp changes NaN semantics; use minnum-equivalent behavior and add a NaN regression test.
Pull request overview
This PR replaces the vectorized upper activation clamp with scalar AMDGPU inline assembly to reduce register pressure in A16W4 MoE GEMMs.
Changes:
- Uses
v_min_f32withpack=1for scalar upper clamping. - Preserves the optional lower clamp.
File summaries
| File | Description |
|---|---|
aiter/ops/triton/_triton_kernels/moe/activations.py |
Implements the scalar inline-assembly upper clamp. |
Review details
Suppressed comments (1)
aiter/ops/triton/_triton_kernels/moe/activations.py:12
- [verified]
tl.minimumdefaults toPropagateNan.NONE, which Triton lowers tominnumf; this change instead emitsv_min_f32, whose NaN behavior differs fromv_min_num_f32. The repository's scalar SwiGLU implementation also explicitly usesarith.minnumffor this clamp, so a NaN activation can now diverge from the previous Triton result andswiglu_torch. Author must use av_min_num_f32-equivalent sequence (or preserve the minnum contract another way) and add a regression case for NaN inputs.
"v_min_f32 $0, $1, $2",
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…oo early Motivation: with a SwiGLU limit (DSv4 10, M3 7), the gfx950 Gluon MoE GEMM1 gives wrong results that change from run to run, for a4w4, a8w8 and a8w4. At T 8192 the DSv4 a8w4 layer had cos 0.80 against the Triton chain. A limit that never clamps (1e30) gave NaN. Technical details: - ROCm#5636 made clip() an inline-asm v_min_f32. The Gluon GEMM1 applies the activation directly to the MFMA accumulators, so the asm follows the last MFMA. LLVM adds the MFMA-to-VALU wait states only before VALU instructions, not before INLINEASM. The ISA had `v_min_f32 v108, v80, v165` directly after `v_mfma_scale_f32_16x16x128_f8f6f4 v[80:83]`. - clip() uses tl.minimum again. With the current LLVM, this also removes the register-pressure problem that ROCm#5636 fixed: the A16W4 Triton GEMM1 (limit 10, 7168 -> 6144, E 48) has 55 VGPR spills instead of 65 and is 5% faster at M 1024 and M 8192. - New test test_moe_gemm_gluon_swiglu_limit.py: it runs each Gluon GEMM1 twice with inputs above the limit, compares the bits, and compares the result with the Triton kernel. Test plan and results (gpu-lock): - New test: 6 failed before the change, 6 passed after. - 208 tests that use a limit: test_model_shapes of test_moe_gemm_{a4w4,a8w4,a8w8,a16w4}.py, test_gemm1_fused_mxfp4_out and test_gemm1_gate_up_split_matches_interleaved of test_moe_gemm_a4w4.py, and test_moe_gemm_gluon_{a8w4_fp8_chain,gemm1_family,gemm1_half_m_tile}.py: all passed. - Gluon a8w4 layer, T 8192, E 48, top-6: limit 10 3,866 us, no limit 3,867 us (same GPU); cos 0.99999 against the Triton chain. - A16W4 Triton GEMM1, limit 10, asm/plain, two runs each on one GPU: M 16 257-260/255-259 us, M 1024 1252-1256/1188-1190 us, M 8192 6039-6060/5749-5754 us. - black and ruff clean. - Not run: the tests/gate.sh asm-hash cells. Cells with a limit change, as expected. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Use scalar AMDGPU inline assembly for the upper activation clamp. The SLP-vectorized minimum is scalarized during backend lowering, while its intermediate vector copies increase register pressure and cause spills in the A16W4 MoE GEMM.
Motivation
Technical Details
Test Plan
Test Result
Submission Checklist