[Bugfix] Add MPS float64->float32 downcast#3548
Merged
vmoens merged 2 commits intopytorch:mainfrom Mar 7, 2026
Merged
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3548
Note: Links to docs will display an error until the docs builds have been completed. ❌ 4 New Failures, 1 Cancelled JobAs of commit fadc7b8 with merge base 491ed0f ( NEW FAILURES - The following jobs have failed:
CANCELLED JOB - The following job was cancelled. Please retry:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
3 tasks
vmoens
approved these changes
Mar 6, 2026
Collaborator
vmoens
left a comment
There was a problem hiding this comment.
LGTM! Thanks!
Maybe let's add a test to check that there is no float64 support with mps? Like that the test will fail if it ever becomes a thing and we know we can upgrade
Contributor
Author
|
@vmoens Thanks for the review, I added a test for that. Thanks!! 😄 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add MPS float64 -> float32 downcast in
_default_dtype_and_device()to prevent crashes when moving specs to MPS device.MPS does not support float64 tensors. This is a problem e.g. when gymnasium/MuJoCo specs (which use float64) are created on CPU and later moved to MPS via
.to("mps"), the spec constructors calltorch.full(..., device="mps", dtype=torch.float64)which raises an error.The fix adds a guard in
_default_dtype_and_device()that automatically downcasts float64 -> float32 with aUserWarningwhen the device is MPS.Motivation and Context
Gymnasium and MuJoCo environments produce float64 observation/action spaces by default. When a user creates a collector with
env_device="mps"(e.g., in the a trainer), it will try to move the specs to MPS with float64, and crashes.The fix prevents this crash by ensuring float64 specs are always downcast to float32 on MPS.
Fixes: #3549
Types of changes
What types of changes does your code introduce? Remove all that do not apply:
Checklist
Go over all the following points, and put an
xin all the boxes that apply.If you are unsure about any of these, don't hesitate to ask. We are here to help!