Skip to content

[Triton/Gluon] Add gluon support for MXFP4 and MXFP8 quant kernel in gfx950 - #4383

Merged
azaidy merged 59 commits into
mainfrom
quant_mxfp4_gfx950_1250
Oct 5, 2026
Merged

azaidy merged 59 commits into
mainfrom
quant_mxfp4_gfx950_1250

Conversation

@NimitPtl

@NimitPtl NimitPtl commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Using gluon instead of triton for performance improvement

Technical Details

  • Current implementation of quantization in triton has a software emulation of the same.
  • Utilize the hardware implementation in gluon to speed up the process.
  • The layout heuristic has been modified to better suite the shapes we need to process.
  • Implement pre-fetch for certain layouts in gluon.
  • Changes are all related to gluon. Triton remain same as before.

Test Plan

Test suite as well as benchmark script for speed of quant kernel. Test script for verifying accuracy.

Test Result

Focusing on MoE layers for GPTOSS and DSR1

Gluon gives positive numbers compared to triton.

Triton vs Gluon (gfx950) — mxfp4, bf16 input:

M N triton (ms) triton (GB/s) gluon (ms) gluon (GB/s) speedup
8 1024 0.0030 6.8 0.0029 7.2 1.05x
32 1024 0.0035 23.8 0.0030 27.8 1.17x
256 1024 0.0035 188.7 0.0031 216.6 1.15x
2048 1024 0.0045 1170.0 0.0037 1420.9 1.21x
8192 1024 0.0088 2421.5 0.0068 3102.0 1.28x
16384 1024 0.0157 2702.0 0.0109 3894.4 1.44x
geomean 1.21x
8 3072 0.0035 17.9 0.0030 20.4 1.14x
32 3072 0.0035 71.4 0.0030 82.0 1.15x
256 3072 0.0056 353.7 0.0031 648.8 1.83x
2048 3072 0.0089 1782.6 0.0064 2506.0 1.41x
8192 3072 0.0193 3305.7 0.0146 4365.2 1.32x
16384 3072 0.0342 3724.8 0.0268 4753.0 1.28x
geomean 1.34x
8 7168 0.0035 41.8 0.0031 47.6 1.14x
32 7168 0.0035 163.6 0.0030 192.3 1.18x
256 7168 0.0060 779.5 0.0034 1347.8 1.73x
2048 7168 0.0143 2591.4 0.0105 3544.6 1.37x
8192 7168 0.0385 3859.0 0.0302 4923.5 1.28x
16384 7168 0.0711 4180.1 0.0535 5555.9 1.33x
geomean 1.32x
overall 1.29x

Triton vs Gluon (gfx950) — mxfp8, bf16 input, float8_e4m3fn:

M N triton (ms) triton (GB/s) gluon (ms) gluon (GB/s) speedup
8 1024 0.0030 8.4 0.0019 13.2 1.57x
32 1024 0.0029 34.0 0.0025 39.8 1.17x
256 1024 0.0030 266.4 0.0029 273.1 1.03x
2048 1024 0.0042 1515.5 0.0041 1562.9 1.03x
8192 1024 0.0098 2597.8 0.0071 3588.6 1.38x
16384 1024 0.0158 3217.2 0.0114 4470.5 1.39x
geomean 1.24x
8 3072 0.0029 25.3 0.0030 24.9 0.99x
32 3072 0.0029 101.2 0.0030 99.2 0.98x
256 3072 0.0031 763.0 0.0031 762.4 1.00x
2048 3072 0.0060 3160.4 0.0059 3209.3 1.02x
8192 3072 0.0142 5367.6 0.0164 4649.1 0.87x
16384 3072 0.0257 5931.9 0.0294 5197.3 0.88x
geomean 0.95x
8 7168 0.0032 54.7 0.0031 56.5 1.03x
32 7168 0.0032 218.0 0.0031 226.7 1.04x
256 7168 0.0041 1361.8 0.0037 1510.6 1.11x
2048 7168 0.0099 4498.7 0.0111 4013.3 0.89x
8192 7168 0.0307 5796.6 0.0333 5338.2 0.92x
16384 7168 0.0614 5794.6 0.0606 5875.7 1.01x
geomean 1.00x
overall 1.06x

Submission Checklist

@NimitPtl
NimitPtl requested a review from a team July 24, 2026 20:44
@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:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
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 4383 --add-label <label>

@NimitPtl

Copy link
Copy Markdown
Contributor Author

#4193 is the parent PR.
Creating a new one to rebase the code off of correct branch.

@NimitPtl NimitPtl self-assigned this Jul 24, 2026
@NimitPtl
NimitPtl marked this pull request as draft July 24, 2026 22:27
@NimitPtl
NimitPtl marked this pull request as ready for review July 27, 2026 18:50
@zufayu
zufayu requested a review from vgokhale August 5, 2026 02:48
@NimitPtl
NimitPtl requested review from azaidy and cagrikymk August 7, 2026 19:53
NimitPtl and others added 6 commits August 16, 2026 03:24
Added pre fetch
slight modification in bench script
…push-hw-cvt

# Conflicts:
#	aiter/ops/triton/_gluon_kernels/gfx950/quant/quant.py
#	aiter/ops/triton/quant/quant.py
#	op_tests/op_benchmarks/triton/bench_quant_mxfp4.py
@github-actions github-actions Bot changed the title [TRITON] Add gluon support for MXFP4 quant kernel in gfx950 and gfx1250 [Triton/Gluon] Add gluon support for MXFP4 quant kernel in gfx950 and gfx1250 Aug 18, 2026
…ler team, now successfully uses the correct instruction
cagrikymk
cagrikymk previously approved these changes Sep 29, 2026
…e mid-M configs

- Drop the Python BLOCK_SIZE_M/N overrides in dynamic_mxfp4_quant and
  dynamic_mxfp8_quant; launch configs now come only from the JSON tables.
- Tune the 33<=M<=1024 buckets (more, smaller CTAs) for MXFP4 and MXFP8.
- Compute e8m0 scale bias in int32 before narrowing to uint8.
@NimitPtl
NimitPtl requested a review from azaidy September 30, 2026 19:59
NimitPtl and others added 9 commits September 30, 2026 20:05
Replace lookup_tuned_config with lookup_config(table, axes, **values) and
drop the "schema" key from the gfx950 mxfp4/mxfp8 JSON tables.
…ig, backend argument

- Share the e8m0 scale math (common/utils.py), the tile store and the warp
  layout between the MXFP4 and MXFP8 Gluon kernels.
- Extend select_leq_config to many axes and reject bad calls; add
  get_quant_config and drop lookup_config.
- Add a keyword-only backend argument (None, "triton", "gluon") to
  dynamic_mxfp4_quant and dynamic_mxfp8_quant; the benchmark gets a gluon
  provider and the triton provider forces the Triton kernel.
- Drop unused SCALING_MODE and waves_per_eu=0 from the Gluon launches; add
  num_warps and EVEN_M_N to the kernel repr keys.
- Add CPU-only tests for the config lookup and the Gluon quant JSON tables;
  update the config docs.

@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 b83cf64 into main Oct 5, 2026
@azaidy
azaidy deleted the quant_mxfp4_gfx950_1250 branch October 5, 2026 21:40
NimitPtl added a commit that referenced this pull request Oct 7, 2026
…gfx1250 (#4894)

* Merge branch 'ROCm:main' into quant_mxfp4

* Update bench_quant_mxfp4.py

* Resolve formatting issues

* Resolve formatting issues

* Resolve formatting issues

* Resolve formatting issues

* Resolve typing deprecation and import formatting

* Fix Ruff import and __all__ ordering

* Replace deprecated typing.Tuple in quant module

* Use PEP 604 unions for optional tensor annotations

* Include instruction for mxfp4 qunatization.

* Change hueristic
Added pre fetch
slight modification in bench script

* Consolidate comments and fix formatting/duplicate imports

* Modifying shapes to be tested

* Remove the inline asm part as the test triton patch provided by compiler team, now successfully uses the correct instruction

* Removing unwanted files

* Removing json file

* Migrate gfx950 Gluon mxfp4/mxfp8 quant tuning to JSON configs

Also update mxfp4/mxfp8 quant test files with representative shapes covering the benchmark shape sweep.

* COnfig file format change

* Add MXFP4/MXFP8 gfx950/gfx1250 gluon quant kernels (squashed)

* style: black-format bench_quant_mxfp4_fp8.py

* refactor(quant): switch gfx1250 mxfp4/mxfp8 block-config to JSON rule trees

Replace the hardcoded if/else tuning chains and the flat bucket-key config
lookup with configs/gfx1250/gluon/quant/{quant_mxfp4,quant_mxfp8}/DEFAULT.json
default+rules trees, resolved via config_utils.select_tuned_config. Drops
the now-unused quant_config_utils module.

* fix(quant): pin mxfp4 gfx1250 config lookup to arch=gfx1250

_mxfp4_gfx1250_config's launch config is also reused, unchanged, by the
plain-Triton fallback kernel on non-gfx1250 archs. Without an explicit arch
override, resolve_config_dir defaulted to the running arch, so the config
lookup 404'd on every non-gfx1250 arch (e.g. gfx950), breaking every
dynamic_mxfp4_quant call there -- including the gfx950 stochastic-rounding
tests and downcast_to_mxfp_pow2_scale_fp4.

* fix(quant): remove dead/broken leftover code in _mxfp4_pack_op from main merge

The merge of main introduced main's own refactor splitting _mxfp4_quant_op
into scale computation + a new _mxfp4_pack_op(qx, ...) helper that takes
already-scaled qx. The merge left dead leftover lines inside
_mxfp4_pack_op that referenced an undefined 'x' (not a parameter of this
function) and recomputed an unused scale, causing a NameError at trace
time (flagged by CI as ruff F821/RUF059).

* perf(quant): narrow gfx1250 mxfp8 small-M tile width for K > 1024

For M <= 32, the launch config previously picked BLOCK_SIZE_N purely from
a fixed element budget over BLOCK_SIZE_M, independent of K. Benchmark
sweeps (repeated trials, not single samples) show that for K > 1024 a
narrower 128-wide tile robustly beats the wider budget-derived tile --
more independent CTAs hides TDM latency better than one bigger transfer
per CTA at this size. ~11-13% bandwidth improvement at M=8, K=3072/7168
(closes the largest lag vs the Triton fallback at these shapes).

* refactor(quant): table-based mxfp8 small-M BLOCK_SIZE_N + tighten comments

Replace inline if/else BLOCK_SIZE_N arithmetic for mxfp8's M<=32 branch with an explicit _MXFP8_SMALL_M_BLOCK_SIZE_N lookup table + helper. Also shorten a duplicated multi-line comment in the gluon kernel and condense select_tuned_config's docstring.

* Address PR review comments: bucket-key config lookup, kernel repr, lazy Gluon import, config dir rename, trim redundant test shapes

- Replace the rule-tree select_tuned_config with lookup_tuned_config, a
  flattened bucket-key resolver ({schema, "M_GEQ_33.N_LEQ_16384": {...},
  "any": {...}}) matching unified_attention_utils's existing pattern.
- Add make_kernel_repr-based repr= to both gfx950 Gluon quant kernels.
- Move the gfx950 Gluon kernel imports in quant.py out of the module
  header into the arch-gated dispatch branches that use them.
- Rename configs/gfx950/gluon/quant/{mxfp4,mxfp8}_quant -> {mxfp4,mxfp8}
  to match the sibling PR's naming convention.
- Drop one of three redundant large-non-square shapes from the mxfp4/
  mxfp8 quant parametrize lists.

* fix(quant): address gfx950-PR review feedback applicable to gfx1250

- Replace select_tuned_config's invented default+rules JSON schema with
  the repo's established composite bucket-key format (config_utils.
  lookup_config), matching the pattern used by unified_attention/gemm/
  conv config families. Flattens mxfp4/mxfp8 DEFAULT.json into complete,
  mutually exclusive buckets instead of stacked rules.
- Add repr= (make_kernel_repr) to the two launched gfx1250 gluon kernels
  so tuned specializations are distinguishable in traces/artifacts.
- Make the gluon kernel import lazy, gated behind the gfx1250 arch
  check, matching gemm_a16w16.py's pattern -- importing aiter.ops.triton.
  quant.quant no longer unconditionally pulls in triton.experimental.gluon.
- Rename configs/gfx1250/gluon/quant/{quant_mxfp4,quant_mxfp8} to
  {mxfp4_quant,mxfp8_quant} to align directory naming with the gfx950
  sibling PR (#4383).

* docs(quant): shorten config lookup docstrings and comments

* docs(quant): shorten config lookup and gfx950 kernel comments

* revert(quant): restore _triton_kernels/quant/quant.py to main (drop unneeded fp32-cast removal)

* Update quant.py

* Move gfx950 Gluon quant shape-derived block sizes into JSON and retune mid-M configs

- Drop the Python BLOCK_SIZE_M/N overrides in dynamic_mxfp4_quant and
  dynamic_mxfp8_quant; launch configs now come only from the JSON tables.
- Tune the 33<=M<=1024 buckets (more, smaller CTAs) for MXFP4 and MXFP8.
- Compute e8m0 scale bias in int32 before narrowing to uint8.

* Use lookup_config for gfx950 Gluon quant configs to match the sibling PR

Replace lookup_tuned_config with lookup_config(table, axes, **values) and
drop the "schema" key from the gfx950 mxfp4/mxfp8 JSON tables.

* perf(quant): retune gfx1250 gluon mxfp4/mxfp8 configs; JSON is gluon-only

- Re-tune per-bucket block/warp/buffer configs via the dispatch path with
  cold inputs (old config kept as a candidate); mxfp4 +10.6%, mxfp8 +5.4%
  geomean vs previous gluon configs.
- Move the former in-code shape rules (small M / small N tile sizes) into
  the JSON buckets so the JSON is the single source of block sizes.
- mxfp4: JSON is used only by the gfx1250 gluon launch; the Triton
  fallback is main's original heuristics again.
- mxfp4: fix compile failures for M<=8 at N>1024 and M<=4 (wide BLOCK_SIZE_N
  at tiny BLOCK_SIZE_M) by using BLOCK_SIZE_N=128 tiles there.
- Shorten comments/docstrings across the touched files.

* bench_quant_mxfp4_fp8: match the gfx950 branch (drop duplicate line_vals, original comment)

* gfx1250 quant: shared e8m0 helper, tile helpers, drop dead params, waves_per_eu in JSON, backend tests

* gfx1250 quant: drop unreachable table entries, restore async_store note, add mxfp8 bucket shape

* gfx1250 quant: int64 mxfp8 strides, overlap mxfp4 stores, infer table axes in get_quant_config

* gfx1250 quant: retune mxfp4 bucket table (38 -> 30 keys)

---------

Co-authored-by: Satya Nikhil Kodukula <[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.

6 participants