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

Add foreach to optimizers #10

Merged
merged 7 commits into from
Apr 11, 2024
Merged

Add foreach to optimizers #10

merged 7 commits into from
Apr 11, 2024

Conversation

drhead
Copy link
Contributor

@drhead drhead commented Apr 7, 2024

I rewrote adamw_schedulefree to support using torch._foreach operations as an option. According to my profiler, this made the optimizer step go from taking ~85ms to ~65ms (the model used was the SD1.5 Unet). In theory, this should also increase peak memory usage during the optimizer step (according to Pytorch's documentation on the built-in optimizers) -- I have left it as enabled by default regardless since this is the default behavior for built-in optimizers.

I think it would obviously be best to add this to all included optimizers, but before I do that I would like to hear some feedback on code style to make sure everything I add is up to standards.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 7, 2024
@adefazio
Copy link
Contributor

adefazio commented Apr 7, 2024

Nice! I will take a look on Monday.

@adefazio
Copy link
Contributor

adefazio commented Apr 7, 2024

Have you tried running https://github.com/facebookresearch/schedule_free/blob/main/schedulefree/test_schedulefree.py
to make sure it gives identical outputs to the closure version? That will help verify if it's correct.

@drhead drhead changed the title Add foreach to adamw_schedulefree Add foreach to optimizers Apr 7, 2024
@drhead drhead marked this pull request as draft April 7, 2024 17:42
@drhead drhead marked this pull request as ready for review April 7, 2024 17:51
@drhead
Copy link
Contributor Author

drhead commented Apr 7, 2024

I implemented it in all of the main optimizers, both closure and non-closure versions. I skipped some of the renaming in the foreach versions for the sake of simplicity on the in-place operations. The code passes the test suite just fine in its current state.

@adefazio
Copy link
Contributor

adefazio commented Apr 9, 2024

Ok, we will look this over during the next few days, sorry for the delay things are hectic at the moment.

@adefazio adefazio merged commit 326f459 into facebookresearch:main Apr 11, 2024
1 check passed
@adefazio
Copy link
Contributor

This looks to be working correctly, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants