Skip to content

[Triton/Gluon] fused_clamp_act_mul: accept rows of whole quant groups - #7489

Merged
azaidy merged 3 commits into
ROCm:mainfrom
karverma-amd:karverma/fused-clamp-act-mul-quant-group-rows
Nov 10, 2026
Merged

azaidy merged 3 commits into
ROCm:mainfrom
karverma-amd:karverma/fused-clamp-act-mul-quant-group-rows

Conversation

@karverma-amd

@karverma-amd karverma-amd commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

fused_clamp_act_mul required the half width to be a multiple of 128. Both the Gluon and Triton kernels already mask columns past n_half inside their power-of-two tile and skip scale groups past it, and read the columns past it as zero, so a last quant group that n_half does not fill is scaled over its real columns. This allows any multiple of 32, exports that multiple as N_HALF_MULTIPLE, and adds a gfx1250 Gluon config for N=576.

Related: consumed by ROCm/ATOM#3021 (DeepSeek-V4.1 shared expert at TP4/TP8, opt-in via ATOM_V4_USE_TRITON_FUSION=1), which reads N_HALF_MULTIPLE and assumes 128 when it is absent.

Motivation

DeepSeek-V4.1-Flash's shared expert has 576 intermediate columns per rank at TP4 and 288 at TP8. The 128 assert keeps it on silu_and_mul plus a separate group-32 quant on every MoE layer.

Changes

  • aiter/ops/triton/fusions/fused_clamp_act_mul.py: assert n_half >= N_HALF_MULTIPLE and n_half % N_HALF_MULTIPLE == 0 (N_HALF_MULTIPLE = 32, a module constant callers can gate on); a partial last quant group is allowed, as before for multiples of 128 (e.g. 384 with quant_block_size=256). On the Gluon path without quant, the unused group is clamped to the N tile, so unquantized rows of 32 or 64 columns do not trip the tile assertion. Docstring updated.
  • aiter/ops/triton/configs/gfx1250/gluon/fusions/fused_clamp_act_mul/FUSED_CLAMP_ACT_MUL-N=576.json: new, 256-wide tiles, 1 warp.
  • op_tests/triton_tests/fusions/test_fused_clamp_act_mul.py: test_fused_clamp_act_mul_mx_partial_width.

Widths that passed before (multiples of 128) take exactly the same path and configs.

Performance (if applicable)

Hardware Workload/configuration Before After Change
gfx1250 Gluon, M=48, N=576, MXFP8 out: DEFAULT whole-row 1024 tile vs new N=576 config 1.88 us 1.53 us -19%
gfx1250 M=48, N=576, 43 calls per HIP graph: silu_and_mul + group-32 quant + w2 vs fused + w2 (DeepSeek-V4.1-Flash TP4 shared expert) 6.68-7.05 us 4.73 us -29 to -33%
gfx1250 Same at N=288 (TP8) 6.03-6.87 us 4.00-4.05 us -34 to -41%

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Tested on gfx1250 only (Gluon backend). The relaxed assert is shared with the Triton backend, whose new partial-width cases run off gfx1250 and were not run here.

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None. Previously accepted widths behave the same (including a partial last group such as 384 / 256); multiples of 32 that used to assert are now accepted.

PR Self-Review

Reviewed revision

8f12739

Behavior and intent

Relaxes the width check from "multiple of 128" to a multiple of N_HALF_MULTIPLE (32), matching what both kernels already handle through masking, and exports that multiple so callers gate on the installed kernel rather than a hard-coded number. The existing check is insufficient because it rejects valid shapes such as DeepSeek-V4.1-Flash's shared expert at TP4 (576) and TP8 (288), forcing an unfused path. Adds a tuned gfx1250 Gluon config for N=576.

Validation and unverified scope

  • gfx1250: python3 -m pytest -q op_tests/triton_tests/fusions/test_fused_clamp_act_mul.py -k partial_width -> 32 passed, 32 skipped (Triton backend, skipped on gfx1250 by the test).
  • gfx1250: full file python3 -m pytest -q op_tests/triton_tests/fusions/test_fused_clamp_act_mul.py -> 364 passed, 484 skipped (same reason), re-run at this revision: no regressions in existing cases.
  • Through ATOM at 576 / 288, M 8-1024: the fused path's w2 output is never less accurate than the unfused one against an fp32 reference (e.g. 576, M=48: 2.643e-2 vs 2.664e-2; 288, M=48: 2.617e-2 vs 2.639e-2).
  • Timing on gfx1250 as in the table; end to end through perf(dsv41): take the fused shared-expert act + quant at TP4 and TP8 ATOM#3021.
  • black --check (26.10) and ruff check clean on changed files.
  • Unverified: the Triton backend's partial-width cases (MI300X / MI355X), and non-MX quant formats at partial widths.

PR-specific question

The only config change is the new file configs/gfx1250/gluon/fusions/fused_clamp_act_mul/FUSED_CLAMP_ACT_MUL-N=576.json (key any). _get_config(M, n_half, ...) loads FUSED_CLAMP_ACT_MUL-N={n_half}.json by filename, so it is consumed only by gfx1250, Gluon backend, n_half == 576, every M. Unrelated shapes keep their selection because no existing file (DEFAULT.json, N=512, N=4096, N=8192) is modified and the lookup is keyed on the exact n_half. Also, before this PR n_half = 576 failed the assert, so no previously working shape can change config.

