Repository navigation
[Triton/Gluon] [Bugfix] Scale gfx942 Sage probabilities before FP8 conversion - #6138
Conversation
Signed-off-by: akshatvishu <[email protected]>
🏷️ 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.
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
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.
|
@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:
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 (✅ / 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 |
ROCm/aiter PR #6138 — [Triton/Gluon] [Bugfix] Scale gfx942 Sage probabilities before FP8 conversionMultiplies 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):
|
Signed-off-by: akshatvishu <[email protected]>

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
iconvpass 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, Triton3.8.0+git669b31ac: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 --checkpass. 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 -qPrior October 5 numerical evidence, using the same kernel arithmetic on PyTorch
2.12.0+git6bbd260: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.
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-300xlane before merge; local results are not an upstream CI pass.