-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
refactor autocast python APIs #124479
Closed
Closed
refactor autocast python APIs #124479
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e0e0e4f
refactor autocast python APIs
guangyey 776571f
Update on "[WIP] refactor autocast python APIs"
guangyey e6502b7
Update on "[WIP] refactor autocast python APIs"
guangyey 8d68ae5
Update on "[WIP] refactor autocast python APIs"
guangyey 90f924c
Update on "[WIP] refactor autocast python APIs"
guangyey 7a7a630
Update on "[WIP] refactor autocast python APIs"
guangyey 9faf0d8
Update on "refactor autocast python APIs"
guangyey 68c3bb1
Update on "refactor autocast python APIs"
guangyey c6d2ebe
Update on "refactor autocast python APIs"
guangyey 1150a37
Update on "refactor autocast python APIs"
guangyey 181e401
Update on "refactor autocast python APIs"
guangyey ede353b
Update on "refactor autocast python APIs"
guangyey 60e6f68
Update on "refactor autocast python APIs"
guangyey fed5e79
Update on "refactor autocast python APIs"
guangyey b9aaa22
Update on "refactor autocast python APIs"
guangyey 5a1d089
Update on "refactor autocast python APIs"
guangyey af4b59a
Update on "refactor autocast python APIs"
guangyey 904bc23
Update on "refactor autocast python APIs"
guangyey cab72c6
Update on "refactor autocast python APIs"
guangyey File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API sounds generally useful. Should we expose it as a public API on
torch.amp.is_autocast_available()
?This can be a follow up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks. I will add it in a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition, I have a quick question. Is it reasonable to add torch.xpu.amp.autocast which is equivalent to torch.autocast('xpu')? PyTorch assumes that each backend has its own autocast in many places, like
pytorch/torch/utils/checkpoint.py
Line 301 in 34bce27
If not, xpu will be not supported in torch.xxx.amp.autocast scenario. Note torch.cuda.amp.autocast is not equivalent to torch.autocast('cuda') as the former one can handle JIT path. If use torch.autocast(device_type), it can not handle CUDA/CPU JIT path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The answer here is a bit tricky. The very honest answer is:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't like to support TorchScript on XPU. We just intend to add
torch.xpu.amp.autocast
, a wrapper oftorch.amp.autocast
specific toxpu
, to supporttorch.xxx.amp.autocast
code-style scenario on eager mode, like the below code defined intorch.xpu.amp.autocast_mode.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what is the benefit of such API? We are adding generic API so that users don't have to use these one-off APIs that make their code locked onto a specific device.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@albanD
This is a history issue, indeed. Before this PR, user has been used to adopting torch.cuda.amp.autocast in their scripts.
We followed CUDA to provide torch.xpu.amp.autocast as a public API in our extension.
Although we have torch.amp.autocast now, it's difficult to ask all users to replace with new API immediately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure to follow.
The existing code contains torch.cuda.XXX calls. So user code must be changed to support xpu. Adding a new torch.xpu.XXX API doesn't remove the need for user-code change.
And if we're changing user code, we might as well change it to use torch.amp.XXX API directly.
Am I missing something here?