Skip to content

[Triton/Gluon] [Bugfix] Scale gfx942 Sage probabilities before FP8 conversion - #6138

Merged
azaidy merged 2 commits into
ROCm:mainfrom
akshatvishu:fix/gfx942-fp8-probability-scaling
Oct 21, 2026
Merged

azaidy merged 2 commits into
ROCm:mainfrom
akshatvishu:fix/gfx942-fp8-probability-scaling

Conversation

@akshatvishu

@akshatvishu akshatvishu commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix the gfx942 Sage FP8 probability underflow reported in #6137. With one score at zero, thousands of scores at minus eight, and V equal to one, the original kernel returns about 0.42. Scale probabilities before FNUZ conversion to retain that tail mass.

Changes

Multiply P by 128 before FNUZ conversion in the dense and sparse full/tail paths, then undo the scale once in the output reciprocal. P is at most 1 and FNUZ's maximum is 240, so 128 is the largest safe power-of-two scale. Keep the FP32 denominator, online maximum updates, accumulator rescaling and LSE unchanged. Other V dtypes bypass both multiplications. There are no config, wrapper or API changes.

Add 14 deterministic cases through fav3_sage_func: uniform scores, minus-seven/minus-eight tails, exact INT8-encoded spreads from minus seven to minus nine, first/last maxima, causal masking, sparse full/tail blocks, LSE, and unaffected BF16 V. The spread uses seven integer Q/K channels so quantizing the fixture does not collapse its logits. Tests use the wrapper's default config.

Nonuniform FNUZ constant-V stress cases allow absolute error 0.05 because scaled FP8 rounding remains and the denominator is intentionally unrounded. Uniform and BF16 controls keep 0.01; LSE keeps atol=rtol=2e-5. These are fixture-specific correctness tolerances, not an image-quality threshold or a guarantee for every distribution.

Restored every unrelated upstream comment requested in review. The repository hook's whole-file iconv pass caused the earlier damaged diagrams. For this update, the installed local hook preserves exact upstream Unicode comment lines while retaining transliteration for new content, Black, Ruff, whitespace and copyright checks. No hook-policy change is included in this PR, and hooks were not skipped.

This is the Triton part of #6137. The v3 ASM object is addressed separately in #6139.

Testing

Current revision, October 13, MI300X/gfx942, PyTorch 2.13.0+git733fca1, Triton 3.8.0+git669b31ac:

  • Original kernel: 8 failed, 6 passed across the 14 regression cases. Failures are output-accuracy assertions, not import or compilation errors. The uniform and BF16 controls pass.
  • Patched kernel: 86 passed, including all 14 regression cases and the existing sparse-reference, empty-row, causal-LSE, LSE-reference and ring-merge selection. No errors or skips.
  • 17 passed in test_fav3_sage_compile.py. These check full-graph execution, output shape and absence of NaNs; they do not establish compiled-versus-eager numerical parity.

Both original and patched kernels run through an isolated source overlay against the same installed AITER wrapper. The wrapper and original kernel are byte-identical to the PR base. Installed AITER files are not changed. Source hashes are checked before execution and against the committed files afterward.

Black 26.3.0, Ruff 0.15.7 (contributor guide), Ruff 0.16.0 (CI) and git diff --check pass. Two pre-commit passes preserve identical file hashes; the commit hook is also run. The kernel's Python AST is unchanged from the previously tested PR head: this revision restores comments, documents the scale, and strengthens tests.

HIP_VISIBLE_DEVICES=0 python -m pytest op_tests/triton_tests/attention/test_fav3_sage.py \
  -k 'small_probabilities or ((block_sparse_vs_reference or block_sparse_empty_kv or causal_above_diagonal or return_lse_matches_reference or ring_merge_matches_single_call) and not mxfp4)' -q
HIP_VISIBLE_DEVICES=0 python -m pytest op_tests/triton_tests/attention/test_fav3_sage_compile.py -q

