Skip to content

[CuTe, SM120] Fix forward/backward bugs and add SM120 test guards - #2420

Closed
2imi9 wants to merge 2 commits into
Dao-AILab:mainfrom
2imi9:fix/sm120-forward-backward-and-tests
Closed

[CuTe, SM120] Fix forward/backward bugs and add SM120 test guards#2420
2imi9 wants to merge 2 commits into
Dao-AILab:mainfrom
2imi9:fix/sm120-forward-backward-and-tests

Conversation

@2imi9

@2imi9 2imi9 commented Apr 1, 2026

Copy link
Copy Markdown

Bug fixes:

  • flash_fwd_sm120.py: Override self.arch after parent init to prevent SM80 epilogue from enabling TMA-O store on SM120
  • interface.py: Initialize dQ_single_wg and num_stages_PdS in SM120 backward config (fixes NameError in compile_key)
  • interface.py: Fix hdim>128 forward tile sizes for SM120 99KB SMEM
  • utils.py: Replace nvvm.atomicrmw with inline PTX red.global.add.f32 for newer NVVM Python bindings compatibility
  • init.py: Graceful FA2 import fallback when flash_attn_2_cuda is not built

Test guards (tests/cute/test_flash_attn.py):

Tested on RTX 5090 Laptop GPU (SM 12.0): 240 test_flash_attn_output cases passed (MHA, bf16, hdim 64/128/192/256, causal/non-causal, multiple sequence lengths, forward + backward).

Builds on #2404 (bug fixes by @NJX-njx).

Bug fixes:
- flash_fwd_sm120.py: Override self.arch after parent __init__ to
  prevent SM80 epilogue from enabling TMA-O store on SM120
- interface.py: Initialize dQ_single_wg and num_stages_PdS in SM120
  backward config (fixes NameError in compile_key)
- interface.py: Fix hdim>128 forward tile sizes for SM120 99KB SMEM
- utils.py: Replace nvvm.atomicrmw with inline PTX red.global.add.f32
  for newer NVVM Python bindings compatibility
- __init__.py: Graceful FA2 import fallback when flash_attn_2_cuda
  is not built

Test guards (tests/cute/test_flash_attn.py):
- Add IS_SM120 flag
- Skip: SplitKV, deterministic backward, learnable_sink, paged KV
- Skip: GQA/MQA (pack_gqa crd2idx incompatibility on newer CUTLASS DSL)
- TODO markers reference tracking PRs (#2336, #2348, #2389)

Tested on RTX 5090 Laptop GPU (SM 12.0): 240 test_flash_attn_output
cases passed (MHA, bf16, hdim 64/128/192/256, causal/non-causal,
multiple sequence lengths, forward + backward).

Builds on #2404 (bug fixes by @NJX-njx).

Co-Authored-By: NJX-njx <NJX-njx@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d3334eb55f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread flash_attn/__init__.py Outdated
flash_attn_varlen_qkvpacked_func,
flash_attn_with_kvcache,
)
except ImportError:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Re-raise unexpected import errors

Catching a bare ImportError here suppresses all failures from flash_attn.flash_attn_interface, not just the missing flash_attn_2_cuda case this fallback is meant to handle. In scenarios like ABI mismatch, dependency regressions, or import-time bugs inside flash_attn_interface, import flash_attn will now appear to succeed but silently drop the public symbols, leading to later AttributeError/missing-function failures that are much harder to diagnose.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, narrowed to ModuleNotFoundError in 715919c.

Only suppress the missing flash_attn_2_cuda module error, not
unexpected ImportError from ABI mismatch or other failures.
blake-snc added a commit to blake-snc/flash-attention-dao that referenced this pull request Apr 2, 2026
Override self.arch = Arch.sm_80 after parent __init__ to prevent base
class code paths from seeing the runtime arch (12.x) and enabling
SM90+ features. The parent __init__ overwrites the class-level arch=80
attribute with the actual GPU arch. This was found by @2imi9 in Dao-AILab#2420
for the CpAsync kernel — same bug applies here.

Add can_implement() check before TMA dispatch in interface.py so that
configs exceeding SM120's 99KB SMEM (e.g. hdim=192 with kv_stages=2)
fall back to the CpAsync kernel instead of failing at instantiation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Blake Ledden <blake@secondnaturecomputing.com>
blake-snc added a commit to blake-snc/flash-attention-dao that referenced this pull request Apr 16, 2026
Override self.arch = Arch.sm_80 after parent __init__ to prevent base
class code paths from seeing the runtime arch (12.x) and enabling
SM90+ features. The parent __init__ overwrites the class-level arch=80
attribute with the actual GPU arch. This was found by @2imi9 in Dao-AILab#2420
for the CpAsync kernel — same bug applies here.

Add can_implement() check before TMA dispatch in interface.py so that
configs exceeding SM120's 99KB SMEM (e.g. hdim=192 with kv_stages=2)
fall back to the CpAsync kernel instead of failing at instantiation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Blake Ledden <blake@secondnaturecomputing.com>
@2imi9 2imi9 closed this by deleting the head repository Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant