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

Support PyTorch 2.0.0 #559

Merged
merged 6 commits into from
Mar 28, 2023
Merged

Support PyTorch 2.0.0 #559

merged 6 commits into from
Mar 28, 2023

Conversation

justheuristic
Copy link
Member

@justheuristic justheuristic commented Mar 16, 2023

@borzunov:

  • Fix LRSchedulerBase
  • Handle None after .zero_grad() in torch 2.0.0
  • Use set_to_none=True by default in torch>=2.0
  • Add set_to_none param to TrainingStateAverager.step()

borzunov added a commit that referenced this pull request Mar 28, 2023
PyTorch 2.0 is not supported yet, it's support will be added in #559 (there are multiple issues to resolve). Until then, we need to require `torch<2.0.0` (otherwise 2.0.0 is installed, so CI doesn't work right now).

This PR also adds Python 3.10 to the CI.
@borzunov
Copy link
Member

I've rebased this PR to the master branch after #558 was merged.

@borzunov borzunov changed the title test compatilility with torch 2.0 Support torch 2.0.0 Mar 28, 2023
@@ -1,5 +1,5 @@
PyYAML
torch>=1.9.0,<2.0.0
torch>=1.9.0
Copy link
Member

@borzunov borzunov Mar 28, 2023

Choose a reason for hiding this comment

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

We'll have torch 1.13.0 on Python 3.7, torch 2.0.0 on Python 3.8-3.10. This allows us to test both torch 1.13.0 and 2.0.0.

We can drop Python 3.7 and PyTorch < 2.0 support when necessary.

def zero_grad(self, set_to_none: bool = False):
_SET_TO_NONE_DEFAULT = Version(torch.__version__).major >= 2

def zero_grad(self, set_to_none: bool = _SET_TO_NONE_DEFAULT):
Copy link
Member

@borzunov borzunov Mar 28, 2023

Choose a reason for hiding this comment

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

So it's consistent with the torch-wide default.

@borzunov borzunov changed the title Support torch 2.0.0 Support PyTorch 2.0.0 Mar 28, 2023
Copy link
Member Author

@justheuristic justheuristic left a comment

Choose a reason for hiding this comment

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

LGTM

@borzunov borzunov requested a review from mryab March 28, 2023 20:23
Comment on lines 154 to 156
assert (model1.weight.grad is None or torch.all(model1.weight.grad == 0)) and (
model2.weight.grad is None or torch.all(model2.weight.grad == 0)
), "zero grad did not trigger"
Copy link
Member

Choose a reason for hiding this comment

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

Can we also use Version(torch.__version__).major >= 2 here? (or at least import _SET_TO_NONE_DEFAULT)

This way, the test won't have a bug where we always set the grad to None regardless of the PyTorch version

@codecov
Copy link

codecov bot commented Mar 28, 2023

Codecov Report

Merging #559 (367bd4e) into master (351abc5) will decrease coverage by 0.09%.
The diff coverage is 59.09%.

@@            Coverage Diff             @@
##           master     #559      +/-   ##
==========================================
- Coverage   76.01%   75.92%   -0.09%     
==========================================
  Files          81       81              
  Lines        7995     8008      +13     
==========================================
+ Hits         6077     6080       +3     
- Misses       1918     1928      +10     
Impacted Files Coverage Δ
hivemind/optim/optimizer.py 69.10% <33.33%> (-0.48%) ⬇️
hivemind/moe/server/module_backend.py 87.17% <50.00%> (-2.16%) ⬇️
hivemind/optim/state_averager.py 85.44% <75.00%> (-0.65%) ⬇️

... and 4 files with indirect coverage changes

@borzunov borzunov merged commit 98531ce into master Mar 28, 2023
13 checks passed
@borzunov borzunov deleted the test-torch2.0 branch March 28, 2023 22:00
mryab pushed a commit that referenced this pull request Mar 31, 2023
PyTorch 2.0 is not supported yet, it's support will be added in #559 (there are multiple issues to resolve). Until then, we need to require `torch<2.0.0` (otherwise 2.0.0 is installed, so CI doesn't work right now).

This PR also adds Python 3.10 to the CI.

(cherry picked from commit 73186cb)
mryab pushed a commit that referenced this pull request Mar 31, 2023
- Fix LRSchedulerBase
- Handle None after .zero_grad() in torch 2.0.0
- Use set_to_none=True by default in torch>=2.0
- Add set_to_none param to TrainingStateAverager.step()

Co-authored-by: Aleksandr Borzunov <hxrussia@gmail.com>
(cherry picked from commit 98531ce)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants