Enable FA4 for context-parallel attention - #3149
Open
sudhakarsingh27 wants to merge 3 commits into
Open
Conversation
Contributor
Greptile SummaryEnables FlashAttention 4 for supported context-parallel attention paths.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[DotProductAttention] --> B{Context parallel?}
B -->|No| C[Standard attention backend]
B -->|Yes| D{CP communication type}
D -->|p2p| E[FA4 P2P forward/backward]
D -->|all_gather| F[FA4 all-gather forward/backward]
D -->|a2a| G[FA4 A2A forward/backward]
D -->|a2a+p2p| H[Disable FA4]
E --> I{Padded THD?}
F --> I
G --> I
I -->|Yes| J[Padded cu_seqlens plus seqused lengths]
I -->|No| K[Regular FA4 arguments]
Reviews (7): Last reviewed commit: "Merge current main into FA4 CP support" | Re-trigger Greptile |
Add minimal FA4 raw-call plumbing for p2p, all_gather, and a2a context-parallel attention. FA4 accepts padded THD cu_seqlens plus seqused values, so keep padded physical offsets separate from visible token lengths for CP and non-CP reference paths. Keep a2a+p2p disabled because that hierarchical path has not been validated for FA4. Update CP tests so FA4-only environments do not skip the FlashAttention CP matrix before the FA4-specific guards run. Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
for more information, see https://pre-commit.ci
Bring PR 3149 onto the latest upstream code so the FA4 context-parallel paths can be validated against current main. Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
sudhakarsingh27
force-pushed
the
fa4-cp-exploration
branch
from
July 30, 2026 00:04
c916e56 to
667c244
Compare
sudhakarsingh27
commented
Jul 30, 2026
Comment on lines
+303
to
+306
| @pytest.mark.skipif( | ||
| not (FlashAttentionUtils.v2_plus or FlashAttentionUtils.v4_is_installed), | ||
| reason="Flash-attn 2.0+ or Flash-attn 4 is required.", | ||
| ) |
Member
Author
There was a problem hiding this comment.
Shouldn't 2.0+ also apply to flash-attn 4?
| **fa_forward_kwargs, | ||
| ) | ||
| else: | ||
| fa_forward_args_thd = get_fa_args( |
Member
Author
There was a problem hiding this comment.
is it possible to extend get_fa_args instead of creating a new get_fa4_thd_kwargs?
cyanguwa
reviewed
Aug 6, 2026
| "Disabling FlashAttention 4 for context parallelism with cp_comm_type = %s", | ||
| cp_comm_type, | ||
| ) | ||
| use_flash_attention_4 = False |
Collaborator
There was a problem hiding this comment.
Please make sure the CI is running FA4 and for all the relevant tests.
| dv=dv, | ||
| seqused_q=seqused_q, | ||
| seqused_k=seqused_k, | ||
| ) |
Collaborator
There was a problem hiding this comment.
Same here, as the comment above about fwd.
sudhakarsingh27
force-pushed
the
fa4-cp-exploration
branch
from
August 12, 2026 05:51
a777924 to
667c244
Compare
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.
Description
Enable FlashAttention 4 for context-parallel attention on the supported
p2p,all_gather, anda2apaths;a2a+p2premains disabled pending validation.FA4 can represent padded THD layouts with physical padded offsets plus
seqused_*visible lengths. This lets the CP path preserve the layout distinction used by the non-CP reference path.This PR is limited to FA4 context-parallel enablement. FlashAttention package isolation, unsupported-configuration gating, and test-helper import fixes remain in #3341.
Type of change
Changes
p2p,all_gather, anda2apaths.cu_seqlens_*together withseqused_*for FA4.a2a+p2p.Validation
6 passed, 10 skipped, 48 deselectedper platform.git diff --check.Checklist