Skip to content

[Triton/Gluon] Avoid vectorizing A16W4 upper clamp - #5636

Merged
lijinpei-amd merged 1 commit into
ROCm:mainfrom
lijinpei-amd:fix/moe-a16w4-inline-fmin
Sep 18, 2026
Merged

lijinpei-amd merged 1 commit into
ROCm:mainfrom
lijinpei-amd:fix/moe-a16w4-inline-fmin

Conversation

@lijinpei-amd

Copy link
Copy Markdown
Contributor

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

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.
@lijinpei-amd
lijinpei-amd requested review from a team and a lite review from Copilot September 17, 2026 15:00
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
multigpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 5636 --add-label <label>

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to opt this PR out.

@github-actions github-actions Bot changed the title [Triton] Avoid vectorizing A16W4 upper clamp [Triton/Gluon] Avoid vectorizing A16W4 upper clamp Sep 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 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_f32 with pack=1 for 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.minimum defaults to PropagateNan.NONE, which Triton lowers to minnumf; this change instead emits v_min_f32, whose NaN behavior differs from v_min_num_f32. The repository's scalar SwiGLU implementation also explicitly uses arith.minnumf for this clamp, so a NaN activation can now diverge from the previous Triton result and swiglu_torch. Author must use a v_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.

@zufayu
zufayu requested review from a team and vgokhale September 18, 2026 01:16
@lijinpei-amd
lijinpei-amd merged commit 5405d76 into ROCm:main Sep 18, 2026
55 of 64 checks passed
lijinpei-amd added a commit to lijinpei-amd/aiter that referenced this pull request Nov 10, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants