Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
liuqi8827 opened this issue Aug 19, 2020 · 4 comments
Open

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

liuqi8827 opened this issue Aug 19, 2020 · 4 comments

Comments

@liuqi8827
Copy link

liuqi8827 commented Aug 19, 2020

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

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

  2. 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
Copy link
Author

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
Copy link
Owner

Hi!

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

@bektaskemal
Copy link

bektaskemal commented Sep 3, 2020

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

@liuqi8827
Copy link
Author

liuqi8827 commented Sep 3, 2020

Hi!

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

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

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

No branches or pull requests

3 participants