Skip to content

[All] Guard THD learnable dSink on older cuDNN - #3470

Merged
KshitijLakhani merged 3 commits into
NVIDIA:mainfrom
KshitijLakhani:klakhani/fix/dsink-cudnn-bug
Oct 14, 2026
Merged

KshitijLakhani merged 3 commits into
NVIDIA:mainfrom
KshitijLakhani:klakhani/fix/dsink-cudnn-bug

Conversation

@KshitijLakhani

@KshitijLakhani KshitijLakhani commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

Description

cuDNN versions before 9.26 have a known backward-pass issue for learnable softmax with packed THD inputs. The generic kernel can incorrectly index ragged softmax statistics, producing an incorrect dSink or a potential out-of-bounds read.

Fixes #3249 (potentially)

Validation

  • Locally validated backend selection across affected and unaffected configurations.
  • Confirmed that the issue reproducer passes with cuDNN 9.26.0.37.
  • Confirmed the existing THD softmax regression test passes.
  • Did not add CI tests, even though I validated locally

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

The change in this PR disables FusedAttention when all the following apply:

  • Training with packed THD inputs
  • Learnable softmax
  • cuDNN older than 9.26
  • head_dim_v is not 64, 128, or 256

When the guard is triggered, TE warns the user to upgrade to cuDNN 9.26 or later. TE falls back to UnfusedDotProductAttention when available; otherwise, the existing “no backend available” error is raised.
Note: Inference, non-THD layouts, other softmax types, and cuDNN 9.26+ are unchanged.

  • Common C++ change: implements the actual guard. It makes nvte_get_fused_attn_backend() return NVTE_No_Backend for the affected configuration. This protects PyTorch, JAX, and direct common callers.

  • PyTorch/Jax change: only recognizes why common returned No_Backend and prints the targeted cuDNN 9.26 warning. It does not independently guard the fused backend.

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

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch L0 L1

@KshitijLakhani KshitijLakhani self-assigned this Sep 3, 2026
@KshitijLakhani
KshitijLakhani marked this pull request as ready for review September 3, 2026 07:23
@greptile-apps

greptile-apps Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The latest revision appears safe to merge; it changes no runtime behavior.

Summary

The guard now permits learnable-softmax training with packed THD inputs on older cuDNN when head_dim_v is 64, 128, or 256.

  • Older cuDNN keeps fused attention eligible for three THD value-head sizes.

Reviews (6) · Last reviewed commit: "nit: Remove extra comment" · Reviewed by Greptile

@KshitijLakhani KshitijLakhani added bug Something isn't working attention labels Sep 4, 2026
and softmax_type == "learnable"
and cudnn_version < (9, 26, 0)
and head_dim_v not in (64, 128, 256)
):

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.

Is this for Hopper only, or all arches?

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 confirmed with @vedaanta and it is not Hopper specific

@KshitijLakhani
KshitijLakhani force-pushed the klakhani/fix/dsink-cudnn-bug branch from 5f5f4e4 to 4fc35a5 Compare September 4, 2026 21:35
@KshitijLakhani KshitijLakhani changed the title [PyT] Guard THD learnable dSink on older cuDNN [PyT] [common] Guard THD learnable dSink on older cuDNN Sep 4, 2026
@KshitijLakhani
KshitijLakhani force-pushed the klakhani/fix/dsink-cudnn-bug branch from a967b8e to d930129 Compare September 4, 2026 22:00
@KshitijLakhani KshitijLakhani changed the title [PyT] [common] Guard THD learnable dSink on older cuDNN [All] Guard THD learnable dSink on older cuDNN Sep 4, 2026
@KshitijLakhani

Copy link
Copy Markdown
Collaborator Author

/te-ci L0 L1

and qkv_layout.is_thd()
and softmax_type == AttnSoftmaxType.LEARNABLE_SOFTMAX
and get_cudnn_version() < (9, 26, 0)
and head_dim_v not in (64, 128, 256)

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.

Sounds like we should disable all head dims for cuDNN < 9.26 based on our Slack conversation? Also, do we need the "not deterministic" here?

"use FusedAttention for this configuration.",
head_dim_v,
)
else:

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.

Do we still need this if we already have the logic in common? I know Jax is a bit different and might still need it?

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.

The common code is the actual guard. This PyT condition runs only after common has returned No_Backend; it does not affect backend selection. It was added only to distinguish this known cuDNN rejection from other unsupported configs and emit the targeted upgrade warning, because the old common API returned only a backend enum. So, I was just trying to properly qualify that message.

However, after #2964, TE common now returns both the backend and its rejection message, so after rebasing this frontend predicate is no longer necessary. PyT and JAX can use the diagnostic supplied by common.

const bool has_f16_ragged_dsink_bug = is_training && qkv_format == NVTE_QKV_Format::NVTE_THD &&
softmax_type == NVTE_Softmax_Type::NVTE_LEARNABLE_SOFTMAX &&
cudnn_runtime_version < 92600 && head_dim_v != 64 &&
head_dim_v != 128 && head_dim_v != 256;

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.

Just and FYI: I'm adding it in PR 2964 (last commit) as well.

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.

Thanks — confirmed that #2964 includes the #3249 mitigation in common and propagates the rejection reason to both PyT and JAX. I’ll rebase this PR on top of it.

Please NOTE: The remaining behavioral difference is that #2964 currently disables all FP16/BF16 value head dimensions, while cuDNN fix confirms that the specialized 64/128/256 kernels were not affected. So, I feel we should not have an umbrella condition, especially for those that are using an older cuDNN version and a supported head dim already - shouldn't have to pay the price of this reection here.

@KshitijLakhani

Copy link
Copy Markdown
Collaborator Author

@cyanguwa I left a few responses to your comments but with the merging of #2964 the essential point is that we if close this PR (#3470), what we lose is fused-attention availability/performance for head_dim_v ∈ {64, 128, 256} with FP16/BF16 and cuDNN < 9.26.

#2964 makes this unavailable whereas this PR makes them available, so I'm thinking of rebasing my PR which should basically translate this PR to a simple check, i.e. do not lose fused-attention availability/performance for head_dim_v ∈ {64, 128, 256} with FP16/BF16 and cuDNN < 9.26.

Sounds good ?

@jberchtold-nvidia

jberchtold-nvidia commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

LGTM from the JAX side, thanks for making the JAX changes as well! Will defer approving the PR to Charlene since it seems like she still has some open comments like

Sounds like we should disable all head dims for cuDNN < 9.26 based on our Slack conversation? Also, do we need the "not deterministic" here?

@cyanguwa

cyanguwa commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

@cyanguwa I left a few responses to your comments but with the merging of #2964 the essential point is that we if close this PR (#3470), what we lose is fused-attention availability/performance for head_dim_v ∈ {64, 128, 256} with FP16/BF16 and cuDNN < 9.26.

#2964 makes this unavailable whereas this PR makes them available, so I'm thinking of rebasing my PR which should basically translate this PR to a simple check, i.e. do not lose fused-attention availability/performance for head_dim_v ∈ {64, 128, 256} with FP16/BF16 and cuDNN < 9.26.

Sounds good ?

Yes, that sounds good! Thanks!

Narrow the pre-cuDNN 9.26 FP16/BF16 guard to the generic value-head-dimension kernel. The specialized kernels for dimensions 64, 128, and 256 already index ragged Stats correctly.

Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
@KshitijLakhani
KshitijLakhani force-pushed the klakhani/fix/dsink-cudnn-bug branch from acfcded to 4c9aeb6 Compare October 12, 2026 17:50
@KshitijLakhani

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch L0 L1

cyanguwa
cyanguwa previously approved these changes Oct 12, 2026
(cfg.max_seqlen_kv % 128 != 0) && cfg.cuda_graph && !cfg.is_padding) {
return reject(message, "Known cuDNN <= 9.15 issue with CUDA graph. Please upgrade cuDNN.");
}
// cuDNN's specialized kernels for these value head dimensions index ragged Stats correctly.

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.

Can we remove this comment? Just wanted to keep the code lean. We can fold the information into the reject message though (if we want). Thanks.

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

Signed-off-by: Kshitij Janardan Lakhani <klakhani@nvidia.com>
@KshitijLakhani
KshitijLakhani merged commit c3081a5 into NVIDIA:main Oct 14, 2026
12 checks passed
@KshitijLakhani
KshitijLakhani deleted the klakhani/fix/dsink-cudnn-bug branch October 14, 2026 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

attention bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] FusedAttention THD + learnable softmax backward IMA (cuDNN err 700) on Hopper

4 participants