-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 support for M1/M2 mac in PytorchModelHandlerTensor #29999
Conversation
Add support for M1/M2 mac
Assigning reviewers. If you would like to opt out of this review, comment R: @damccorm for label python. Available commands:
The PR bot will only process comments in the main thread (not review comments). |
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.
Thanks, this looks like a helpful change. I think we need a few more things for completeness though.
- Could you please update
_load_model
to add a check likeif device == torch.device('cuda') and not torch.cuda.is_available(): if device == torch.device('cuda') and not torch.cuda.is_available(): - Could you please update the pydoc for each of the modified functions to call out that mps is an allowed device type?
- We should probably prefer
MPS
tomps
to stay consistent with ourGPU
parameter. Alternately, we can just make both case insensitive (this would probably be for the best anyways).
Reminder, please take a look at this pr: @damccorm |
waiting on author |
Thanks for the review! Addressed the comments. On #3 I decided to make everything case insensitive as well as support specifying Lmk what you think, happy to just leave the case insensitivity part. |
198f42b
to
fcb8fa2
Compare
@@ -243,9 +250,12 @@ def __init__( | |||
with PyTorch 1.9 and 1.10. | |||
""" | |||
self._state_dict_path = state_dict_path | |||
if device == 'GPU': | |||
if device in ['gpu', 'GPU', 'cuda', 'CUDA']: |
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.
Hey, sorry for the slow review - this looks mostly good. The only thing I'd ask is that if we go case-insensitive we do it all the way (so device.lower() == 'gpu'
here, and the same type of change applied elsewhere in the PR). Otherwise, this looks good to me, thanks!
@@ -91,6 +91,12 @@ def _load_model( | |||
"Model handler specified a 'GPU' device, but GPUs are not available. " | |||
"Switching to CPU.") | |||
device = torch.device('cpu') | |||
if device == torch.device('mps') and not (torch.backend.mps.is_available() and |
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.
Ah, it also looks like torch.device('mps')
causes older versions of pytorch to throw. To maintain compat with older versions, could we wrap this in a try except? It should be fine to silently swallow the exception since we'll throw below if someone tries to set the device to mps and the pytorch version doesn't support it.
This is why the test checks are failing
This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@beam.apache.org list. Thank you for your contributions. |
This pull request has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time. |
Add support for M1/M2 mac
Add support for M1/M2 mac by allowing
mps
pytorch device type.Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123
), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>
instead.CHANGES.md
with noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.