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: Attempted to set the storage of a tensor on device "cuda:0" to a storage on different device "cpu". #10

Open
mayanktiwariiiitdmj opened this issue Mar 28, 2022 · 1 comment

Comments

@mayanktiwariiiitdmj
Copy link

Right now the Pytorch with CUDA 10.2 is not available for the Windows OS.
When I am running this project with the CUDA 11.3 for the Windows OS, then I am getting the following ERRORs.

  File "F:\Restart_08122021\my_project\module_x\test.py", line 51, in evaluate
    net = BiSeNet(n_classes=n_classes)
  File "F:\Restart_08122021\my_project\module_x\model.py", line 235, in __init__
    self.cp = ContextPath()
  File "F:\Restart_08122021\my_project\module_x\model.py", line 97, in __init__
    self.resnet = Resnet18()
  File "F:\Restart_08122021\my_project\module_x\resnet.py", line 69, in __init__
    self.init_weight()
  File "F:\Restart_08122021\my_project\module_x\resnet.py", line 83, in init_weight
    state_dict = modelzoo.load_url(resnet18_url)
  File "C:\ProgramData\Anaconda3\envs\my_project\lib\site-packages\torch\hub.py", line 595, in load_state_dict_from_url
    return torch.load(cached_file, map_location=map_location)
  File "C:\ProgramData\Anaconda3\envs\my_project\lib\site-packages\torch\serialization.py", line 713, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "C:\ProgramData\Anaconda3\envs\my_project\lib\site-packages\torch\serialization.py", line 905, in _legacy_load
    return legacy_load(f)
  File "C:\ProgramData\Anaconda3\envs\my_project\lib\site-packages\torch\serialization.py", line 841, in legacy_load
    tensor = torch.tensor([], dtype=storage.dtype).set_(
  RuntimeError: Attempted to set the storage of a tensor on device "cuda:0" to a storage on different device "cpu".  This is no longer allowed; the devices must match.

Please help me in solving this error.

@vinayak015
Copy link

Could you try modifying this line: state_dict = modelzoo.load_url(resnet18_url) to state_dict = modelzoo.load_url(resnet18_url, map_location=lambda storage, loc: storage.cuda())

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

2 participants