-
Notifications
You must be signed in to change notification settings - Fork 708
[PyTorch] Add pad_between_seqs support for non-CP and CP (A2A and P2P) with FA3 + THD (varlen)
#2596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sudhakarsingh27
wants to merge
7
commits into
NVIDIA:main
Choose a base branch
from
sudhakarsingh27:flash_attn_pad_bw_seqs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[PyTorch] Add pad_between_seqs support for non-CP and CP (A2A and P2P) with FA3 + THD (varlen)
#2596
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
10e4cfc
[PyTorch] Add pad_between_seqs support for FlashAttention 3 with CP
sudhakarsingh27 2a49dee
[PyTorch] Add pad_between_seqs tests for CP and non-CP FlashAttention
sudhakarsingh27 34e3d62
[QA] Add CP deterministic tests to L3 and support TE_PATH in FA test
sudhakarsingh27 4745f98
[PyTorch] Fix FA3 deterministic gate to match upstream backward const…
sudhakarsingh27 4be004f
[PyTorch] Disable FlashAttention 4 for pad_between_seqs with THD
sudhakarsingh27 c476f15
Merge branch 'main' of github.com:NVIDIA/TransformerEngine into flash…
sudhakarsingh27 a2b0f1b
[QA] Fix cutlass-dsl utils shadow in FA versions test
sudhakarsingh27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,11 +91,20 @@ def get_bash_arguments(num_gpus_per_node, **kwargs): | |
| @pytest.mark.parametrize("model", model_configs_flash_attn.keys()) | ||
| @pytest.mark.parametrize("qkv_format", qkv_formats) | ||
| @pytest.mark.parametrize("cp_comm_type", cp_comm_types) | ||
| def test_cp_with_flash_attention(dtype, model, qkv_format, cp_comm_type): | ||
| @pytest.mark.parametrize("pad_between_seqs", [False, True]) | ||
| def test_cp_with_flash_attention(dtype, model, qkv_format, cp_comm_type, pad_between_seqs): | ||
| num_gpus = 4 if cp_comm_type == "a2a+p2p" else 2 | ||
| if num_gpus > torch.cuda.device_count(): | ||
| pytest.skip(f"Test requires {num_gpus} GPUs, but found {torch.cuda.device_count()}") | ||
|
|
||
| if pad_between_seqs: | ||
| if qkv_format != "thd": | ||
| pytest.skip("pad_between_seqs only applies to THD format!") | ||
| if not FlashAttentionUtils.v3_is_installed: | ||
| pytest.skip("pad_between_seqs with CP requires Flash Attention v3!") | ||
| if cp_comm_type == "a2a+p2p": | ||
| pytest.skip("pad_between_seqs is not yet supported with A2A+P2P CP comm type!") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about AG? |
||
|
|
||
| config = model_configs_flash_attn[model] | ||
| config.context_parallel = True | ||
| config.cp_comm_type = cp_comm_type | ||
|
|
@@ -148,6 +157,7 @@ def test_cp_with_flash_attention(dtype, model, qkv_format, cp_comm_type): | |
| qkv_format=qkv_format, | ||
| kernel_backend="FlashAttention", | ||
| cp_comm_type=cp_comm_type, | ||
| fa_pad_between_seqs=pad_between_seqs, | ||
| log_level=pytest_logging_level, | ||
| ), | ||
| ) | ||
|
|
@@ -386,6 +396,7 @@ def test_cp_with_fused_attention( | |
| is_training=is_training, | ||
| deterministic=_deterministic, | ||
| ) | ||
|
|
||
| _, fused_attn_supported, _ = available_backends | ||
| if fused_attn_supported and config.attn_mask_type in ["causal", "padding_causal"]: | ||
| config_copy = copy.deepcopy(config) | ||
|
|
@@ -404,6 +415,15 @@ def test_cp_with_fused_attention( | |
| if not fused_attn_supported: | ||
| pytest.skip("No attention backend available.") | ||
|
|
||
| deterministic = not bool(int(os.getenv("NVTE_ALLOW_NONDETERMINISTIC_ALGO", "1"))) | ||
| if deterministic: | ||
| if config.softmax_type != "vanilla": | ||
| pytest.skip( | ||
| "Deterministic mode does not support non-vanilla softmax with FusedAttention" | ||
| ) | ||
| if config.attn_bias_type == "post_scale_bias" and is_training: | ||
| pytest.skip("Deterministic mode does not support post_scale_bias with requires_grad") | ||
|
|
||
| run_distributed( | ||
| get_bash_arguments( | ||
| num_gpus_per_node=num_gpus, | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.