Repository navigation
[Bugfix] Downcast to float32 when Parallel/SerialEnv is on MPS - #3551
Merged
vmoens merged 1 commit intoMar 11, 2026
Merged
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3551
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New Failures, 4 Cancelled Jobs, 1 Pending, 1 Unrelated FailureAs of commit e2d0cf7 with merge base b6326f7 ( NEW FAILURES - The following jobs have failed:
CANCELLED JOBS - The following jobs were cancelled. Please retry:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
3 tasks done
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
Fix
SerialEnvandParallelEnvcrashing withTypeError: Cannot convert a MPS Tensor to float64 dtypewhen the parent environment is placed on an MPS device and sub-environments producefloat64observations (the default for many Gym/Gymnasium envs).Motivation and Context
MPS has no hardware support for 64-bit floating-point. Standard envs (e.g.
HalfCheetah-v4) returnfloat64observations by default. As a result, any user who tried to run a batched environment on MPS with a standard Gym env received a hard crash with an opaqueTypeErrorfrom PyTorch's MPS backend.How can this happen: the
Parallel/SerialEnvhave workers which actually run the rollouts. These workers may run the env on CPU, so it can collect float64 data. The error comes when returning that data to the parentParallel/SerialEnv. To do so, it has to cast it to the parent's device, which can be a different device from the workers. If the parent is on MPS, then an error is raised as it cannot have float64 tensors.Even if the workers are on CPU in many cases it is better to have the parent be on MPS, as the parent env can be wrapped in a sequence of transforms which are typically more efficient on MPS. More practically, it is just easier to always keep the parent on GPU as a default, and let the worker envs be cpu/gpu as their defaults specify.
Closes: #3550
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!