Repository navigation
[Triton/Gluon] Fix Flash Attention main ci - #6859
micmelesse wants to merge 6 commits into
Conversation
Reuse the shared causal and sliding-window predicate in fused dQ, retain the backward end_n bound, and mask logits before exponentiation. Add a low-level dropout and ALiBi regression test.
🏷️ 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 regression test must use the public wrapper and specify an explicit dtype for its ALiBi slopes.
2 open issues
What changed in this PR
This PR addresses Flash Attention CI failures by changing dQ backward masking and adding a focused regression test.
Changes:
- Reuses
attention_maskand masks invalid logits before exponentiation. - Adds gfx950 backward checks for causal attention with dropout and ALiBi, including a padded head dimension.
| File | Description |
|---|---|
op_tests/triton_tests/attention/test_mha_dao_ai.py |
Adds two regression cases that compare gradients against a reference. |
aiter/ops/triton/_triton_kernels/flash_attn_triton_amd/bwd.py |
Replaces local dQ masking logic with the shared helper before exponentiation. |
Review effort: Balanced
7ca2392 to
1da3992
Compare
21bc0f3 to
da7cb76
Compare
Compute dK/dV and dQ in separately compiled phases while keeping the 128-row tile. Apply the causal probability mask after the exponential.
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
|
Sorry @azaidy and @brunomazzottiamd, I am putting this in draft. I want to get #6502 merged first. I will ping you when this pr is ready. |
No worries @micmelesse! I started reviewing this PR 10 minutes ago! I'll publish some minor nitpicks related to the test, address them at your judgment. |
brunomazzottiamd
left a comment
There was a problem hiding this comment.
Sharing minor nitpicks.
| def test_mha_dao_ai_causal_dropout_alibi_backward( | ||
| dao_ai_impl, batch, seqlen_q, seqlen_k, head_dim, nheads_k, varlen | ||
| ): | ||
| from aiter.ops.triton.utils._triton.arch_info import get_arch |
There was a problem hiding this comment.
Can we import get_arch at module top level instead of inside a test function?
| if get_arch() != "gfx950": | ||
| pytest.skip("gfx950 causal backward configuration regression") |
There was a problem hiding this comment.
Suggestion / non-blocker: Implement the skip with an annotation.
@pytest.mark.skipif(get_arch() != "gfx950", reason="gfx950 causal backward configuration regression")| for actual, expected in ((dq, dq_ref), (dk, dk_ref), (dv, dv_ref)): | ||
| assert torch.isfinite(actual).all() | ||
| torch.testing.assert_close(actual, expected, atol=1e-2, rtol=1e-2) |
There was a problem hiding this comment.
Can you please add messages to this assertions, saying which tensor is failing (dq, dk, dv)? I think this improve troubleshooting in case of failures.


Summary
Fix gfx950 causal Flash Attention backward failures in aiter's Dao-AI Triton path. The backward fix passed the complete ordered FA2 test file on a local gfx950 node.
Motivation
Flash Attention CI on aiter main found incorrect gradients and native aborts in causal backward cases. The previous dQ mask handling and fused backward program were sensitive to gfx950 code generation. Dao-AI dropout backward also needs the RNG state returned by forward.
Changes
Performance (if applicable)
The comparison below uses the PR base and current head
4c315368don the same local gfx950 GPU withbench_mha.py -impl dao_ai -metric throughputand equal sequence lengths.The d56 windowed backward case remains slower than the PR base. A 380-case sweep of a preparatory scratch revision found six cases more than 10% below the base. The full sweep has not been rerun on this head.
Testing
Documentation
The change is internal to the existing Flash Attention implementation and does not change its public API.
Dependencies
Breaking Changes
None.
PR Self-Review
Reviewed revision
4c315368d3fabd9b2f7bf5865867704ae7b4de90Behavior and intent
The PR corrects gfx950 causal backward gradients and prevents the tested native aborts. It masks invalid dQ logits before exponentiation, simplifies the causal phase bodies, gives dropout backward the forward RNG state, and separates windowed and unwindowed autotune entries. The previous behavior failed the FA2 correctness cases described below.
Validation and unverified scope
832eafce1passed the complete ordered FA2 test file withFLASH_ATTENTION_TRITON_AMD_AUTOTUNE=0: 60,576 passed and 27,004 skipped. The 12 new regression cases and four previously failing FA cases also passed.4c315368dpassed 41 targeted Dao-AI tests with autotuning enabled. The complete FA2 file has not been rerun after the autotune-key change.PR-specific question
The new op test checks for incorrect or nonfinite dQ, dK, and dV, or an abort, in gfx950 causal backward with dropout and ALiBi. Its dense 113×203 d59 case covers the main CI gradient failure. Existing Dao-AI backward tests do not combine these conditions, and the existing dropout-scores test checks forward output rather than gradients.
Changed op tests
op_tests/triton_tests/attention/test_mha_dao_ai.pyadds a public-wrapper autograd comparison against a PyTorch reference for six shapes in both dense and varlen layouts, including MHA, MQA, GQA, unequal sequence lengths, and padded head dimensions. This covers the failing backward combinations absent from the existing tests.