[JAX] [PyT] [Common] Enable D=256 BWD cuDNN fused attn for Blackwell CC 10.x #3056
[JAX] [PyT] [Common] Enable D=256 BWD cuDNN fused attn for Blackwell CC 10.x #3056KshitijLakhani wants to merge 26 commits into
Conversation
51ad582 to
d177ecf
Compare
Greptile SummaryThis PR enables D=256 head-dim backward pass support for cuDNN fused attention on Blackwell (SM10x) GPUs by adding a new version-gated condition in the C++ backend selector and matching test coverage across PyTorch, JAX, and distributed CP test suites. BSHD support is gated at cuDNN 9.23+ and THD at cuDNN 9.25+ (the THD path is forward-looking and acknowledged as not yet stable pending a cuDNN fix).
Confidence Score: 5/5Safe to merge once the THD cuDNN version question is resolved and the SM10x guard style is harmonised; the core C++ backend logic is correctly constrained and no existing paths are altered. The C++ change adds a tightly scoped, additive condition that only activates for the exact combination of D=256+SM10x+training+no-bias+no-dropout+vanilla-softmax, leaving every other code path untouched. The THD path is intentionally forward-looking and acknowledged by the author as not yet merged. transformer_engine/common/fused_attn/fused_attn.cpp — confirm whether 9.25 or 9.30 is the correct cuDNN minimum for THD before merging. test_attention.py and test_attention_with_cp.py — consider widening the SM compute-capability allowlist to the full SM10x range to match the backend. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["nvte_get_fused_attn_backend()"] --> B{head_dim_qk == 256 and head_dim_v == 256?}
B -- No --> C[Other head_dim conditions]
B -- Yes --> D{is_training and sm_arch_ in range 100-109?}
D -- No --> C
D -- Yes --> E{is_thd_layout?}
E -- THD --> F{cuDNN >= 9.25?}
E -- BSHD --> G{cuDNN >= 9.23?}
F -- No --> C
G -- No --> C
F -- Yes --> H{bias=NO_BIAS, dropout=0.0, softmax=VANILLA, not paged-KV?}
G -- Yes --> H
H -- Fail --> C
H -- Pass --> I{Window: full-window OR causal-mask with right in -1 or 0?}
I -- No --> C
I -- Yes --> J[flag_arb = true: NVTE_F16_arbitrary_seqlen D=256 BWD]
Reviews (12): Last reviewed commit: "[pre-commit.ci] auto fixes from pre-comm..." | Re-trigger Greptile |
| attn_mask_type == NVTE_Mask_Type::NVTE_PADDING_CAUSAL_MASK || | ||
| attn_mask_type == NVTE_Mask_Type::NVTE_CAUSAL_BOTTOM_RIGHT_MASK || | ||
| attn_mask_type == NVTE_Mask_Type::NVTE_PADDING_CAUSAL_BOTTOM_RIGHT_MASK) && | ||
| (window_size_right == -1 || window_size_right == 0)))) || |
There was a problem hiding this comment.
Could these changes be moved to before "\ bias type" just so it's following an increasing order of the cuDNN version?
There was a problem hiding this comment.
Does this new feature support BSHD/SBHD and THD? It looks like the tests are focused on BSHD/SBHD only.
There was a problem hiding this comment.
RE: THD support
I did test BSHD and BSHD+CP and it did pass on the JAX side and the CI for the PyT side did not fail either so I think that works.
My testing revealed that THD support is not yet available (Bwd plan compialtion issue) so I've filed a bug and shared a reproducer for the same with the cuDNN team: NVIDIA/cudnn-frontend#276
There was a problem hiding this comment.
Could these changes be moved to before "\ bias type" just so it's following an increasing order of the cuDNN version?
Fixed in a264de1
| "D=256 BWD on Blackwell only supports right window -1 or 0" | ||
| " for causal masks." | ||
| ) | ||
|
|
There was a problem hiding this comment.
Aren't these checks duplicate to the checks we added on the C++ side? Would the call FusedAttnHelper().get_fused_attn_backend() give you the same gating effect?
There was a problem hiding this comment.
So if we are just interested in the gating effect, you are right. The get_fused_attn_backend() will return NVTE_No_Backend and then there's a catch-all at the end which basically skip the tests as there is no fused attn backend avalable.
However, the reason for this to be here is to give a meaningful reason as to why a test is being skipped as compared to a generic "Unsupported inputs combination or device compute capability." message which does not qualify the reason for the skip. Unfortunately, on the JAX attn side we do not log the reason for disabling fused attn in the feature code like we have on the Pytorch side in d_p_a/utils.py. So there is no way for the user to know why the test was skipped. Hence, we need to rely on test code to log this on the JAX side.
I'd suggest we leave this in here for now. And when your PR for generating log messages in the C++ level when selecting the attn backend is ready, I can plumb it through onto the JAX side and then as part of that clean up, get rid of all the skip messages in check_configs()
e317f99 to
e08e9e8
Compare
5063b39 to
55f3bb4
Compare
|
Latest testing: Pipeline [56553160] |
a678b84 to
ba0cb94
Compare
|
/te-ci L2 |
| // 9.23: d_qk = d_v = 256 + SM10x (cuDNN FE 1.24 / BE 9.23+) + bprop + non-paged. | ||
| // THD layouts require cuDNN FE 1.26 / BE 9.30+ for execution-plan support. | ||
| (head_dim_qk == 256 && head_dim_v == 256 && is_training && sm_arch_ >= 100 && | ||
| sm_arch_ < 110 && cudnn_runtime_version >= (is_thd_layout ? 93000 : 92300) && |
There was a problem hiding this comment.
The PR body says this should be 92500, not 93000. Which one is correct?
There was a problem hiding this comment.
Good catch !
I've updated the PR body to reflect cuDN 9.30. I believe the body was a preemptive action from me while I was waiting for cuDNN to add support for THD via the C++ API.
There was a problem hiding this comment.
I think cuDNN has renamed 9.30 to 9.25? Please double check!
| # TODO(KshitijLakhani): cuDNN FE can model bias input separately from dBias, | ||
| # but TE does not yet plumb whether dBias is requested into the common backend selector. | ||
| # Until that distinction is available, the D=256 SM10x gate requires no bias. |
| // 9.23: d_qk = d_v = 256 + SM10x (cuDNN FE 1.24 / BE 9.23+) + bprop + non-paged. | ||
| // THD layouts require cuDNN FE 1.26 / BE 9.30+ for execution-plan support. | ||
| (head_dim_qk == 256 && head_dim_v == 256 && is_training && sm_arch_ >= 100 && | ||
| sm_arch_ < 110 && cudnn_runtime_version >= (is_thd_layout ? 93000 : 92300) && |
There was a problem hiding this comment.
Good catch !
I've updated the PR body to reflect cuDN 9.30. I believe the body was a preemptive action from me while I was waiting for cuDNN to add support for THD via the C++ API.
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
for more information, see https://pre-commit.ci
…n fused attn Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
for more information, see https://pre-commit.ci
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
…ersions Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
for more information, see https://pre-commit.ci
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
for more information, see https://pre-commit.ci
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
88217fd to
06eee35
Compare
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
|
Latest testing: Pipeline [58978691] |
| NVTE_QKV_Format kv_format = nvte_get_kv_format(qkv_layout); | ||
| const bool is_thd_layout = q_format == NVTE_QKV_Format::NVTE_THD || | ||
| kv_format == NVTE_QKV_Format::NVTE_THD || | ||
| qkv_format == NVTE_QKV_Format::NVTE_THD; |
There was a problem hiding this comment.
is_thd_layout ORs q_format, kv_format, and the combined qkv_format against NVTE_THD — the third is redundant with the first two, but harmless.
There was a problem hiding this comment.
That's right. Let me get rid of it and push a commit
| "fused_hd256_padding_causal_gqa": ModelConfig( | ||
| 2, 1024, 16, 256, num_gqa_groups=4, attn_mask_type="padding_causal" | ||
| ), | ||
| } |
There was a problem hiding this comment.
Can we reuse some of the configs in other tests (I think there are some h256 ones as well), or can we keep this dict and remove those other h256 ones to deduplicate?
| ), | ||
| ), | ||
| ], | ||
| ) |
There was a problem hiding this comment.
No problem with the "id", but it seems inconsistent with other PyTorch tests. Also, please check the 9.30 vs 9.25 version guard.
| "cp_hd256_causal": ModelConfig(2, 1024, 16, 256, attn_mask_type="causal"), | ||
| "cp_hd256_causal_swa": ModelConfig( | ||
| 2, 1024, 16, 256, attn_mask_type="causal", window_size=(128, 0) | ||
| ), |
There was a problem hiding this comment.
Should we test no_mask, padding_causal as well, or not really?
| ) | ||
| @pytest.mark.parametrize("dtype", ["bf16", "fp16"]) | ||
| @pytest.mark.parametrize("model,qkv_format,cp_comm_type", DPA_CP_FUSED_HD256_CASES) | ||
| def test_cp_with_fused_attention_hdim256(cp_pool, dtype, model, qkv_format, cp_comm_type): |
There was a problem hiding this comment.
Could we fold this into the regular test_cp_with_fused_attention() tests instead of creating this extra test code and extra tests? You can modify some of the existing tests to cover the d256 cases as well, or force some skips if you think it's adding too many tests (I feel your pytest params above might have enumerated all the combinations anyway). Thanks.
Also, please use d256 as the reference, same as in the title, instead of hdim256. (nit)
There was a problem hiding this comment.
Also, please use d256 as the reference, same as in the title, instead of hdim256. (nit)
Done. Do you want me to change it for the Flas Attn tests too ?
| # cuDNN FE 1.26 / BE 9.30. The kernel rejects dBias, dropout, and ALiBi, supports vanilla | ||
| # softmax only, and allows SWA together with a causal mask only. | ||
| is_sm10x = 100 <= compute_capability < 110 | ||
| if self.is_training and is_sm10x and (self.head_dim_qk == 256 or self.head_dim_v == 256): |
There was a problem hiding this comment.
Shouldn't these checks already be covered on the C side? Are these by any chance duplicate?
There was a problem hiding this comment.
IIUC, is your concern the same as you had in your earlier review: #3056 (comment). ? I think my comment goes into more details. Happy to answer any follow ups on that.
I will get rid of these extraneous checks in the tests (if #2964 does not already) once #2964 is merged in. For now, I think we should let them be in. The clean up for these test messages can follow up once we've confirmed that a more descriptive string is plumbed through to the tests
There was a problem hiding this comment.
Sounds good - are there any CP specific skips/conditions we should add?
#2964 will surface the reject reason to Jax FusedAttnHelper.get_fused_attn_backend() so it'd be nice to use that as a single source of rejection/pass reasons. The d256 feature reject reason does come from cudnn-frontend so we should be able to remove some of the code (and reduce some maintenance cost).
| # TODO(KshitijLakhani): cuDNN FE can model bias input separately from dBias, | ||
| # but TE does not yet plumb whether dBias is requested into the common backend selector. | ||
| # Until that distinction is available, the D=256 SM10x gate requires no bias. |
There was a problem hiding this comment.
#2964 will plumb bias/dbias shapes/requirements to the C side, so hopefully when that's merged, this wouldn't be an issue.
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
da25221 to
e3032d3
Compare
for more information, see https://pre-commit.ci
Description
Support for D=256 BWD for Blackwell CC 10x via the C++ API (which TE uses) was added in cuDNN 9.23 + cuDNN FE 1.24 (BSHD) and cuDNN 9.30 + cuDNN FE 1.26 (THD)
Enabling this support in TE attention and adding conditional tests for the same
Type of change
Changes
Add guard when picking the backend (sub backend) in TE common.
Add tests for D=256 case in TE PyT and TE JAX
Checklist: