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

Training fixes for MPS #5810

Merged
merged 2 commits into from
Dec 24, 2022
Merged

Conversation

brkirch
Copy link
Collaborator

@brkirch brkirch commented Dec 17, 2022

  • Although training itself works with the MPS device on PyTorch 1.12.1, the result fails to save due to torch.save() throwing an exception: RuntimeError: Can't call numpy() on Tensor that requires grad. Use tensor.detach().numpy() instead. So for MPS on PyTorch 1.12.1, use a monkey patch to call detach() before numpy() on any torch.Tensor that has requires_grad set to true.
  • Add attributes used by MPS to the safety checker

With these changes training seems to work correctly on MPS.

When saving training results with torch.save(), an exception is thrown:
"RuntimeError: Can't call numpy() on Tensor that requires grad. Use tensor.detach().numpy() instead."

So for MPS, check if Tensor.requires_grad and detach() if necessary.
@AUTOMATIC1111 AUTOMATIC1111 merged commit 3bfc6c0 into AUTOMATIC1111:master Dec 24, 2022
@brkirch brkirch deleted the fix-training-mps branch December 27, 2022 12:05
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