tessavdheiden / SCR

SocialCompliantRobot
16 stars 5 forks source link

RuntimeError: expected device cuda:0 but got device cpu #1

Open liuqi8827 opened 4 years ago

liuqi8827 commented 4 years ago

Thanks for your work. I'm facing two problems when I run your project.

1.I installed the project successfully according to your README.md.

2.In order to use GPU, I changed the code in /SCR/crowd_nav/train.py def main(): parser.add_argument('--gpu', default=False, action='store_true') to parser.add_argument('--gpu', default=True, action='store_true') However, I got some errors in the terminator RuntimeError: Expected object of backend CUDA but got backend CPU ...

  1. Then I changed the code in /SCR/crowd_nav/empowerment/source.py class Source(nn.Module):

    self.fc = nn.Linear(nb_states, hidden1)
    self.mu_head = nn.Linear(hidden1, nb_actions)
    self.sigma_head = nn.Linear(hidden1, nb_actions)

    to

     self.fc = nn.Linear(nb_states, hidden1).cuda()
     self.mu_head = nn.Linear(hidden1, nb_actions).cuda()
     self.sigma_head = nn.Linear(hidden1, nb_actions).cuda()

    I did the same change in /SCR/crowd_nav/empowerment/transition.py and /SCR/crowd_nav/empowerment/planning.py

  2. Then I run python train.py --policy scr However, I got the error in the terminator: RuntimeError: expected device cuda:0 but got device cpu

  3. What's the version of your torch? My environment is Ubuntu = 16.04 python = 3.6.10 torch version = 0.6.0 pyTorch = 1.5.0 GPU GTX 2070s NVIDIA-SMI 430.64 CUDA Version: 10.1

  4. I got an error when I use cpu: RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation So I changed all the a += b to a = a + b in the code of your project. For example epoch_loss += loss to epoch_loss = epoch_loss + loss But it dosen't work, I got the same error. Maybe the version of torch is the reason of this error.

Thanks a lot!

liuqi8827 commented 4 years ago

Hi,

I git clone your project and didn't modify any code. However, when I run python train.py --policy scr I got the error in the terminator: Screenshot from 2020-08-23 21-27-47

Can you give me some suggestions to solve this problem? Thanks a lot!

tessavdheiden commented 4 years ago

Hi!

The second issue (backward.step()) is resolved now. Let me know if it works!

bektaskemal commented 4 years ago

Hi, I also have problem using Gpu. Any update on that?

liuqi8827 commented 4 years ago

Hi!

The second issue (backward.step()) is resolved now. Let me know if it works!

@tessavdheiden Yes, it worked successfully. Thanks a lot!