rlworkgroup / garage

A toolkit for reproducible reinforcement learning research.
MIT License
1.84k stars 309 forks source link

RuntimeError: Tensor for argument #2 'mat1' is on CPU, but expected it to be on GPU (while checking arguments for addmm) #2318

Closed mastns closed 2 years ago

mastns commented 2 years ago

Hello,

I am training the garage example "sac_half_cheetah_batch.py" using CUDA 11.6 I am able to log using the @wrap_experiment(log_dir='~/my_log_dir', snapshot_mode='all') and plot the logs using Tensorboard but when I try to reuse the trained policy as described in: https://garage.readthedocs.io/en/stable/user/reuse_garage_policy.html I get the following error: RuntimeError: Tensor for argument #2 'mat1' is on CPU, but expected it to be on GPU (while checking arguments for addmm)

UserWarning: WARN: Box bound precision lowered by casting to float32 warnings.warn(colorize("%s: %s" % ("WARN", msg % args), "yellow")) Creating window glfw Traceback (most recent call last): File "test_policy.py", line 13, in path = rollout(env, policy, animated=True) File "/home/tns/.mujoco/python38/lib/python3.8/site-packages/garage/_functions.py", line 120, in rollout a, agent_info = agent.get_action(last_obs) File "/home/tns/.mujoco/python38/lib/python3.8/site-packages/garage/torch/policies/stochastic_policy.py", line 43, in get_action action, agent_infos = self.get_actions(observation) File "/home/tns/.mujoco/python38/lib/python3.8/site-packages/garage/torch/policies/stochastic_policy.py", line 85, in get_actions dist, info = self.forward(observations) File "/home/tns/.mujoco/python38/lib/python3.8/site-packages/garage/torch/policies/tanh_gaussian_mlp_policy.py", line 102, in forward dist = self._module(observations) File "/home/tns/.mujoco/python38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, kwargs) File "/home/tns/.mujoco/python38/lib/python3.8/site-packages/garage/torch/modules/gaussian_mlp_module.py", line 169, in forward mean, log_std_uncentered = self._get_mean_and_log_std(inputs) File "/home/tns/.mujoco/python38/lib/python3.8/site-packages/garage/torch/modules/gaussian_mlp_module.py", line 573, in _get_mean_and_log_std return self._shared_mean_log_std_network(inputs) File "/home/tns/.mujoco/python38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, *kwargs) File "/home/tns/.mujoco/python38/lib/python3.8/site-packages/garage/torch/modules/multi_headed_mlp_module.py", line 149, in forward x = layer(x) File "/home/tns/.mujoco/python38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(input, kwargs) File "/home/tns/.mujoco/python38/lib/python3.8/site-packages/torch/nn/modules/container.py", line 117, in forward input = module(input) File "/home/tns/.mujoco/python38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "/home/tns/.mujoco/python38/lib/python3.8/site-packages/torch/nn/modules/linear.py", line 93, in forward return F.linear(input, self.weight, self.bias) File "/home/tns/.mujoco/python38/lib/python3.8/site-packages/torch/nn/functional.py", line 1690, in linear ret = torch.addmm(bias, input, weight.t()) RuntimeError: Tensor for argument #2 'mat1' is on CPU, but expected it to be on GPU (while checking arguments for addmm)

I am using: torch 1.7.1 garage 2021.3.0 torchvision 0.8.2

Some hints are appreciated Thanks

krzentner commented 2 years ago

You need to move the policy (or, if you prefer, the entire algorithm) to the cpu from the gpu. Try doing policy = policy.to('cpu').