Repository navigation
Conversation
Preserve the upstream FP32 diagonal inverse and add standalone correlated-key regression coverage for both gate domains.
Replace the BF16 two-component compensation with the existing FP32 MFMA helper. Keep merge operands and intermediate products in FP32 while preserving the upstream diagonal solve and regression tolerances.
Reuse the prepare reference and FlyDSL wrapper, retaining FP32 reference outputs for the correlated-key relative RMS check. Run the regression from both the existing CLI and targeted pytest, and keep the 0.003 tolerance.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
There was a problem hiding this comment.
🟡 Changes recommended
The documented pytest invocation bypasses the architecture gate, causing gfx1250 to raise a ValueError instead of skipping the unsupported test.
1 open issue
What changed in this PR
This PR extends #4952’s numerical-stability work by preserving FP32 precision during off-diagonal inverse block merges in the FlyDSL GDN prepare kernel.
Changes:
- Replace BF16 merge operands and intermediate conversions with FP32 operations while retaining the merge formula and execution order.
- Add a correlated-key precision regression test with an FP32 reference.
- Add a production benchmark shape and support skipping empty benchmark sweeps.
| File | Description |
|---|---|
op_tests/test_gdn_prepare.py |
Adds precision regression coverage, optional FP32 reference outputs, and benchmark sweep updates. |
aiter/ops/flydsl/kernels/gdr_prefill/gdn_prepare.py |
Keeps off-diagonal inverse merge operands and intermediates in FP32. |
Review effort: Balanced
Skip test if graphics hardware is not supported. Co-authored-by: Copilot Autofix powered by AI <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
The FP32 MFMA changes require head-matched GPU accuracy and base/head latency validation on gfx942 and gfx950, which this static review cannot perform and the supplied gfx942-only measurements do not establish.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
WAITING ON AUTHORPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🔵 Needs a closer look
The FP32 MFMA merge requires correctness and base-versus-head latency validation on gfx942/gfx950 with pinned FlyDSL 0.4.1, but GPU execution and required dependencies are unavailable in this review environment.
No open issues 🎉
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The FP32 MFMA merge needs accuracy and latency validation at this head on gfx942/gfx950 with pinned FlyDSL 0.4.2, but supplied results used 0.4.0 on gfx942 and GPU execution is unavailable in this review.
No open issues 🎉
Review effort: Balanced
|
No activity for 15 days, so this is now labelled |
|
|
||
| def test_gdn_prepare_merge_precision(): | ||
| """Pytest entry point for the same timed regression sweep used by the CLI.""" | ||
| if get_gfx() not in SUPPORTED_GFX: |
There was a problem hiding this comment.
Fixed in b408fef. Replaced get_gfx() with get_gfx_runtime() for the pytest and CLI architecture gates, the skip log, and all three benchmark summaries in test_gdn_prepare.py.
Validated six cases with mocked hardware detection, including gfx942 with GPU_ARCHS="gfx942;gfx1250" and gfx1250 with GPU_ARCHS="gfx942". Supported devices pass the gates, unsupported devices are skipped, and the summaries report the runtime architecture. Black and Ruff checks also pass.
xytpai
left a comment
There was a problem hiding this comment.
Read at b408fef (2 files, +144 -59). I did not run anything on a GPU. The numbers below are from this head's CI logs.
Checked, no finding
- Kernel, by reading. All six off-diagonal blocks (c21, c32, c43, c31, c42, c41) now load their fp32 tiles raw, multiply through
_mfma16_f32(the helper the diagonal inversion already uses) and keep the intermediate as fp32. The formulas and their order are unchanged, and so is the final conversion of C to bf16 for WY. Operand and accumulator layouts are consistent between the loads, the MFMA chain and the stores. - Accuracy on gfx950 (CI, MI35X shard 0). The new merge-precision sweep reports a relative RMS of w / u of 0.096% / 0.172% for (hg, h) = (8, 24) and 0.153% / 0.173% for (4, 12), in both exp2 modes. These are the values the description reports for gfx942. Every row of the
gdn_preparetable haserr0. - Performance on gfx950 (same log).
prepare_flydsl usof each row lies inside the spread of five recent CI runs of the base, for exampleqwen35_35b_tp2at batch 1: 17.9 us against 15.7 to 18.0 us. So there is no visible regression there. This covers the "gfx950 unverified" note in the last Copilot review. - The new test can fail.
MERGE_REL_RMS_TOL = 3e-3is about 1.7x the measured value and below the 0.50% (u) and 2.3% (w) the description reports without the change, and_check_prepare_outputsraises on any element beyond the absolute bound.
Two notes, not blocking
- gfx942 at this head. The PR has no
ci:mi300xlabel, so CI ran the MI35X shards only, and the gfx942 numbers in the description are from October on FlyDSL 0.4.0. The change is arch-generic and the gfx950 numbers above match the October ones, so I do not expect a difference. Addingci:mi300xwould confirm it on the pinned FlyDSL. - Description. "Reviewed revision" still names 3622269, and the head is b408fef.


Motivation
#4952 has changed the inversion of the 16×16 diagonal blocks to fp32 in
gdn_prepare_kernel, but the off-diagonal block merge still converts the inverse blocks and the intermediate results across GEMMs to BF16. When keys are highly correlated, beta is close to 1, and gate decay is weak, these conversions can increase the final error ofgdn_prepare_kernel.This PR preserves fp32 inputs to the multiplications and fp32 intermediate results during the off-diagonal block merge. The diagonal block inversion, merge formula, and execution order remain unchanged.
In practice, the changes in this PR improve numerical accuracy, and no clear performance regression was observed on the tested MI308X using the prepare benchmark in op_test.
Technical Details
Test Plan
acc test
Verified with
op_tests/test_gdn_prepare.py::test_gdn_prepare_merge_precisionusing a fixed random seed (2026) andB=1, T=64, K=V=128. The keys were made strongly correlated by adding 0.01 × noise to the same base, then normalizing and converting to BF16. Parameters:beta=0.999,g=-1e-4.The reference implementation reuses the existing
run_torch_gdn_prepare(). The error is measured as||actual-reference||₂ / ||reference||₂, equivalent to a normalized RMS error, and is reported as a percentage, the lower the better (gfx942 flydsl0.4.0)falsetruefalsetrueBaseline represents the version without this pr's change.
Across all 4 cases, the baseline w/u exceeded the 0.3% regression threshold, while the patched version stayed below the same threshold in every case.
perf regression tests
Measured on a MI308X with FlyDSL 0.4.0, using the existing
test_gdn_prepare(). This PR adds a new caseqwen38_flash_next_tp2.Each measurement uses 3 warmup iterations and 21 profiler iterations. Reported latency is the median of three measurements with alternating baseline/patch order, after populating compilation caches.
Both kernels use identical shape definitions and inputs. All prepare correctness checks reported err=0. Here
Change = (patched / baseline − 1) × 100%; negative values indicate lower latency.Test Result
PR Self-Review
Reviewed revision
36222698d127c616fb853e6ade12bbf7f289918bBehavior and intent
Preserve FP32 operands and intermediate results in the off-diagonal inverse
block merges of FlyDSL GDN prepare. The existing BF16 conversions between
GEMMs cause avoidable w/u error for strongly correlated keys, beta near 1,
and weak gate decay. This extends the FP32 diagonal-block inversion from
#4952 to the subsequent merge products. The final inverse-to-BF16 conversion
for WY and the public output contract remain unchanged.
Validation and unverified scope
Recorded validation used one AMD Instinct MI308X (
gfx942, 80 CUs), FlyDSL0.4.0, PyTorch
2.12.0+rocm7.14.0.git6bbd260, and Triton3.8.0+rocm7.14.0.git4cff872.From the repository root, in that AITER/FlyDSL environment:
The timed regression reported
1 passed, covering all four head-ratio/exp2configurations, and the CLI emitted precision, prepare, and pipeline summaries
with
err=0. Replacing only the prepare implementation with the baselinekernel makes the unchanged regression fail: the first w relative RMS is
0.02316339, above0.003. The accuracy table above records all fourbaseline/patch comparisons. The performance command, measurement procedure,
and 12-case results are in the Test Plan above.
These are recorded measurements from October 25-28, not new GPU runs at this
head. The kernel and test files at the reviewed revision were compared with
the locally validated versions and are byte-for-byte identical. The complete
dependency/integration state of this revision has not been rerun. gfx950,
other devices, and end-to-end model quality/serving performance remain
unverified by this PR's evidence. The reference is the FP32/BF16 specification
described above, not a fully FP64 reference.
PR-specific question
test_gdn_prepare_merge_precision()fails on the pre-patch implementationbecause the w/u relative RMS exceeds 0.3% for the fixed correlated-key inputs.
The existing canonical
test_gdn_prepare()uses independent random keys,stronger decay, and an absolute w/u tolerance of 0.05; it does not exercise
this input condition or enforce this relative-error bound. The new regression
reuses its reference and output checks in the same file, with FP32 final
reference outputs for the RMS assertion.
The added
qwen38_flash_next_tp2shape in the existing prepare sweep isperformance and correctness coverage for
T=12000, Hg=8, H=24. It is notclaimed to fail numerically before the patch; the correlated-key regression
provides the demonstrated pre-patch failure.
Changed op tests
op_tests/test_gdn_prepare.py: adds the correlated-key merge regression for(Hg,H)=(8,24)/(4,12)and both exp2 modes. This covers a numerical failureabsent from the original random-input sweep. It uses the shared reference,
@benchmark(),run_perftest, and a summary table while retaining the tightRMS assertion. It also adds the 12K Qwen3.8 TP2 shape to the existing prepare
benchmark; no previous catalog entry covers that token count and head ratio.
Existing callers retain the reference's default BF16 output behavior.
Submission Checklist