Skip to content

[FlyDSL] FMHA gfx1250: per-tensor fp8 descales for the a8w8 kernel - #7214

Merged
coderfeli merged 7 commits into
mainfrom
jruan/gfx1250_fdsl_fmha_8b_descale
Nov 3, 2026
Merged

coderfeli merged 7 commits into
mainfrom
jruan/gfx1250_fdsl_fmha_8b_descale

Conversation

@ruanjm

@ruanjm ruanjm commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Accept the q/k/v descales the gfx950 fp8 FMHA takes -- fp32, one element, on q's device.

All three must be given together, as gfx950 requires; a partial set is ambiguous, so the gate declines it rather than assuming 1.0.

Checked: descale 1.0 is bitwise identical to the no-descale path; q*k descale 4 against softmax_scale/4 is bitwise identical to baseline; v_descale 4 scales O by exactly 4; against an fp32 reference that dequantizes first, error is fp8 quantisation noise (3.6% non-causal, 1.4% causal); the existing fp8 sweep is 16/16 clean.

Accept the q/k/v descales the gfx950 fp8 FMHA takes -- fp32, one element,
on q's device -- instead of declining them and falling through to CK.

They are scalars, so no scaled WMMA is involved. V_WMMA_SCALE_F32_16X16X128
carries an E8M0 scale, which is a power of two and cannot represent an
arbitrary fp32 descale, and the kernel already applies softmax_scale to the
fp32 logits after QK precisely because 8-bit Q cannot carry it. So the split
is the one fmha_gfx950/pipeline.py:init_descale uses:

  q_descale * k_descale  ->  folded into softmax_scale, hence into _s_scale,
                             which row_max already multiplies -- so it reaches
                             the LSE through m with no change to that line
  v_descale              ->  folded into the epilogue's per-row inv_denom,
                             scaling O alone and leaving the LSE untouched

Loaded on device from the tensors, as gfx950 does; reading them host-side
would mean .item() and a device sync on every call.

has_descale is compile-time and part of the build key, so the no-descale build
is unchanged: same 6692 instructions, same 69 SGPR / 410 VGPR / 0 spills, with
only kernarg offsets shifted by the three unused pointers.

All three must be given together, as gfx950 requires; a partial set is
ambiguous, so the gate declines it rather than assuming 1.0.

Checked: descale 1.0 is bitwise identical to the no-descale path; q*k descale
4 against softmax_scale/4 is bitwise identical to baseline; v_descale 4 scales
O by exactly 4; against an fp32 reference that dequantizes first, error is fp8
quantisation noise (3.6% non-causal, 1.4% causal); the existing fp8 sweep is
16/16 clean.
@ruanjm ruanjm added the FlyDSL label Oct 30, 2026
@github-actions

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
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu 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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 7214 --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.

@aiter-bot

aiter-bot commented Oct 30, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision fb9b850a1af9 · mode shadow

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

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_mha_flydsl.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@ruanjm
ruanjm marked this pull request as ready for review October 30, 2026 10:12
@ruanjm
ruanjm requested review from a team and a balanced review from Copilot October 30, 2026 10:12
@github-actions github-actions Bot changed the title FMHA gfx1250: per-tensor fp8 descales for the a8w8 kernel [FlyDSL] FMHA gfx1250: per-tensor fp8 descales for the a8w8 kernel Oct 30, 2026

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.

🟡 Changes recommended

Zero effective Q/K scales can produce NaNs for masked keys, while public calls with descales bypass the FlyDSL path and can fail when CK is disabled.

3 open issues
What changed in this PR

Adds per-tensor fp32 Q/K/V descale support to the gfx1250 FlyDSL FP8 attention backend, matching the gfx950 input contract.

Changes:

  • Loads descales on device, applying Q/K scaling to logits and V scaling to output.
  • Adds descale specialization to both variable-length and batched kernels and their cache keys.
  • Updates backend dispatch to accept complete, valid descale sets and decline unsupported requests.
File Description
aiter/​ops/​flydsl/​kernels/​fmha_gfx1250/​fmha_fwd_prefill_a8w8_m32x8.py Adds descale loading, scaling, validation, and launch specialization.
aiter/​ops/​flydsl/​fmha_kernels.py Validates and forwards descales to the gfx1250 FP8 kernels.

Review effort: Balanced

Comment thread aiter/ops/flydsl/fmha_kernels.py Resolved
Copilot AI balanced review requested due to automatic review settings October 30, 2026 10:18
flash_attn_varlen_func gated its FlyDSL hook on `not has_all_descales` and did
not forward the descales, so a prequantized fp8 call could never reach the
a8w8 kernel even now that it handles them -- it went straight to CK.

Drop that condition and pass the three through. The FlyDSL gate already
declines what it cannot serve (16-bit inputs, a partial set, a non-scalar or
non-fp32 descale) by returning None, so anything unsupported still falls
through to CK exactly as before.

Verified through the public entry, not the internal one: the FlyDSL path is
called and serves the request, and v_descale=4 scales O by exactly 4.0000.
No regression -- fp8 16/16 and bf16 32/32 clean, the latter all at err 0.

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.

🔵 Needs a closer look

Zero Q or K descales can produce NaNs in masked softmax, and the new gfx1250 descale specialization and dispatch validation lack regression coverage.

2 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Preserve masked softmax behavior with zero descale

aiter/​ops/​flydsl/​kernels/​fmha_gfx1250/​fmha_fwd_prefill_a8w8_m32x8.py:2491

A zero Q or K descale passes validation but makes the effective logit scale zero in both THD and BSHD. _softmax masks scores to -inf before scaling, so its exponential argument evaluates -inf * 0 to NaN instead of giving masked keys zero probability. Preserve masking when applying a zero scale, including the row-max handling for fully masked rows.

1 resolved since last review

Review effort: Balanced

flash_attn_func took no descales at all, so the bshd half of the a8w8 descale
support was unreachable. Add the three parameters, forward them to the FlyDSL
hook, and validate the all-or-none rule the varlen entry already enforces.

Unlike varlen, neither batched fallback consumes descales: the CK varlen path
takes q/k/v_descale, but FlashAttnFunc and the Triton batch entry do not. A
request that reached them with descales would be served unscaled, so raise
instead of returning a wrong answer. That keeps the rule that a backend either
honours an option or declines the call.

Checked through flash_attn_func: served with the right shape and dtype,
v_descale=4 scales O by exactly 4.0000, a partial set raises ValueError, and
bf16 + descale raises rather than silently dropping the scaling. fp8 16/16 and
bf16 32/32 clean, varlen route unaffected.
Copilot AI balanced review requested due to automatic review settings October 30, 2026 10:27

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.

🟡 Changes recommended

Supported FP8 descale requests are rejected before reaching FlyDSL when CK is disabled, and accepted zero Q/K descales can produce NaNs in causal attention.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Zero Q/K descales can produce NaNs on masked scores

aiter/​ops/​flydsl/​fmha_kernels.py:261

This accepts a zero Q or K descale, but the shared _softmax implementation assumes its effective scale is positive: it masks scores to -inf before computing fma_inf(score, s_scale, ...). For causal FP8 attention with q_descale=0 and k_descale=v_descale=1, masked entries therefore evaluate -inf * 0, introducing NaNs instead of producing uniform attention over valid keys. Preserve masked -inf after scaling, or explicitly reject unsupported zero Q/K scales.

2 resolved since last review

Review effort: Balanced

Comment thread aiter/ops/mha.py Resolved
…escales

flash_attn_varlen_func rejected every descale call up front when ENABLE_CK=0,
before the FlyDSL hook ran. That was right when CK was the only backend that
could consume descales, but the a8w8 gfx1250 kernel now can, so a supported
fp8 request was refused for a reason that no longer applied to it.

Move the rejection to the Triton fallback it actually protects. FlyDSL gets
first refusal; only a request that falls past it, to a backend with no descale
support, raises.

With ENABLE_CK=0: fp8 + descales is now served by FlyDSL, and bf16 + descales
still raises instead of reaching Triton and being computed unscaled. With
ENABLE_CK=1 nothing changes -- varlen and batch routes and the fp8 sweep are
unaffected.
Copilot AI balanced review requested due to automatic review settings November 2, 2026 02:56

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.

🔵 Needs a closer look

The new gfx1250 descale-enabled specializations lack checked-in regression coverage because existing gfx1250 sweeps never pass descales and current descale tests target only gfx950.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

A third sweep beside thd and bshd, with its own table. Besides the usual error
against a reference that pre-scales q*qd, k*kd and v*vd, it checks three
invariants that pin the fold itself and do not depend on fp8 noise:

  identity     descales of 1.0 reproduce the no-descale path bit for bit
  v_scale_ok   v_descale=4 scales O exactly (x4 shifts the bf16 exponent and
               leaves the mantissa, so round(4x) == 4*round(x))
  qk_fold_ok   q/k descale 2*2 against softmax_scale/4 is bitwise the baseline

Those matter because a wrong fold shows up as an error that reads like
quantisation noise; bitwise columns cannot be mistaken for it.

Descales are a8w8-only, so the sweep takes just the 8-bit dtype pairs and
self-skips when none is requested, leaving the existing two sweeps and their
--max-cases sampling untouched. --descale 0 turns it off.

64/64 rows across fp8/bf8, hdim 128 and 192/128, causal and not, batch 1 and 3,
GQA 1x and 4x: all three invariants true, err 0.
Copilot AI balanced review requested due to automatic review settings November 2, 2026 03:10

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.

🟡 Changes recommended

The descale tests do not fail when invariants are false, and the default-enabled sweep bypasses --max-cases, leaving regressions unenforced and partial runs unbounded by the requested limit.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread op_tests/test_mha_flydsl.py Resolved
Comment thread op_tests/test_mha_flydsl.py Resolved
The descale sweep iterated its product directly, so --max-cases bounded the
two layout sweeps but not it: a partial-axis request still paid for the whole
hdim x shape x fp8-dtype x causal product first, defeating the point of the
bound.

Split the indexed sampler out of _cases into _sample(axes, label) and route
all three sweeps through it. _cases keeps the hdim filtering that makes its
index space exact; the descale sweep passes its own four axes.

--max-cases 1 now yields one row per table and three sampling lines, and
--max-cases 0 still runs the full 64-row descale sweep, all invariants true
and err 0.
Copilot AI balanced review requested due to automatic review settings November 2, 2026 03:27

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.

🔵 Needs a closer look

The correctness and invariant checks only report results without asserting them, allowing descaling regressions to pass CI.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@coderfeli
coderfeli merged commit e3e0263 into main Nov 3, 2026
@coderfeli
coderfeli deleted the jruan/gfx1250_fdsl_fmha_8b_descale branch November 3, 2026 02:35
shantipriya-amd pushed a commit to shantipriya-amd/aiter that referenced this pull request Nov 18, 2026
…OCm#7214)

* FMHA gfx1250: per-tensor fp8 descales for the a8w8 kernel

Accept the q/k/v descales the gfx950 fp8 FMHA takes -- fp32, one element,
on q's device -- instead of declining them and falling through to CK.

They are scalars, so no scaled WMMA is involved. V_WMMA_SCALE_F32_16X16X128
carries an E8M0 scale, which is a power of two and cannot represent an
arbitrary fp32 descale, and the kernel already applies softmax_scale to the
fp32 logits after QK precisely because 8-bit Q cannot carry it. So the split
is the one fmha_gfx950/pipeline.py:init_descale uses:

  q_descale * k_descale  ->  folded into softmax_scale, hence into _s_scale,
                             which row_max already multiplies -- so it reaches
                             the LSE through m with no change to that line
  v_descale              ->  folded into the epilogue's per-row inv_denom,
                             scaling O alone and leaving the LSE untouched

Loaded on device from the tensors, as gfx950 does; reading them host-side
would mean .item() and a device sync on every call.

has_descale is compile-time and part of the build key, so the no-descale build
is unchanged: same 6692 instructions, same 69 SGPR / 410 VGPR / 0 spills, with
only kernarg offsets shifted by the three unused pointers.

All three must be given together, as gfx950 requires; a partial set is
ambiguous, so the gate declines it rather than assuming 1.0.

Checked: descale 1.0 is bitwise identical to the no-descale path; q*k descale
4 against softmax_scale/4 is bitwise identical to baseline; v_descale 4 scales
O by exactly 4; against an fp32 reference that dequantizes first, error is fp8
quantisation noise (3.6% non-causal, 1.4% causal); the existing fp8 sweep is
16/16 clean.

* FMHA gfx1250: black formatting for the a8w8 descale change

* FMHA gfx1250: let descale calls reach the FlyDSL varlen path

flash_attn_varlen_func gated its FlyDSL hook on `not has_all_descales` and did
not forward the descales, so a prequantized fp8 call could never reach the
a8w8 kernel even now that it handles them -- it went straight to CK.

Drop that condition and pass the three through. The FlyDSL gate already
declines what it cannot serve (16-bit inputs, a partial set, a non-scalar or
non-fp32 descale) by returning None, so anything unsupported still falls
through to CK exactly as before.

Verified through the public entry, not the internal one: the FlyDSL path is
called and serves the request, and v_descale=4 scales O by exactly 4.0000.
No regression -- fp8 16/16 and bf16 32/32 clean, the latter all at err 0.

* FMHA gfx1250: route batched descale calls to the FlyDSL kernel too

flash_attn_func took no descales at all, so the bshd half of the a8w8 descale
support was unreachable. Add the three parameters, forward them to the FlyDSL
hook, and validate the all-or-none rule the varlen entry already enforces.

Unlike varlen, neither batched fallback consumes descales: the CK varlen path
takes q/k/v_descale, but FlashAttnFunc and the Triton batch entry do not. A
request that reached them with descales would be served unscaled, so raise
instead of returning a wrong answer. That keeps the rule that a backend either
honours an option or declines the call.

Checked through flash_attn_func: served with the right shape and dtype,
v_descale=4 scales O by exactly 4.0000, a partial set raises ValueError, and
bf16 + descale raises rather than silently dropping the scaling. fp8 16/16 and
bf16 32/32 clean, varlen route unaffected.

* FMHA gfx1250: guard the fallback, not the dispatch, for ENABLE_CK=0 descales

flash_attn_varlen_func rejected every descale call up front when ENABLE_CK=0,
before the FlyDSL hook ran. That was right when CK was the only backend that
could consume descales, but the a8w8 gfx1250 kernel now can, so a supported
fp8 request was refused for a reason that no longer applied to it.

Move the rejection to the Triton fallback it actually protects. FlyDSL gets
first refusal; only a request that falls past it, to a backend with no descale
support, raises.

With ENABLE_CK=0: fp8 + descales is now served by FlyDSL, and bf16 + descales
still raises instead of reaching Triton and being computed unscaled. With
ENABLE_CK=1 nothing changes -- varlen and batch routes and the fp8 sweep are
unaffected.

* FMHA gfx1250: test coverage for the fp8 per-tensor descales

A third sweep beside thd and bshd, with its own table. Besides the usual error
against a reference that pre-scales q*qd, k*kd and v*vd, it checks three
invariants that pin the fold itself and do not depend on fp8 noise:

  identity     descales of 1.0 reproduce the no-descale path bit for bit
  v_scale_ok   v_descale=4 scales O exactly (x4 shifts the bf16 exponent and
               leaves the mantissa, so round(4x) == 4*round(x))
  qk_fold_ok   q/k descale 2*2 against softmax_scale/4 is bitwise the baseline

Those matter because a wrong fold shows up as an error that reads like
quantisation noise; bitwise columns cannot be mistaken for it.

Descales are a8w8-only, so the sweep takes just the 8-bit dtype pairs and
self-skips when none is requested, leaving the existing two sweeps and their
--max-cases sampling untouched. --descale 0 turns it off.

64/64 rows across fp8/bf8, hdim 128 and 192/128, causal and not, batch 1 and 3,
GQA 1x and 4x: all three invariants true, err 0.

* FMHA gfx1250: bound the descale sweep with --max-cases too

The descale sweep iterated its product directly, so --max-cases bounded the
two layout sweeps but not it: a partial-axis request still paid for the whole
hdim x shape x fp8-dtype x causal product first, defeating the point of the
bound.

Split the indexed sampler out of _cases into _sample(axes, label) and route
all three sweeps through it. _cases keeps the hdim filtering that makes its
index space exact; the descale sweep passes its own four axes.

--max-cases 1 now yields one row per table and three sampling lines, and
--max-cases 0 still runs the full 64-row descale sweep, all invariants true
and err 0.
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.

4 participants