[PyTorch][Fused Attn] Add support for cuDNN to return Softmax Stats always and Max when return_max_logit=True#2677
Open
sudhakarsingh27 wants to merge 8 commits intoNVIDIA:mainfrom
Conversation
Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
for more information, see https://pre-commit.ci
Contributor
Greptile OverviewGreptile SummaryThis PR adapts Transformer Engine to leverage cuDNN's new capability to return Stats (log(SumExp)+Max) directly, eliminating the need for manual computation. The changes simplify the code by removing Key changes:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Py as Python (fused_attn.py)
participant CPP as C++ (attention.cpp)
participant CU as CUDA (fused_attn_f16_arbitrary_seqlen.cu)
participant cuDNN as cuDNN Backend
Py->>CPP: fused_attn_fwd(return_max_logit=True)
CPP->>CU: fused_attn_arbitrary_seqlen_fwd()
Note over CU: Set generate_stats=true (always)
CU->>cuDNN: sdpa() with logit_max option
Note over cuDNN: Computes Stats internally<br/>Stats = log(SumExp) + Max
cuDNN-->>CU: Returns: O, Stats, Max
Note over CU: Tensor order: S1=Stats, S2=Max
CU-->>CPP: output_tensors[0]=O, [1]=Stats, [2]=Max
CPP-->>Py: output_tensors list
Note over Py: Extract max_logit = amax(output_tensors[2])<br/>Store Stats for backward pass
Py-->>Py: Return: O, aux_ctx_tensors=[Stats, ...], max_logit
Last reviewed commit: 260380b |
Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
…27/TransformerEngine into fix_return_stats_max_cudnn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
cuDNN recently made returning any subset of {Stats, SumExp, Max} possible. This PR adapts TE to always get
Statsfrom cuDNN andMaxtensor ifreturn_max_logit=True. (Note thatStats= log(SumExp)+Max)Type of change
Changes
Please list the changes introduced in this PR:
fused_attn_f16_arbitrary_seqlen.cuSumExptensor as it's not needed since cuDNN returnsStatsby default.generate_stats=Truewhich forces cuDNN to always returnStatstensor (needed in the backward pass)transformer_engine/pytorch/cpp_extensions/fused_attn.pyStats = log(SumExp) + Maxsince cuDNN returnsStatsdirectly and TE doesn't needSumExpfrom cuDNNChecklist: