-
Notifications
You must be signed in to change notification settings - Fork 667
[PyTorch][Fused Attn] Add support for cuDNN to return Softmax Stats always and Max when return_max_logit=True
#2677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sudhakarsingh27
wants to merge
22
commits into
NVIDIA:main
Choose a base branch
from
sudhakarsingh27:fix_return_stats_max_cudnn
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3fb19fc
cudnn now returns Stats always and Max only with `return_max_logit=true`
sudhakarsingh27 5b40701
Merge branch 'main' of github.com:NVIDIA/TransformerEngine
sudhakarsingh27 5d479ad
fix a typo that caused a bug
sudhakarsingh27 296fb9f
update doc strings
sudhakarsingh27 24bfd45
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fd42feb
fix more docs
sudhakarsingh27 2d7b51b
Merge branch 'fix_return_stats_max_cudnn' of github.com:sudhakarsingh…
sudhakarsingh27 260380b
Merge branch 'main' into fix_return_stats_max_cudnn
sudhakarsingh27 7a5ab35
Merge branch 'main' into fix_return_stats_max_cudnn
sudhakarsingh27 9710810
Merge branch 'main' into fix_return_stats_max_cudnn
sudhakarsingh27 07db752
Merge branch 'main' into fix_return_stats_max_cudnn
sudhakarsingh27 f8b1a68
Merge branch 'main' of github.com:NVIDIA/TransformerEngine into fix_r…
sudhakarsingh27 b5b2b9d
Merge branch 'fix_return_stats_max_cudnn' of github.com:sudhakarsingh…
sudhakarsingh27 8f40cab
fixes from the feedback
sudhakarsingh27 56e46fd
Merge branch 'main' of github.com:NVIDIA/TransformerEngine into fix_r…
sudhakarsingh27 1102738
Merge branch 'main' into fix_return_stats_max_cudnn
sudhakarsingh27 7363541
merge main
sudhakarsingh27 8c0d6a1
Merge branch 'main' of github.com:NVIDIA/TransformerEngine into fix_r…
sudhakarsingh27 d517a13
update cudnn-frontend to v1.19.1
sudhakarsingh27 e005455
Merge branch 'main' of github.com:NVIDIA/TransformerEngine into fix_r…
sudhakarsingh27 3ae0a34
update the cudnn frontend
sudhakarsingh27 ef0d7ec
Merge branch 'main' of github.com:NVIDIA/TransformerEngine into fix_r…
sudhakarsingh27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Submodule cudnn-frontend
updated
198 files
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -353,14 +353,14 @@ def fused_attn_fwd( | |
|
|
||
| if return_max_logit: | ||
| qkv_format = qkv_layout.replace("3", "").replace("2", "").split("_")[0] | ||
| # thd: output_tensors: out [tq, h, d], Max [tq, h, 1], Sum_Exp [tq, h, 1] | ||
| # bshd: output_tensors: out [b, sq, h, d], Max [b, h, sq, 1], Sum_Exp [b, h, sq, 1] | ||
| # sbhd: output_tensors: out [sq, b, h, d], Max [b, h, sq, 1], Sum_Exp [b, h, sq, 1] | ||
| stats = output_tensors[1] + torch.log(output_tensors[2]) | ||
| # thd: output_tensors: out [tq, h, d], Stats [tq, h, 1], Max [tq, h, 1] | ||
| # bshd: output_tensors: out [b, sq, h, d], Stats [b, h, sq, 1], Max [b, h, sq, 1] | ||
| # sbhd: output_tensors: out [sq, b, h, d], Stats [b, h, sq, 1], Max [b, h, sq, 1] (there's no typo here) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need the "there's no typo here" :)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I deliberately added it because I didn't believe it and checked the shapes myself :P |
||
|
|
||
| aux_ctx_tensors = [output_tensors[1]] # "Stats" | ||
| amax_dims = (0, 2) if qkv_format == "thd" else (0, 2, 3) | ||
| # Max -> max_logit [h] | ||
| max_logit = torch.amax(output_tensors[1], dim=amax_dims).to(dtype=output_tensors[0].dtype) | ||
| aux_ctx_tensors = [stats] | ||
| max_logit = torch.amax(output_tensors[2], dim=amax_dims).to(dtype=output_tensors[0].dtype) | ||
cyanguwa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| aux_ctx_tensors.extend(output_tensors[3:]) | ||
| return output_tensors[0], aux_ctx_tensors, max_logit | ||
|
|
||
|
|
||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.