Skip to content

[FlyDSL] mxfp8 activation quantizer for the decode GEMM tiers: (16, 16) code layout + shuffled E8M0 scales - #8606

Closed
ganyi1996ppo wants to merge 3 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/mxfp8-quant-shuffled
Closed

ganyi1996ppo wants to merge 3 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/mxfp8-quant-shuffled

Conversation

@ganyi1996ppo

Copy link
Copy Markdown
Contributor

Summary

gfx950 FlyDSL MXFP8 activation quantizer for the decode MXFP8 GEMM tiers: bf16 [M, K] -> fp8 e4m3 codes in the weight's (16, 16) preshuffled layout (rows padded to the row tile, padding rows zero) + E8M0 scales in AITER's shuffled layout (shuffle_scale_a16w4), or row-major codes (shuffled=False). One launch, a workgroup per 32-row x 256-K tile. Prerequisite of the one-launch QKV front chain in the next PR (stacked on this one), which reads exactly these codes.

Stacked on #8576 (only the top commit is this PR). Technique source: amd-kernels gemm/mxfp8_common/mxfp8_quant.py and the scale/convert helpers of mxfp8_gemm_decode.py (ported, credited in the file header, no import).

Why a quantizer PR on its own

It has no end-to-end effect by itself: it is the producer of the layout the chain kernel needs (a row-major quantizer cannot feed it). Cost vs the quantizer the public path uses today, graph replay with 8 rotated activations, MI355X, K=6144, us per call (aiter per_group_quant_hip / this kernel): M16 3.94 / 3.68, M24 3.75 / 3.67, M32 3.83 / 3.66, M48 3.85 / 3.94, M64 3.81 / 3.92, M96 3.81 / 4.00, M128 3.89 / 4.05 (parity, +-0.2 us). The gain is measured on the stack in the next PR.

Test

op_tests/test_flydsl_mxfp8_quant_shuffled.py (pytest, gfx950): codes and scales compared byte for byte against a torch reference of the Triton MXFP8 rule (scale byte clamp(ceil(log2(amax/448))+127) from the bf16 pattern of the group max, RNE e4m3, permutation into the (16, 16) layout, shuffle_scale_a16w4), M in {1,5,8,16,17,24,33,48,64,96,100,128}, K in {6144, 2048}, four magnitudes (0.01 .. 3000), zero rows/blocks. Also compared against the amd-kernels quantizer on 15 row counts x 4 magnitudes during development: bit-identical.

Review

By-hand pass over the repo's review-pr rules (triage of A1/A4, B2, C1/C2, D1/D8, P1-P6, HK6/HK12, siblings, guards, FlyDSL bounds): no runtime-surface change to existing ops (new module only), buffer resources are sized from the runtime row counts, pytest-collectable test in op_tests/, no env knobs, no print. P6: base-vs-head timing is the table above; the end-to-end measurement is in the stacked PR.

Co-authored with Claude Code.

🤖 Generated with Claude Code

ganyi1996ppo and others added 2 commits November 24, 2026 07:45
…Max-M3 TP4 prefill

Same bytes as the HIP kernel, 1.6-3.0x faster on device and 3.5x less host time per
call for calls of at least 1024 tokens (nvfp4 K/V/index-K, 16/1/1 heads, rotary 64,
gfx950). Ported from amd-kernels. AITER_FUSED_QKNORM_NVFP4_FLYDSL=0 keeps the HIP kernel.

Co-Authored-By: Claude <[email protected]>
…6) code layout + shuffled E8M0 scales

gfx950 FlyDSL quantizer: bf16 [M, K] -> fp8 e4m3 codes in the weight's (16, 16) preshuffled layout (rows padded to the row
tile, padding rows zero) plus E8M0 scales in AITER's shuffled layout, or row-major codes. One launch, a workgroup per
32-row x 256-K tile. Prerequisite of the one-launch QKV front chain (next PR): that kernel reads exactly these codes.

Technique source: amd-kernels gemm/mxfp8_common/mxfp8_quant.py and the scale/convert helpers of mxfp8_gemm_decode.py
(ported, no import). op_tests/test_flydsl_mxfp8_quant_shuffled.py compares codes and scales byte for byte against a torch
reference of the Triton MXFP8 rule (60 shape/magnitude cases).

Co-Authored-By: Claude <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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 Radeon R9700 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 8606 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@aiter-bot

aiter-bot commented Nov 24, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 93e027838156 · 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. What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  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 — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_flydsl_mxfp8_quant_shuffled.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_fused_qknorm_nvfp4_flydsl.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

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

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 quantizer can read out of bounds for rpw=4 and reuse device-bound handles across GPUs, risking incorrect outputs, while CI skips all 24 regression test cases.

5 open issues
What changed in this PR

Adds a gfx950 FlyDSL MXFP8 activation quantizer that produces the layouts needed by the upcoming decode QKV chain. This PR is stacked on #8576; the supplied diff also includes that prerequisite’s NVFP4 insert work.

Changes:

  • Quantizes BF16 activations into FP8 codes with either row-major or (16, 16) preshuffled layout, plus shuffled E8M0 scales.
  • Adds byte-exact reference tests across row counts, widths, magnitudes, and padding cases.
  • Includes the stacked NVFP4 insert kernels, public dispatch, and comparison tests.
File Description
op_tests/​test_fused_qknorm_nvfp4_flydsl.py Stacked NVFP4 correctness and performance tests.
op_tests/​test_flydsl_mxfp8_quant_shuffled.py Byte-exact quantizer and layout comparisons.
aiter/​ops/​fused_qknorm_idxrqknorm.py Stacked FlyDSL NVFP4 dispatch with HIP fallback.
aiter/​ops/​flydsl/​kernels/​mxfp8_quant_shuffled.py MXFP8 quantization kernel and launch wrappers.
aiter/​ops/​flydsl/​kernels/​fused_qknorm_idxr_nvfp4_insert.py Stacked fused norm, RoPE, and NVFP4 insert kernel.
aiter/​ops/​flydsl/​kernels/​fused_qknorm_idxr_nvfp4_insert_prefill.py Stacked prefill-optimized NVFP4 insert variant.

Review effort: Balanced

@pytest.mark.skipif(get_gfx_runtime() != "gfx950", reason="gfx950 only")
@pytest.mark.parametrize("k", [6144, 2048])
@pytest.mark.parametrize("m", [1, 5, 8, 16, 17, 24, 33, 48, 64, 96, 100, 128])
def test_quant_shuffled(m, k):
…er-device compiled handle + x.device stream, whole-tile rule for rpw>2, op test entry point

Co-Authored-By: Claude <[email protected]>
@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

Review fixes pushed (93e0278, fast-forward):

  • bf16/contiguity (real): quantize() rejects non-bf16 or non-contiguous input before the byte views.
  • Device handles (real): the compiled handle is keyed per device (specialization_key) and launched under x.device with its current stream.
  • rpw=4 scalar-offset read (real only off the default path): mxfp8_quantize_shuffled always uses rpw=2, whose j loop is a single iteration; the rpw>2 paths now require M padded to whole 32-row tiles (ValueError otherwise) instead of reading past X.
  • CI entry point (real): the op test file now runs under pytest from python3 <file>, plus a test for the new rejections. Tests: 24 + new cases pass on gfx950.
  • @benchmark/run_perftest harness: not done in this PR (kernel timing is in the description); will follow if wanted.

ganyi1996ppo added a commit to ganyi1996ppo/aiter that referenced this pull request Nov 24, 2026
ganyi1996ppo added a commit to ganyi1996ppo/aiter that referenced this pull request Nov 24, 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.

🟡 Changes recommended

Missing output-buffer validation permits out-of-bounds writes, while absent architecture gating and a scale-rounding mismatch leave additional correctness issues unresolved.

2 open issues
3 previously missed issues

In code that hasn't changed since last review

Medium severity Align or document MXFP8 scale rounding at mantissa boundaries

aiter/​ops/​flydsl/​kernels/​mxfp8_quant_shuffled.py:65

The claimed byte equivalence with AITER's Triton MXFP8 scale rule fails at the mantissa boundary: bf16 amax=448 produces scale byte 127 here, but _mxfp8_quant_op in aiter/ops/triton/_triton_kernels/quant/quant.py:851-858 produces 128. Document this different rounding contract in the kernel and test descriptions, or align the implementation with the existing rule and add a boundary comparison.

Medium severity Reject unsupported architectures before compilation or launch

aiter/​ops/​flydsl/​kernels/​mxfp8_quant_shuffled.py:295

Could you reject unsupported architectures at this entry point? A contiguous bf16 [16, 256] input on gfx942 passes the current validation and reaches the gfx950-only cvt_scalef32_pk_fp8_bf16 path. Neither this function nor its allocating wrapper has a runtime architecture gate; skipping the numerical test on other cards does not protect callers. Use get_gfx_runtime() to reject non-gfx950 calls before compiling or launching.

Low severity Replace legacy buffer_ops and raw LDS handling

aiter/​ops/​flydsl/​kernels/​mxfp8_quant_shuffled.py:171

This new kernel introduces the legacy buffer_ops memory path, including raw LLVM LDS pointer handling below. aiter/ops/flydsl/AGENTS.md:30-35 explicitly reserves buffer_ops for older kernels and requires new code to use FlyDSL buffer tensors and fx.copy; raw operations need a documented missing/slower stable API backed by evidence. Please migrate the buffer/LDS path to those APIs, retaining only instruction-specific boundaries with the required justification, so this module does not add another legacy implementation to maintain.

4 resolved since last review

Review effort: Balanced

Comment on lines +300 to +306
if rpw > 2 and m != scale.shape[0]:
# the scalar-offset row loads of the rpw > 2 paths are not bounds-checked against X: whole 32-row tiles only
raise ValueError(
f"rpw {rpw} needs M padded to whole 32-row tiles, got M {m}, tile rows {scale.shape[0]}"
)
exe = _launcher(k, shuffled, rpw)
n_tiles = (scale.shape[0] // 32) * (k // 256)
@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

Withdrawn: the QKV front now reads plain row-major activation codes from the existing per_group_quant_hip quantizer, so this (16,16)-layout quantizer has no consumer (measured: the layout gained only 0.1-1.4 us per front and needed separate A-shuffle support). Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants