[CuTe, Fwd] Fix forward compile key churn when max_seqlen is a tensor - #2762
Merged
jayhshah merged 1 commit intoAug 7, 2026
Merged
Conversation
jayhshah
self-requested a review
August 7, 2026 02:20
jayhshah
approved these changes
Aug 7, 2026
Collaborator
|
btw this breaks because we end up passing a pytorch tensor into the kernel for the max_seqlen_q slot even though we are running the persistent kernel |
This was referenced Aug 23, 2026
StevenWang-CY
pushed a commit
to StevenWang-CY/flash-attention
that referenced
this pull request
Aug 28, 2026
(cherry picked from commit 1cc7ff6) Signed-off-by: StevenWang-CY <stevenwang0805@outlook.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
max_seqlen_q/max_seqlen_kare CUDA tensors, as in Hugging Face varlen and padding-free attention,_flash_attn_fwdcan place a fresh 0-D tensor in its compile key. Identical forward calls then miss the JIT cache and recompile on every invocation, significantly slowing down training.This is the forward counterpart of #2507.
Root Cause
max_m_blocks_leq_oneinherits the tensor type frommax_seqlen_q:When this predicate is false, the Python boolean expression used to compute is_static_persistent can return the tensor itself instead of a Python bool. Since is_static_persistent is included in the forward compile key, each newly created tensor produces a different cache key.
Fix
Only use the
max_m_blocks_leq_onestatic-persistent shortcut when the predicate is not a tensor.This keeps the compile key host-scalar-only and avoids calling
.item(), so the fix does not introduce a CPU-GPU synchronization. Tensor-valued callers conservatively use the non-static-persistent path.Verification
Added a regression test that:
Tested on NVIDIA RTX PRO 6000 Blackwell (SM120):
Result:
1 passed
The full FakeTensor fast suite also passes:
192 passed, 49 skipped