Skip to content

[ASM] [Bugfix] Scale gfx942 v3 FP8 FMHA probabilities before conversion - #6139

Open
akshatvishu wants to merge 2 commits into
ROCm:mainfrom
akshatvishu:fix/gfx942-fmha-fp8-probability-scaling
Open

akshatvishu wants to merge 2 commits into
ROCm:mainfrom
akshatvishu:fix/gfx942-fmha-fp8-probability-scaling

Conversation

@akshatvishu

Copy link
Copy Markdown
Contributor

Summary

Fix the reported gfx942 dense v3 FP8 FMHA probability underflow in #6137. The constant-V stress case returns about 0.42 in the original binary because its FP8 PV numerator drops small exponentials while the FP32 denominator retains them. The patched binary passes the regression with absolute tolerance 0.01.

Changes

  • Scale the 32 probability registers by 128 immediately before each of the six FP8 packing blocks, after their unrounded values enter the denominator.
  • Apply 1/128 to the final normalization before broadcasting it to the packed output lanes. Preserve the denominator, LSE, online maximum/accumulator rescaling, masks, branches and existing waits.
  • Add 13 public-API regression cases with uniform and long-tail scores, first/last maxima, aligned/masked sequences, nonconstant V and five repetitions per case.
  • Include the exact ISA diff and rebuild instructions under docs/examples/isa_optimization/.

Only hsa/gfx942/fmha_v3_fwd/MI300/fwd_hd128_fp8.co changes. Sibling causal/grouped/MI308 code objects are not claimed fixed. The Sage part of #6137 is a separate PR, following the one-backend-per-PR contribution rule.

Binary audit

The original object disassembles and reassembles with identical .text, descriptor, metadata and target flags using the repository's roundtrip.sh. Re-extracting the patched object produces exactly the intended instruction sequence. Removing the 193 inserted multiplications recovers the original assembly. VGPRs, SGPRs and LDS allocation are unchanged.

  • Original SHA-256: 7bffc09e0fea2165b609e3661c896839bff3d0418e4511e99ef62bc2101c8b04.
  • Patched SHA-256: e5575cb14fe020289f31dd0653d213f792724b71a76a993219eae215fda435dc.
  • Instructions: 2872 to 3065. No additional memory operations or launches.

The public tree contains the code object without its instruction generator. The included ISA diff makes this repair reproducible; apply the same arithmetic in the generator when regenerating it. Related open #5535 uses probability scaling for a different gfx950 MLA object.

Testing

  • MI300X, gfx942, ROCm 7.2.3 LLVM, PyTorch 2.12.0+git6bbd260.
  • Original and unchanged-roundtrip binaries each have 4 failed, 9 passed in the new regression. The patched binary has 13 passed.
  • Six real Qwen-Image captures, B=1/H=24/D=128/S=4101 or 4117, including nonunit Q/K/V descales. Five exact repeats and post-timing repeats pass. The unchanged roundtrip is byte-identical to original output on all six captures.
  • Relative L2 against original-input FP32 decreases from 5.236% to 9.365% to 4.525% to 6.782%. A separate tiled CPU model with the same quantized inputs and unrounded denominator agrees with patched native output within 0.0046% relative L2 after BF16 rounding, over every query/head.
  • Loader logs identify the exact original/roundtrip/patched file, and a separate trace confirms FP8 FMHA dispatch. Kernel symbol alone is insufficient because v3 and v4 share that name.
  • Black 26.3.0, Ruff 0.16.0, repository pre-commit hook and git diff --check pass.
HIP_VISIBLE_DEVICES=0 ENABLE_CK=1 python -m pytest op_tests/test_mha_fp8_probability.py -q

Performance

This correctness repair has a measured cost. Full-operation pooled medians in microseconds, including caller Q/K/V quantization, over six captures and three rounds of ten unprofiled event measurements per cache mode:

Cache mode Original Patched Change
Primed 376.41 403.54 +7.21%
Scrubbed before the whole operation 386.86 414.86 +7.24%

Original and patched arms use separate processes; BF16 controls remain around 527 to 530 microseconds primed. These operation measurements do not establish request latency or image quality. FP8 input quantization and probability rounding remain. No new dependencies or public API changes; other architectures and code objects were not tested.

@akshatvishu
akshatvishu requested a review from a team October 4, 2026 19:35
@github-actions github-actions Bot changed the title [Bugfix] Scale gfx942 v3 FP8 FMHA probabilities before conversion [ASM] [Bugfix] Scale gfx942 v3 FP8 FMHA probabilities before conversion Oct 4, 2026
@github-actions github-actions Bot added the ASM label Oct 4, 2026
@github-actions

github-actions Bot commented Oct 4, 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
multigpu 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: 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 6139 --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.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Nov 1, 2026
@akshatvishu

akshatvishu commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor Author

keep-open

@github-actions github-actions Bot removed the stale The PR hasn't been updated in 2 weeks label Nov 2, 2026
@github-actions

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Nov 17, 2026
@shay-li77

Copy link
Copy Markdown
Contributor

@akshatvishu Thanks for tracking this down. The underflow is real at these sequence lengths, and the ISA diff makes the change easy to follow.

One suggestion that may remove most of the cost: instead of 32 v_mul_f32 per packing block, fold the ×128 into the exponent. Subtract 7 more from the row-max term in the log2 domain, so exp2 already produces 128·P. The denominator then carries the same factor and cancels it, so the final 1/128 multiply goes away, and the accumulator rescale exp2(m_old - m_new) is unaffected because the offset cancels. Only the LSE needs a 7·ln2 correction. I've used this approach before; could you try it here and see whether it holds and how much of the +7.2% it recovers?

Beyond that:

  1. This object becomes the default for every non-causal FP8 hd128 call on MI300, so please add: the existing op_tests/test_mha_fp8.py results (including the return-LSE cases) on the patched object; accuracy for batch > 1, short and non-tile-multiple seqlens, seqlen_q != seqlen_k and GQA; and kernel-only base-vs-head timing over a seqlen/batch sweep, listing any slower shapes (the +7.2% includes caller quantization).
  2. The new test only gates on gfx942, but hsa/gfx942/fmha_v3_fwd/MI308/fwd_hd128_fp8.co isn't patched, so the test should fail on an MI308 node. Please patch that object too, or skip/xfail it there.
  3. There are no CI results on this branch yet; please merge the latest main to trigger a run.

@github-actions github-actions Bot removed the stale The PR hasn't been updated in 2 weeks label Nov 30, 2026

This branch has not been deployed

No deployments
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.

3 participants