diff --git a/tests/pytorch/attention/run_attention_with_cp.py b/tests/pytorch/attention/run_attention_with_cp.py index 82b9df262f..332c4e3ae2 100644 --- a/tests/pytorch/attention/run_attention_with_cp.py +++ b/tests/pytorch/attention/run_attention_with_cp.py @@ -209,6 +209,11 @@ def run_dpa_with_cp( logging.root.setLevel(log_level) # When is_training is False, gradient outputs are None. is_training = is_training == "True" + pad_between_seqs = None + if qkv_format == "thd": + # Keep this in sync with generate_input_shapes so DPA gets the explicit + # padding state without a GPU-to-CPU sync. + pad_between_seqs = kernel_backend == "FusedAttention" or fa_pad_between_seqs == "True" # set up environment variables and config if deterministic == "True": @@ -411,13 +416,7 @@ def run_dpa_with_cp( cu_seqlens_kv=cu_seqlens_kv, cu_seqlens_q_padded=cu_seqlens_q_padded, cu_seqlens_kv_padded=cu_seqlens_kv_padded, - # Test runner sets cu_seqlens_q == cu_seqlens_q_padded for the - # FlashAttention path, i.e. no inter-sequence padding. Declare this - # explicitly so the sync-free auto-detect (which conservatively - # picks True when padded cu_seqlens are present) does not disable FA. - pad_between_seqs=( - (kernel_backend != "FlashAttention") if qkv_format == "thd" else None - ), + pad_between_seqs=pad_between_seqs, fp8_output=fp8_mha, ) if config.return_max_logit: @@ -535,12 +534,7 @@ def run_dpa_with_cp( cu_seqlens_kv=cu_seqlens_kv, cu_seqlens_q_padded=cu_seqlens_q_padded, cu_seqlens_kv_padded=cu_seqlens_kv_padded, - # See note above (non-CP branch): same explicit declaration so - # FlashAttention isn't disabled by the conservative sync-free - # auto-detect when this test path constructs no inter-seq padding. - pad_between_seqs=( - (kernel_backend != "FlashAttention") if qkv_format == "thd" else None - ), + pad_between_seqs=pad_between_seqs, fp8_output=fp8_mha, ) if config.return_max_logit: