Skip to content
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

[optim] Adam defaults to fused when CUDA + differentiable=False #90865

Closed
wants to merge 7 commits into from

Conversation

janeyx99
Copy link
Contributor

Step 1 in faster default optimizers.

Preliminary benchmarks show gaps in improvement on CUDA for BERT_pytorch and resnet18:
image

@pytorch-bot
Copy link

pytorch-bot bot commented Dec 14, 2022

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/90865

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 5df2847:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@janeyx99 janeyx99 added release notes: nn release notes category topic: performance topic category labels Dec 14, 2022
@janeyx99 janeyx99 force-pushed the adam-default-fused branch 3 times, most recently from c292b78 to e379ec5 Compare December 23, 2022 03:01
@janeyx99 janeyx99 added the ciflow/trunk Trigger trunk jobs on your pull request label Dec 23, 2022
@janeyx99 janeyx99 marked this pull request as ready for review December 23, 2022 06:34
@janeyx99 janeyx99 changed the title [optim] Adam defaults to fused/foreach when CUDA + differentiable=False [optim] Adam defaults to fused when CUDA + differentiable=False Dec 23, 2022
Copy link
Collaborator

@albanD albanD left a comment

Choose a reason for hiding this comment

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

Sounds good!

@@ -105,9 +105,12 @@ class Adam(Optimizer):
capturable (bool, optional): whether this instance is safe to capture in a CUDA graph.
Passing True can impair ungraphed performance, so if you don't intend to
graph capture this instance, leave it False (default: False)
fused (bool, optional): whether fused implementation of optimizer is used.
fused (bool, optional): whether the fused implementation (CUDA only) is used.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: it is not really cuda-only? You could use it for CPU. And other device like xla/mps/xpu might benefit from it as well.
Or you prefer to mention this for now and update it when we get more implementations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! I thought it was CUDA only since fused_adam only has a CUDA dispatch, but yea we can update this when there are more implementations.
https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/native_functions.yaml#L14471-L14476

@janeyx99
Copy link
Contributor Author

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 1 additional jobs have failed, first few of them are: build

Details for Dev Infra team Raised by workflow job

@janeyx99
Copy link
Contributor Author

@pytorchbot merge -f "build ios failure not related"

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

pytorchmergebot pushed a commit that referenced this pull request Jan 14, 2023
…g to fused (#92181)

A "fix" following #90865. Realized that fused is not compatible with torch.jit.is_scripting() when looking at a later line.

Took the opportunity to make the code cleaner/slightly more performant (with the extends) as well.
Pull Request resolved: #92181
Approved by: https://github.com/albanD
@crcrpar
Copy link
Collaborator

crcrpar commented Jan 27, 2023

@janeyx99 what would be the expected behavior when foreach=True and fused=None? Would _multi_tensor_adam be selcted?

@janeyx99
Copy link
Contributor Author

@crcrpar good point. that is the intuitive thing but is currently not true. I'm fixing it with #93184

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: nn release notes category topic: performance topic category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants