Skip to content

[JAX] [PyT] [Common] Enable D=256 BWD cuDNN fused attn for Blackwell CC 10.x - #3056

Open
KshitijLakhani wants to merge 31 commits into
NVIDIA:mainfrom
KshitijLakhani:klakhani/feat/enable-headdim256-bwd-sm100
Open

[JAX] [PyT] [Common] Enable D=256 BWD cuDNN fused attn for Blackwell CC 10.x #3056
KshitijLakhani wants to merge 31 commits into
NVIDIA:mainfrom
KshitijLakhani:klakhani/feat/enable-headdim256-bwd-sm100

Conversation

@KshitijLakhani

@KshitijLakhani KshitijLakhani commented May 28, 2026

Copy link
Copy Markdown
Collaborator

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

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

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:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@KshitijLakhani
KshitijLakhani force-pushed the klakhani/feat/enable-headdim256-bwd-sm100 branch from 51ad582 to d177ecf Compare May 28, 2026 23:05
@KshitijLakhani KshitijLakhani changed the title [JAX] [Common] Enable D=256 BWD cuDNN fused attn for Blackwell CC 10.x [JAX] [PyT] [Common] Enable D=256 BWD cuDNN fused attn for Blackwell CC 10.x May 28, 2026
@KshitijLakhani
KshitijLakhani marked this pull request as ready for review May 29, 2026 22:56
@KshitijLakhani
KshitijLakhani requested a review from cyanguwa as a code owner May 29, 2026 22:56
@KshitijLakhani KshitijLakhani self-assigned this May 29, 2026
@greptile-apps

greptile-apps Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR enables SM10x D=256 fused-attention backward dispatch and expands corresponding JAX and PyTorch coverage.

  • Adds architecture, cuDNN-version, layout, bias, dropout, softmax, and window guards to the common backend selector.
  • Adds single-device and context-parallel D=256 tests for JAX and PyTorch.
  • Repairs the PyTorch CP runner’s fused-attention configuration import and lookup.

Confidence Score: 3/5

The PR is not yet safe to merge until THD D=256 execution-plan support at the new cuDNN 9.25 threshold is verified or the selector excludes THD.

The selector now routes THD D=256 backward to the cuDNN backend at version 9.25, but the available evidence does not establish that the previously reported execution-plan failure is resolved; if it remains, plan construction raises a hard runtime error without fallback.

Files Needing Attention: transformer_engine/common/fused_attn/fused_attn.cpp

Important Files Changed

Filename Overview
transformer_engine/common/fused_attn/fused_attn.cpp Adds constrained SM10x D=256 backward backend selection, including a THD-specific cuDNN 9.25 threshold whose runtime support remains unverified.
tests/jax/test_fused_attn.py Aligns D=256 test skips with the common selector and adds BSHD and THD coverage.
tests/jax/test_distributed_fused_attn.py Adds version-gated D=256 ring and all-gather context-parallel test coverage.
tests/pytorch/attention/test_attention.py Adds isolated D=256 attention configurations and copies shared configurations before mutation.
tests/pytorch/attention/test_attention_with_cp.py Adds D=256 context-parallel configurations with hardware, dtype, communication, and cuDNN guards.
tests/pytorch/attention/run_attention_with_cp.py Fixes the undefined configuration import and resolves D=256 models through the existing fused-attention dictionary.
qa/L1_jax_distributed_unittest/test.sh Reorders the distributed fused-attention suite ahead of the softmax-specific XLA flag invocation.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["JAX / PyTorch attention"] --> B["Common fused-attention selector"]
  B --> C{"SM10x D=256 constraints satisfied?"}
  C -- "No" --> D["No fused backend / framework fallback"]
  C -- "Yes" --> E["NVTE_F16_arbitrary_seqlen"]
  E --> F["cuDNN execution-plan validation and build"]
  F --> G["D=256 backward"]
Loading

Reviews (18): Last reviewed commit: "[pre-commit.ci] auto fixes from pre-comm..." | Re-trigger Greptile

Comment thread tests/pytorch/attention/test_attention.py Outdated
Comment thread tests/jax/test_fused_attn.py Outdated
Comment thread transformer_engine/common/fused_attn/fused_attn.cpp Outdated
Comment thread tests/jax/test_fused_attn.py
@KshitijLakhani
KshitijLakhani force-pushed the klakhani/feat/enable-headdim256-bwd-sm100 branch from e317f99 to e08e9e8 Compare June 3, 2026 21:48
Comment thread transformer_engine/common/fused_attn/fused_attn.cpp Outdated
@KshitijLakhani

KshitijLakhani commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

Latest testing: Pipeline [56553160]
I manually set the cuDNN BE in the CI to be 9.30+ and the cuDNN FE to point at latest develop as of 07/01/26 to test the THD support for D=256
I confirmed that the newly added tests for BSHD and THD (PyT and JAX, both) pass

@KshitijLakhani
KshitijLakhani force-pushed the klakhani/feat/enable-headdim256-bwd-sm100 branch from a678b84 to ba0cb94 Compare July 8, 2026 04:55
@KshitijLakhani

Copy link
Copy Markdown
Collaborator Author

/te-ci L2

@KshitijLakhani
KshitijLakhani requested a review from cyanguwa July 8, 2026 05:08
Comment thread transformer_engine/common/fused_attn/fused_attn.cpp Outdated
Comment thread tests/jax/test_fused_attn.py
Comment thread transformer_engine/common/fused_attn/fused_attn.cpp Outdated
KshitijLakhani and others added 9 commits July 21, 2026 10:29
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>
…n fused attn

Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
KshitijLakhani and others added 5 commits July 21, 2026 10:29
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>
@KshitijLakhani
KshitijLakhani force-pushed the klakhani/feat/enable-headdim256-bwd-sm100 branch from 88217fd to 06eee35 Compare July 21, 2026 17:30
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
@KshitijLakhani

Copy link
Copy Markdown
Collaborator Author

Latest testing: Pipeline [58978691]
I manually set the cuDNN BE in the CI to be 9.30+ and the cuDNN FE to be 1.26 to test the THD support for D=256
I confirmed that the newly added tests for BSHD and THD (PyT and JAX, both) pass for non-CP and CP

Comment thread transformer_engine/common/fused_attn/fused_attn.cpp Outdated
Comment thread tests/pytorch/attention/test_attention.py
),
),
],
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem with the "id", but it seems inconsistent with other PyTorch tests. Also, please check the 9.30 vs 9.25 version guard.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the 'id' fields actually - they just look really odd sitting next to other tests with no 'id's. :D

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done SHA 5ef0d4f

"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)
),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we test no_mask, padding_causal as well, or not really?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's okay to not test those two, if you are fine with it ?
The non-CP tests cover no_mask and I believe THD CP anyways translates to padding_causal under the hood, so I decided to keep this lightweight.

Comment thread tests/pytorch/attention/test_attention_with_cp.py Outdated
Comment thread tests/jax/test_fused_attn.py
Comment thread tests/jax/test_fused_attn.py
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>
@KshitijLakhani
KshitijLakhani force-pushed the klakhani/feat/enable-headdim256-bwd-sm100 branch from da25221 to e3032d3 Compare July 23, 2026 00:22
@KshitijLakhani
KshitijLakhani requested a review from cyanguwa July 24, 2026 04:03
Comment thread tests/pytorch/attention/run_attention_with_cp.py Outdated
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
@KshitijLakhani
KshitijLakhani force-pushed the klakhani/feat/enable-headdim256-bwd-sm100 branch from 078c80f to 9921b99 Compare July 27, 2026 00:37
@KshitijLakhani

Copy link
Copy Markdown
Collaborator Author

Latest testing: Pipeline 59713381
I manually set the cuDNN BE in the CI to be 9.25+ (cuDNN FE defaults to 1.26) to test the full support for D=256. This pipeline uses base image ghcr.io/nvidia/jax:jax for JAX and defaults for PyT and Core.
I confirmed that the newly added tests for BSHD and THD (PyT and JAX, both) pass for non-CP and CP

),
],
)
def test_dpa_fused_attn_d256(dtype, model_configs, model, qkv_layout):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove the "fused_xx" keyword from model_configs_fused_d256, fused_d256_no_mask, and test_dpa_fused_attn_d256. Those tests will run both unfused/flash and fused for comparison. Maybe there's no need to restrict it to "fused". Essentially what we want to test here is d256.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done SHA eda1a74

cyanguwa
cyanguwa previously approved these changes Jul 27, 2026

@cyanguwa cyanguwa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the two nits (test name change and 'id' removal), looks good!

// Blackwell rejects dBias, dropout, and ALiBi (and supports vanilla softmax only).
bias_type == NVTE_Bias_Type::NVTE_NO_BIAS && dropout == 0.0 &&
softmax_type == NVTE_Softmax_Type::NVTE_VANILLA_SOFTMAX &&
// Non-causal D=256 supports only full-window attention; SWA is allowed only for causal masks.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants