Configurable inference device, use MPS on mac - #12
Open
benjamincburns wants to merge 1 commit into
Open
Conversation
benjamincburns
commented
Sep 12, 2023
| if self.device == self.inference_device: | ||
| self.agent.policy = self.ppo_learner.policy | ||
| else: | ||
| self.agent.policy = self.ppo_learner.policy.clone(to=inference_device) |
Contributor
Author
There was a problem hiding this comment.
ah, this is a bug - should be to=self.inference_device. will push a fix.
Details: Adds a `inference_device` field to the `Learner` class's constructor. Attempts to use the `"mps"` device on mac for backprop when `"auto"` or `"gpu"` are used as the value of `device` argument. When the value `"auto"` is specified for the `inference_device` argument, the behaviour varies based on the available hardware. On systems with multiple CUDA devices, `"cuda:1"` is used. On systems with only one CUDA device, `"cuda:0"` is used. On macs with MPS support, `"cpu"` is used, as it's much faster to use `"cpu"` for inference and `"mps"` for backprop. When the value of `"gpu"` is specified for the `inference_device` argument, the behaviour is the same as `"auto"` for CUDA systems, but on mac, `"mps"` is used, even though this doesn't perform as well, as the user is explicitly asking for the GPU device. Finally, if the user explicitly specifies a torch device identifier in the `inference_device` argument, that device will be used. To enable use of a separate inference device, this commit also adds a clone method to all of the model types in the PPO directory. Adding this for the `ValueEstimator` wasn't necessary for this change, but I did it anyway for consistency.
benjamincburns
force-pushed
the
inference-device
branch
from
September 12, 2023 13:56
b6ded19 to
34eaf4f
Compare
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.
Adds an
inference_devicefield to theLearnerclass's constructor.Attempts to use the
"mps"device on mac for backprop when"auto"or"gpu"are used as the value ofdeviceargument.When the value
"auto"is specified for theinference_deviceargument, the behaviour varies based on the available hardware. On systems with multiple CUDA devices,"cuda:1"is used. On systems with only one CUDA device,"cuda:0"is used. On macs with MPS support,"cpu"is used, as it's much faster to use"cpu"for inference and"mps"for backprop.When the value of
"gpu"is specified for theinference_deviceargument, the behaviour is the same as"auto"for CUDA systems, but on mac,"mps"is used, even though this doesn't perform as well, as the user is explicitly asking for the GPU device.Finally, if the user explicitly specifies a torch device identifier in the
inference_deviceargument, that device will be used.To enable use of a separate inference device, this commit also adds a clone method to all of the model types in the PPO directory. Adding this for the
ValueEstimatorwasn't necessary for this change, but I did it anyway for consistency.I also added a
get_actions_no_gradmethod to each of the policy types for use during inference, as this seemed to speed things up slightly.