You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Faster dynamic_per_group_scaled_quant on gfx1250 for MX (e8m0) scales, groups 32 and 128, bf16/fp16 -> fp8/fp4. MXFP8 NaN/Inf output is also made the same on every arch. Other architectures keep their existing paths, apart from the MXFP8 NaN rule.
Technical Details
gfx1250, group 128
fp8 from bf16: each 128B group row is written by one full store; paired groups exchange halves over DPP.
fp4: interleaved 32B load chunks under column-major group order.
Shuffled (transposed) e8m0 scales are gathered per block in LDS and stored as words.
The generic path drops TDM staging.
TDM tile path (16x512 tiles, one 128-thread block per tile), now for both fp8 and fp4. It replaces AITER_DPGSQ_D01_TUNING with one shape rule:
M a multiple of 16 and N a multiple of 512;
at least one tile per SIMD;
at most 1/8 of the launched blocks are padding. The scale-major tile axis is padded to a multiple of 8 so each XCD owns whole 256B spans of the scale output.
fp4 tiles are staged as two full-width half tiles (8 rows x 512) instead of two half-width ones. An fp4 tile row is exactly one 256B output line, so each store writes whole lines. Half-line (128B) writes made L2 fill every line from DRAM before merging. At 4096x7168 the change cuts DRAM reads by 20% (now equal to a pure stream kernel) and write requests by 74%.
bf16 on gfx1250 (fp8 and fp4, tiled or not) uses a packed amax: a signed and an unsigned 16-bit max chain over the raw bits, falling back to the NaN-skipping fp32 reduction when a NaN is present.
The 7168-only env path (direct_prefetch) is removed.
fp16 -> fp8 e8m0 uses the native v_cvt_scalef32_pk8_fp8_f16 convert, as bf16 already did.
bf16/fp16 -> fp4 uses the native v_cvt_scalef32_pk8_fp4_{bf16,f16}: eight values per instruction instead of widening to fp32 and converting two at a time.
gfx1250, group 32
Each 32x8 MX scale tile is staged in LDS and stored as sixteen aligned writes.
An fp4 tile block covers two scale tiles along the row.
The tile path is gated on tile count; below the gate, the generic kernel is faster.
Dispatch
The gfx1250 check and CU count are cached per device (SynchronizedCache), so a mixed-arch process never launches the gfx1250-only grids on another arch.
MXFP8 NaN/Inf (all archs, all layouts including scale_layout_m32k4)
The rule is what gfx1250's native convert writes; gfx942/gfx950 follow it in software.
MXFP8 NaN / Inf semantics
The behavior is now the same on gfx942, gfx950 and gfx1250, and for bf16 and fp16 input:
NaN: NaN elements stay NaN (0xFF; 0x80 on FNUZ) and are skipped by the group amax, so the rest of the group quantizes normally.
Inf: a group holding an Inf gets the largest finite e8m0 scale, 0xFE (2^127). Its Inf converts to an FP8 NaN, and its finite elements are divided by 2^127 as usual, so ordinary values become 0 while a finite 2^127 beside the Inf becomes 1. This matches the DeepGEMM / vLLM torch reference. It costs one v_min_f32 on the scale and shows no measurable perf change on gfx942, gfx950 or gfx1250.
main was inconsistent here. On bf16 it saturated Inf to +448 with scale 0xF6, while fp16 gave scale 0xFF and turned +Inf into -448.
The NaN sign that an Inf converts to differs by arch (0x7F on gfx1250, 0xFF on gfx950). Both are e4m3fn NaN encodings, so the tests treat them as equal.
On gfx942/gfx950 the convert is v_cvt_pk_fp8_f32 without the med3 clamp. The RoundUp scale keeps finite values in range, and unclamped NaN converts to NaN.
The division by the scale is a v_ldexp_f32 by minus its exponent, not a multiply by 1/scale: 1/2^127 is an fp32 denormal that -fgpu-flush-denormals-to-zero flushes to 0, which would quantize a finite 2^127 next to an Inf as 0 instead of 1. This applies to the generic, m32k4 and fused-MoE software paths and is within noise on gfx942/gfx950 (gfx942: 0.994 / 0.995 geomean over 150 cold group-32/128 and 504 test_quant group-128 cases; gfx950: 0.998 on shapes above 15 us, smaller ones within run-to-run noise).
There is no per-thread detection and no branch.
Known exception: on gfx9, v_max_f32 returns a quieted sNaN operand, so a bf16 sNaN restarts the amax. fp16 sNaN is quieted by its convert. main behaves the same way, and the test skips this case on gfx9.
On gfx942/gfx950, for bf16 input with an sNaN, MXFP4 and fp32-scale per-group results now differ from main: gfx9's v_max_f32 restarted the amax at a bf16 sNaN, dropping the larger values before it. All other inputs are byte-identical to main for MXFP4.
Test Plan
python3 op_tests/test_quant.py, which includes fp8_1x128_e8m0, fp8_1x32_e8m0, fp4_1x128_e8m0 and fp8_mx_nonfinite:
Byte-exact fp8/fp4 data and scales against a torch reference, covering shuffled and plain scales, strided input, odd M, the group-32 / group-128 tile paths, and m32k4.
Dispatch predicates are asserted (mirroring the host gates), so each special path is actually exercised.
MXFP8 non-finite cases: NaN, +-Inf, mixed, all-NaN, sNaN, and large finite values. Group 32/64/128 x shuffle x bf16/fp16, checked against an OCP/FNUZ reference.
A BF16 Inf next to the finite 2^127 (scale 0xFE, 2^127 -> 1) on the generic group-32/128, m32k4 and fused-MoE paths.
Test Result
gfx1250: all of test_quant.py passes on the final commit.
gfx950 (MI355X), gfx942 (MI308X): all of test_quant.py passes. The Inf + 2^127 cases fail on the previous head (0/12 on both) and pass with the ldexp division (12/12).
NaN/Inf probe (936 cases, fp8 and fp4): the last commit is byte-identical to the previous one; fp4 is byte-identical to main.
An extra 512-case NaN/Inf probe is byte-exact on gfx1250. On gfx950 and gfx942 the only differences are the 4 bf16 sNaN cases above.
fp4 e8m0 runs only on gfx950 and gfx1250, which have the packed fp4 convert.
Performance vs main
Timed the way test_quant.py does (run_perftest, inputs rotated so caches are cold), main and this PR in alternating processes on an idle GPU, median of the rounds; ratio = this PR / main, below 1 is faster.
gfx1250, bf16 input, group 128, us (4 interleaved rounds):
Shape
fp8, no shuffle
fp8, shuffle
fp4, no shuffle
fp4, shuffle
1536x7168
5.40 → 4.37 (0.809)
5.59 → 4.52 (0.809)
5.56 → 4.13 (0.744)
6.82 → 4.16 (0.611)
1536x16384
9.73 → 7.09 (0.729)
9.62 → 7.16 (0.745)
9.22 → 6.45 (0.700)
11.81 → 6.64 (0.563)
1536x18432
10.38 → 7.66 (0.738)
10.76 → 7.77 (0.722)
9.77 → 6.87 (0.703)
12.98 → 7.05 (0.543)
8192x1536
5.77 → 5.07 (0.878)
6.07 → 5.01 (0.826)
5.87 → 4.71 (0.802)
7.35 → 4.92 (0.670)
16384x7168
36.43 → 22.70 (0.623)
37.26 → 21.52 (0.577)
32.22 → 18.89 (0.586)
36.62 → 19.03 (0.520)
16384x16384
79.63 → 51.07 (0.641)
80.16 → 49.93 (0.623)
70.28 → 41.43 (0.590)
81.58 → 46.28 (0.567)
16384x18432
88.70 → 57.08 (0.644)
90.02 → 56.74 (0.630)
78.38 → 46.15 (0.589)
92.48 → 48.68 (0.526)
Geomean over this table: fp8 0.723 (plain) / 0.722 (shuffled), fp4 0.696 / 0.670. Tiled fp4 now uses the packed bf16 amax as well: the later group-32 / single-step tile commit reworked it into a signed and an unsigned 16-bit max chain and enabled it for all bf16 on gfx1250, and its cold-cache A/B against main (208 cases, G128 fp4 0.709) reported no slower case. For the small-M shapes, a stream kernel under the same cold, gapped launches takes 4.3 / 6.4 / 6.9 us (fp4) and 4.6 / 7.1 / 7.9 us (fp8) at 1536 x 7168 / 16384 / 18432. This PR is within 3-8% of that floor.
Broader sweeps (the default e8m0 list plus M 64-16384 x N 1536-18432; bf16/fp16 x shuffled/plain x contiguous/strided):
Arch
Group 128 fp8
Group 128 fp4
gfx1250
0.851 (504 cases)
0.940 (504), before the fp4 tile path
gfx950
0.972 (504)
0.989 (504)
gfx942
0.987 (160 cases, M 256-2048)
-
On gfx1250 the last commit (fp4 tile path, new tile gate, pk8 fp4 convert) was A/B'd against the previous commit on 30 shapes: fp4 geomean 0.90 (plain) / 0.92 (shuffled), fp8 0.96 / 0.98, with no case slower beyond noise. 16384 x 18432 fp4 goes 56.8 -> 49.9 us from the whole-line stores alone.
Group 32, gfx1250, us:
Shape (M x N)
Config
main
this PR
16384 x 7168
bf16 -> fp8, shuffled
66.4
31.3
32768 x 1536
bf16 -> fp8, shuffled
26.6
14.4
(Group 32 is not timed by test_quant.py; those rows use the same run_perftest(fn, out, x, scale, ...) call.)
Known regressions
gfx942, fp8 shuffled, 256-1024 rows: 2-4% (1024x4096 fp16: 10.12 -> 10.51 us; 256x16384 bf16: 9.49 -> 9.77 us). The kernel is main's with the med3 clamp dropped (651 vs 731 instructions, same loads, stores and control flow, 2 fewer VGPRs). The shorter kernel changes how its scattered scale-byte stores line up. Plain scales are unaffected. Store-reordering workarounds helped some shapes and hurt others, so they were left out.
gfx1250, fp4 plain: up to 1.7% (0.04-0.13 us) on a few mid shapes off the tile path.
gfx950: nothing outside run-to-run noise (single runs vary +-10% around 10 us; 10-round medians within 1-3%).
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 5985 --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.
Tile-rule comment conflicts with dispatch and listed shapes
op_tests/test_quant.py:206
This comment's tile rule is inconsistent with both the listed 7168 shapes and the dispatch, which permits 512-column multiples from 7168. Keeping the old rule here makes it unclear which entries actually exercise TDM.
Add large gfx1250 BF16 nonfinite test for packed path
csrc/kernels/quant_kernels.cu:318
The nonfinite tests never exercise this packed-BF16 branch: test_mxfp8_nonfinite uses at most 1,024 columns, while packed_bf16_amax is enabled only by the tiled launch gated on cols >= 7168. A regression in the new NaN/Inf folding through TDM and wide stores would therefore pass the suite. Add a gfx1250 BF16 nonfinite case large enough to satisfy the tiled dispatch threshold.
The Test Plan points reviewers to op_tests/test_dynamic_per_group_quant_e8m0.py, but that file does not exist; these checks were added here instead. Update the PR description to name op_tests/test_quant.py so the stated validation command/path is reproducible.
Comment misstates shapes using the tiled dispatch path
op_tests/test_quant.py:273
This comment repeats the obsolete TDM rule and conflicts with the dispatch below: the kernel also tiles 512-aligned widths from 7168 using a three-tiles-per-SIMD threshold. As written, it misstates which shapes in this list exercise the tiled path.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The gfx1250 TDM/DPP/LDS paths and cross-architecture MXFP8 non-finite semantics need independent GPU correctness and performance validation, which this source-only review could not perform.
Negative history positions in the first overlapping CSA window can read
stale NaN/Inf state. Masking their scores gives zero probability, but
zero times a non-finite KV value still contaminates the compressed output.
Zero padded KV values in both the single-wave and K-split state-cache
loads. Preserve NaN propagation from valid history.
Add BF16 and group-FP8 regression coverage across wave counts and plan
capacities, including poisoned padding and valid-history NaNs.
Validation: 18 GPU regression cases pass on gfx950. With the original
no-clamp quantization, full DSV4-Pro DSpark GSM8K recovers from 12.51%
to 95.68% (1262/1319), with zero empty responses.
Run the poisoned-padding and valid-history NaN regression cases from
the existing compressor test entry point on gfx950. Remove the separate
pytest file so the checks run with the normal CSA Main test suite.
Validation: all 18 cases pass through the existing CLI; Black and Ruff
pass. The compressor kernel is unchanged.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because an unpublished moderate-severity finding indicates that unmasked NaN/Inf padding can contaminate gfx1250 outputs at the first compression boundary.
Skip negative-history state iterations in the K-split compressor while
retaining the padding KV mask in the single-wave path. Disable input
prefetch for the short CSA Main group-FP8 single-wave window.
Extend the existing compressor regression to cover partially valid and
all-state windows, including empty K-split waves and valid-history NaNs.
Validation: existing GPU tests and 84 paired kernel cases pass; finite
benchmark outputs are byte-identical to the original kernel. Full
DeepSeek-V4-Pro DSpark GSM8K passes at 94.92% (1252/1319), with no empty
responses. Long paired microbenchmarks remove the prior group-FP8
prefill regression; a small FP4 case retains a 0.7% increase (~0.02 us).
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The cache comparison bypasses the required checkAllclose helper and its shared mismatch diagnostics, so it should use the expected tensor as the second argument and assert a zero error ratio.
Focused re-review, unchanged head 719c5e4: no remaining code blocker in the scoped quantization checks. Generic, m32k4, and fused-MoE use denormal-safe scaling with Inf + 2^127 coverage; default FP4 e8m0 is gfx950/gfx1250-only; the PR description and tiled-FP4 amax wording are corrected. MI35X quant validation and required CI pass. The same three ATOM accuracy jobs remain failed; please triage/rerun them or provide a same-head baseline comparison before merge.
dsv4-pro failed as nan exposed after the change of no-clamp. Now it is fixed in #7550
Resolve overlapping CSA padding fixes while retaining the validated
K-split negative-history skip and single-wave input-prefetch policy.
Keep both the existing padding-state regression and upstream CSA/HCA
masked-NaN regression in the original test entry point.
Validated the merged compressor tests on MI355X/gfx950, including
padding, masked-NaN, decode/prefill, and FP8/FP4 K-split cases.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The regression comparison at line 924 uses torch.testing.assert_close instead of the required checkAllclose helper, bypassing shared mismatch diagnostics and needing an update that preserves strict per-element tolerance.
Resolve compressor dispatch and test conflicts with upstream FP4 OPUS support. Keep padding and K-split fixes and both regression suites. Remove the PR-specific CSA Main prefetch override so dispatch uses the existing default.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The new FlyDSL reference comparison bypasses the required shared checker and its standard mismatch diagnostics, so it should use the shared comparison path while preserving zero-mismatch strictness.
Make LDS scale runs use block-derived bounds and handle zero dynamic rows.
Add dynamic-row, alignment and canary regression coverage, include string_view
directly, and cover gfx1250-strict in the quant test gates. Clarify exponent
extraction and FP8 NaN documentation.
Restore compressor code and tests to main for a separate follow-up PR.
Validation: gfx950 group-128 FP8/FP4, BF16/FP16 and MX nonfinite suites
passed, including 80 dynamic-row/alignment cases; Black, Ruff and diff checks
passed. gfx1250-specific runtime validation remains pending.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The gfx1250 TDM/DPP/LDS paths and native FP8/FP4 conversions require GPU correctness and performance validation, but no head-bound runtime report is supplied and this source-only review cannot independently verify the PR’s claims.
Remove the optional block-derived scale rewrite, zero-row early return and their added dynamic-row tests. Retain the direct string_view include, gfx1250-strict test gates, exponent mask and docstring corrections.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Architecture-specific TDM/LDS paths and native FP8/FP4 conversions require independent, head-matched GPU correctness and performance validation that could not be reproduced in this source-only review environment.
… on gfx942
The coverage shapes are picked for the full 256-CU gfx1250. On a partitioned or
smaller part the check asserted and stopped test_quant.py before the group-32 and
non-finite cases; it now logs and skips there, and every case still runs.
The m32k4 NaN / Inf patterns move to the block that also runs on gfx942.
Validation: test_quant.py passes on gfx1250; Black and Ruff pass.
Co-authored-by: Cursor <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The new gfx1250 TDM/DPP paths, packed conversions, and cross-architecture MXFP8 semantics require GPU correctness and performance validation that this source-only review cannot reproduce, with no head-matched validation report supplied.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Faster
dynamic_per_group_scaled_quanton gfx1250 for MX (e8m0) scales, groups 32 and 128, bf16/fp16 -> fp8/fp4. MXFP8 NaN/Inf output is also made the same on every arch. Other architectures keep their existing paths, apart from the MXFP8 NaN rule.Technical Details
gfx1250, group 128
AITER_DPGSQ_D01_TUNINGwith one shape rule:direct_prefetch) is removed.v_cvt_scalef32_pk8_fp8_f16convert, as bf16 already did.v_cvt_scalef32_pk8_fp4_{bf16,f16}: eight values per instruction instead of widening to fp32 and converting two at a time.gfx1250, group 32
Dispatch
SynchronizedCache), so a mixed-arch process never launches the gfx1250-only grids on another arch.MXFP8 NaN/Inf (all archs, all layouts including
scale_layout_m32k4)The rule is what gfx1250's native convert writes; gfx942/gfx950 follow it in software.
MXFP8 NaN / Inf semantics
The behavior is now the same on gfx942, gfx950 and gfx1250, and for bf16 and fp16 input:
v_min_f32on the scale and shows no measurable perf change on gfx942, gfx950 or gfx1250.main was inconsistent here. On bf16 it saturated Inf to +448 with scale 0xF6, while fp16 gave scale 0xFF and turned +Inf into -448.
The NaN sign that an Inf converts to differs by arch (0x7F on gfx1250, 0xFF on gfx950). Both are e4m3fn NaN encodings, so the tests treat them as equal.
v_cvt_pk_fp8_f32without the med3 clamp. The RoundUp scale keeps finite values in range, and unclamped NaN converts to NaN.v_ldexp_f32by minus its exponent, not a multiply by1/scale:1/2^127is an fp32 denormal that-fgpu-flush-denormals-to-zeroflushes to 0, which would quantize a finite 2^127 next to an Inf as 0 instead of 1. This applies to the generic, m32k4 and fused-MoE software paths and is within noise on gfx942/gfx950 (gfx942: 0.994 / 0.995 geomean over 150 cold group-32/128 and 504 test_quant group-128 cases; gfx950: 0.998 on shapes above 15 us, smaller ones within run-to-run noise).Known exception: on gfx9,
v_max_f32returns a quieted sNaN operand, so a bf16 sNaN restarts the amax. fp16 sNaN is quieted by its convert. main behaves the same way, and the test skips this case on gfx9.On gfx942/gfx950, for bf16 input with an sNaN, MXFP4 and fp32-scale per-group results now differ from main: gfx9's v_max_f32 restarted the amax at a bf16 sNaN, dropping the larger values before it. All other inputs are byte-identical to main for MXFP4.
Test Plan
python3 op_tests/test_quant.py, which includesfp8_1x128_e8m0,fp8_1x32_e8m0,fp4_1x128_e8m0andfp8_mx_nonfinite:Test Result
test_quant.pypasses on the final commit.test_quant.pypasses. The Inf + 2^127 cases fail on the previous head (0/12 on both) and pass with the ldexp division (12/12).Performance vs main
Timed the way
test_quant.pydoes (run_perftest, inputs rotated so caches are cold), main and this PR in alternating processes on an idle GPU, median of the rounds; ratio = this PR / main, below 1 is faster.gfx1250, bf16 input, group 128, us (4 interleaved rounds):
Geomean over this table: fp8 0.723 (plain) / 0.722 (shuffled), fp4 0.696 / 0.670. Tiled fp4 now uses the packed bf16 amax as well: the later group-32 / single-step tile commit reworked it into a signed and an unsigned 16-bit max chain and enabled it for all bf16 on gfx1250, and its cold-cache A/B against main (208 cases, G128 fp4 0.709) reported no slower case. For the small-M shapes, a stream kernel under the same cold, gapped launches takes 4.3 / 6.4 / 6.9 us (fp4) and 4.6 / 7.1 / 7.9 us (fp8) at 1536 x 7168 / 16384 / 18432. This PR is within 3-8% of that floor.
Broader sweeps (the default e8m0 list plus M 64-16384 x N 1536-18432; bf16/fp16 x shuffled/plain x contiguous/strided):
On gfx1250 the last commit (fp4 tile path, new tile gate, pk8 fp4 convert) was A/B'd against the previous commit on 30 shapes: fp4 geomean 0.90 (plain) / 0.92 (shuffled), fp8 0.96 / 0.98, with no case slower beyond noise. 16384 x 18432 fp4 goes 56.8 -> 49.9 us from the whole-line stores alone.
Group 32, gfx1250, us:
(Group 32 is not timed by
test_quant.py; those rows use the samerun_perftest(fn, out, x, scale, ...)call.)Known regressions
Submission Checklist