Prior October 5 numerical evidence, using the same kernel arithmetic on PyTorch 2.12.0+git6bbd260:

  • Six real Qwen-Image block-30 captures, B=1/H=24/D=128/S=4101 or 4117. Actual quantized operands match between arms; five exact repeats and post-timing repeats pass. Default gfx942 config remains 256 by 128, eight warps, two stages.
  • Relative L2 against original-input FP32 decreases from 3.085%–6.716% to 1.628%–2.429%. A separate tiled CPU model with the same quantized inputs and unrounded denominator agrees with patched native output within 0.0062% relative L2 after BF16 rounding, over every query/head.

Performance and downstream scope

Historical full-operation pooled medians in microseconds, including quantization and smoothing, over six captures and three rounds of ten event measurements per cache mode. Original and candidate use separate processes, with a BF16 control in each. Timing is unprofiled; dispatch was checked separately.

Cache mode Original Patched Change
Primed 734.15 729.44 -0.64%
Scrubbed before the whole operation 758.58 757.96 -0.08%

These differences do not establish a speedup. No performance rerun is claimed for the comment/test revision. The fix adds constant multiplications without another probability reduction, buffer or launch.

A prior controlled vLLM-Omni Qwen-Image harness also ran five prompts at 1024x1024, 50 steps. Each saved Sage request recorded 6,000 expected calls with finite outputs and no harness fallback. This was an experimental substitution, not stock vLLM-Omni dispatch. Only 2/5 Sage images met the historical LPIPS diagnostic of 0.15; its instrumented request median was 15.565 s versus BF16's 14.433 s. Those limits were not a calibrated production contract, and the timings were not fresh-process pairs. This does not establish acceptable image quality or a request-level speedup. BF16 remains the application default.

Limits

Scaling reduces underflow but leaves FP8 rounding and input quantization error. It does not guarantee exact normalization for every distribution. Dropout and returned-score ordering is preserved in source but was not exercised by these public-wrapper tests. E4M3FN on other architectures and the sibling MXFP4 implementation are outside this FNUZ fix and still require separate validation. Other architectures were not tested locally. No new dependencies or public API changes.

The gfx942 regressions need the ci:triton-300x lane before merge; local results are not an upstream CI pass.

@akshatvishu
akshatvishu requested a review from a team October 4, 2026 19:34
@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 6138 --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 changed the title [Bugfix] Scale gfx942 Sage probabilities before FP8 conversion [Triton/Gluon] [Bugfix] Scale gfx942 Sage probabilities before FP8 conversion Oct 4, 2026
@Boss2002n
Boss2002n requested a balanced review from Copilot October 4, 2026 21:33

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.

Copilot review overview

🟡 Changes recommended

The unrelated comment cleanup should be separated and several ASCII substitutions currently obscure masking documentation.

Review effort: Balanced
Findings: 4 Low severity

Open (4)
What changed in this PR

Fixes gfx942 Sage FP8 probability underflow by scaling probabilities before FNUZ conversion and compensating during normalization.

Changes:

  • Applies scaling across dense and block-sparse paths.
  • Adds nine deterministic regression cases.
  • Performs unrelated ASCII comment normalization.
File Description
aiter/​ops/​triton/​_triton_kernels/​attention/​fav3_sage_attention.py Adds FP8 probability scaling and rewrites comments.
op_tests/​triton_tests/​attention/​test_fav3_sage.py Adds dense, sparse, causal, LSE, and BF16 regression coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@zufayu
zufayu requested review from a team and Dewei-Wang-sh October 5, 2026 00:32
@azaidy
azaidy requested a review from vgokhale October 5, 2026 22:16
@zufayu

zufayu commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review


Trying the review bot on a few representative PRs across different areas, so the team can see what it actually produces on real diffs.

How to use it — just comment on any PR:

  • @aiter-bot review — first pass
  • @aiter-bot re-review — after you push fixes

What it is: advisory only. It surfaces hints for a human reviewer — perf regressions, silent correctness bugs, dispatch-gate holes, AI-generated code patterns. Its judgement is stochastic, it never blocks a merge, and every verdict (✅ / ⚠️ / 🔴) is posted so the reviewer who asked for it sees the result.

It runs on a self-hosted box against a local model, so a pass takes roughly 25–30 min.

Who can trigger it: the logins in authorized.txt — the aiter review roster. Details in SKILL.md.

@aiter-bot

Copy link
Copy Markdown

ROCm/aiter PR #6138 — [Triton/Gluon] [Bugfix] Scale gfx942 Sage probabilities before FP8 conversion

Multiplies softmax probabilities by 128 before their fp8-fnuz conversion in all four fav3 Sage forward loop kernels and divides the 128 back out in the output normalization, so the small probabilities that previously flushed to zero in the fp8 conversion (the #6137 underflow) survive the quantized P·V dot while the fp32 denominator, LSE and online-softmax rescaling stay unchanged.

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — auto-validation disabled (REVIEW_AUTO_VALIDATE=0); the target op_tests/triton_tests/attention/test_fav3_sage.py exists but was not executed here, so all correctness evidence is the PR's own (81 passed on MI300X/gfx942, ROCm 7.2.3)
Perf (advisory): NOT RUN — the triaged target ships no benchmark entry point (no --scenario bench, no perftest/@benchmark harness); the PR's own hand measurement (base vs head, six Qwen-Image captures, three rounds of ten event measurements per cache mode, BF16 control in each arm) reports -0.64%/-0.08% pooled medians and explicitly disclaims a speedup

⚠️ [verified] op_tests/triton_tests/attention/test_fav3_sage.py:61 skips all eight fnuz regression cases on non-gfx942 arches, and no CI path in this PR runs them on gfx942 — the MI300X Triton job is gated on a gfx942 config/gluon path or the ci:triton-300x label (select_triton_tests.py:395, triton-test.yaml:58), this PR changes neither and carries neither, and the aiter-test job collects op_tests only at maxdepth 1 — so the fix's regression suite never executes on the arch it targets and a future regression of exactly this fix passes CI green. Author must add the ci:triton-300x label so the new cases run on MI300X before merge.
⚠️ [inferred] The unscaled p-to-fp8 conversion this PR fixes remains in the sibling paths: aiter/ops/triton/_triton_kernels/attention/fav3_sage_attention_mxfp4.py:238/349/453/564 still converts p to V's dtype with no scaling, and on gfx950/gfx1250 the fixed kernel aiter/ops/triton/_triton_kernels/attention/fav3_sage_attention.py itself receives e4m3fn V (aiter/utility/dtypes.py:13) where the new guard does not fire — if #6137's underflow class also flushes sub-2^-9 probabilities in e4m3fn, those paths keep the bug. Reviewer should ask whether the underflow affects the fn paths and whether a follow-up covers them (the v3 ASM object is split out, but the mxfp4 Triton kernel is unmentioned).
📝 [verified] The hook-mandated ASCII transliteration degrades the masking documentation this PR rewrites: -∞ became -?, ⌈BLOCK_M / BLOCK_N⌉ became ?BLOCK_M / BLOCK_N? and ↑ became ? in fav3_sage_attention.py:1056-1201, so the causal-masking diagrams now explain themselves with question marks. Reviewer should ask for meaningful ASCII replacements (-inf, ceil(), ^) — the pre-commit hook mandates ASCII, not question marks.
📝 [verified] 128.0 at fav3_sage_attention.py:220 (and the 1.0/128.0 at 1859) carries no in-code derivation — the comment says only "retain more small probabilities", while the unstated bound (p <= 1 so p128 <= 128 < 240, the fnuz max) is what makes 128 the largest safe power-of-two scale. Reviewer should ask for the derivation in a comment so the constant is not retuned without the bound.
📝 [inferred] The changed kernel aiter/ops/triton/_triton_kernels/attention/fav3_sage_attention.py is consumed by a serving stack outside aiter (the PR's own six Qwen-Image captures prove it), yet the PR carries no ci:
label and no label's model roster covers Qwen-Image (ci:sglang covers Qwen 3.5; ci:atom/ci:vllm cover DeepSeek/GPT-OSS/Kimi) — the changed numerics ship on the author's local runs alone. Reviewer should ask which downstream serves fav3_sage and whether one downstream run is wanted before merge.

@azaidy
azaidy merged commit 0766f73 into ROCm:main Oct 21, 2026
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.

7 participants