-
Notifications
You must be signed in to change notification settings - Fork 730
[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
[PyTorch] Add pad_between_seqs support for non-CP and CP (A2A and P2P) with FA3 + THD (varlen)
#2596
Changes from 9 commits
10e4cfc
2a49dee
34e3d62
4745f98
4be004f
c476f15
a2b0f1b
b94e175
fc9182f
636666f
7928bc9
1585ebb
2464f43
789ccf0
0a32185
c33cf2d
13ba004
e41bb96
7b8ca1e
e02b658
9389309
77941e0
d8e8ba4
8794aa8
908ca2b
c4b6e07
d3bd4e4
0638d58
3b1e4ce
1563b10
a27e301
2b05809
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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,21 @@ 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") | ||
| if qkv_format == "thd" and config.num_heads >= 20 and get_device_compute_capability() == (9, 0): | ||
| pytest.skip( | ||
| "Deterministic FusedAttention backward with THD format OOMs on sm90" | ||
| " for this particular test config since cuDNN reserves memory" | ||
| " proportional to bHSS (known cuDNN issue)." | ||
| ) | ||
|
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. The motivation for this makes sense to me but seems like the way we are skipping the test is viewing it from a slightly narrow lens. What I mean by that is the main issue is total memory (bhSS) but we seem to be guarding on head dims only This skip guard would not be correct if tomorrow someone were to add a test with small b,S and H>20 (IIUC) - it almost makes it seem that the issue is the num_heads rather than the total memory Is there a better way to do this ?
Member
Author
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. Good catch — gated on the actual |
||
|
|
||
| run_distributed( | ||
| get_bash_arguments( | ||
| num_gpus_per_node=num_gpus, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.