Changed op tests

  • op_tests/triton_tests/fusions/test_fused_clamp_act_mul.py: adds test_fused_clamp_act_mul_mx_partial_width (widths 288/576/1152/2304, M up to 97, MXFP8 ue8m0 output) against an fp32 model of the kernel's quant: scale codes within one step on <0.1% of groups, values within E4M3 rounding. It fails before this PR on 288 and 576 (assert), and would catch wrong masking of the tail tile. test_fused_clamp_act_mul_partial_last_group (384 / 256 and 576 / 128, fp32 scales) checks a partial last group's scale is the amax of its real columns, and test_fused_clamp_act_mul_narrow_rows_unquantized covers unquantized 32- and 64-column rows. Not redundant: the existing cases use only power-of-two / multiple-of-128 widths, where the tile has no masked tail.

The wrapper required the half width to be a multiple of 128, but both the
Gluon and Triton kernels already mask the columns past n_half inside their
power-of-two tile and skip the scale groups past it. The real constraint is
whole quant groups, so allow any multiple of 32 (and of quant_block_size when
quantizing).

This lets DeepSeek-V4.1-Flash's shared expert take the fused clamp + SiLU*up +
MXFP8 path at TP4 (576 columns per rank) and TP8 (288). Adds a gfx1250 Gluon
config for N=576 (256-wide tiles, 1 warp): 1.88 -> 1.53 us at M=48 against the
default whole-row 1024 tile.

At M=48, N=576, 43 calls per HIP graph, the fused kernel against
silu_and_mul + group-32 quant: 3.39 -> 1.54 us; with the w2 GEMM after it,
6.37 -> 4.51 us.

test_fused_clamp_act_mul_mx_partial_width: widths 288/576/1152/2304, M up to
97, against an fp32 model of the kernel's ue8m0 quant (scale codes within one
step on <0.1% of groups, values within E4M3 rounding).
@karverma-amd
karverma-amd requested a review from a team November 5, 2026 02:51
@github-actions

github-actions Bot commented Nov 5, 2026

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 (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu 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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 7489 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

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 stop the title rewrites; labels stay in sync either way.

@aiter-bot

aiter-bot commented Nov 5, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision becee629f2b2 · mode shadow

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

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

The width the wrapper asserts (a multiple of 32) is now a module constant,
so a caller can gate on what the installed kernel accepts instead of
hard-coding it (ROCm/ATOM#3021 reads it and assumes 128 when it is absent).

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.

🟡 Changes recommended

The change causes gfx1250 unquantized rows with n_half=32 or 64 to fail a tile assertion and rejects a previously supported FP8 quantization configuration without documenting the breaking restriction.

2 open issues
What changed in this PR

This PR broadens fused_clamp_act_mul width support for shared-expert workloads such as DeepSeek-V4.1 TP4/TP8, allowing more shapes to use fused activation and quantization.

Changes:

  • Exports N_HALF_MULTIPLE = 32 and checks that quantized rows contain whole groups.
  • Adds a gfx1250 Gluon configuration for half-width 576.
  • Adds partial-width MXFP8 tests covering tail masking, scales, and zero groups.
File Description
op_tests/​triton_tests/​fusions/​test_fused_clamp_act_mul.py Adds an MX reference and partial-width test cases.
aiter/​ops/​triton/​fusions/​fused_clamp_act_mul.py Updates width checks, exports the width multiple, and revises documentation.
aiter/​ops/​triton/​configs/​gfx1250/​gluon/​fusions/​fused_clamp_act_mul/​FUSED_CLAMP_ACT_MUL-N=576.json Adds a 256-column, one-warp Gluon configuration.

Review effort: Balanced

@azaidy
azaidy self-requested a review November 5, 2026 14:07
@azaidy azaidy self-assigned this Nov 5, 2026
@azaidy
azaidy requested a review from Boss2002n November 5, 2026 14:54
@azaidy azaidy assigned Boss2002n and unassigned azaidy Nov 5, 2026
- Drop the whole-group requirement: both kernels read the columns past
  n_half as zero, so a partial last group is scaled over its real
  columns. n_half=384 with quant_block_size=256 is accepted again.
- Gluon: without quant, clamp the group to the N tile, so unquantized
  rows of 32 or 64 columns no longer fail the tile assertion.
- Tests: unquantized 32/64-column rows, and partial last groups
  (384/256, 576/128) against an fp32 reference.

Co-authored-by: Cursor <[email protected]>

@azaidy azaidy 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.

LGTM!

@azaidy
azaidy merged commit 57bcd66 into ROCm:main Nov 10, 2026
eppaneamd added a commit that referenced this pull request Nov 10, 2026
One conflict, in op_tests/triton_tests/fusions/test_fused_clamp_act_mul.py:
both sides appended tests at the end of the file. Both are kept: main's
(#7489) first, then this branch's row-count compile test.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
azaidy pushed a commit that referenced this pull request Nov 13, 2026
…#7908)

When the whole-group requirement was relaxed (becee62), the Triton quant
path lost the check that kept next_power_of_2(n_half) >= quant_block_size.
The Gluon branch still asserts BLOCK_SIZE_N % quant_block_size == 0, but
the Triton branch had no equivalent, so a row narrower than one quant
group reached _fp8_quant_op with
NUM_QUANT_BLOCKS = BLOCK_SIZE_N // QUANT_BLOCK_SIZE == 0 and a reshape
targeting 0 elements against a non-empty tile, instead of the clean
AssertionError both backends raised before.

The hole is exactly n_half <= quant_block_size / 2 (e.g. n_half = 32 or
64 at the default quant_block_size = 128): the Triton tile is
next_power_of_2(n_half), so it is narrower than one group there.

Hoist the divisibility assert above the backend branch under HAS_QUANT so
it covers the Triton tile (next_power_of_2(n_half)); keep the Gluon
branch's own assert and its no-quant min clamp, since Gluon may override
BLOCK_SIZE_N from its config. Add a regression test asserting both
backends raise cleanly at n_half = 32 and 64 with quant_block_size = 128.

Follow-up to #7489.

Co-authored-by: karverma-amd <[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.

5 participants