Skip to content

Configurable inference device, use MPS on mac - #12

Open
benjamincburns wants to merge 1 commit into
AechPro:mainfrom
benjamincburns:inference-device
Open

Configurable inference device, use MPS on mac#12
benjamincburns wants to merge 1 commit into
AechPro:mainfrom
benjamincburns:inference-device

Conversation

@benjamincburns

Copy link
Copy Markdown
Contributor

Adds an 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.

I also added a get_actions_no_grad method to each of the policy types for use during inference, as this seemed to speed things up slightly.

Comment thread rlgym_ppo/learner.py Outdated
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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
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.

1 participant