Erros in loadding model.pth

  weights_dict = torch.load(weightspath)
  File "/home/user/local/python3/anaconda3/lib/python3.6/site-packages/torch/serialization.py", line 229, in load
    return _load(f, map_location, pickle_module)
  File "/home/user/local/python3/anaconda3/lib/python3.6/site-packages/torch/serialization.py", line 377, in _load
    result = unpickler.load()
  File "/home/user/local/python3/anaconda3/lib/python3.6/site-packages/torch/serialization.py", line 348, in persistent_load
    data_type(size), location)
  File "/home/user/local/python3/anaconda3/lib/python3.6/site-packages/torch/serialization.py", line 85, in default_restore_location
    result = fn(storage, location)
  File "/home/user/local/python3/anaconda3/lib/python3.6/site-packages/torch/serialization.py", line 67, in _cuda_deserialize
    return obj.cuda(device_id)
  File "/home/user/local/python3/anaconda3/lib/python3.6/site-packages/torch/_utils.py", line 57, in _cuda
    with torch.cuda.device(device):
  File "/home/user/local/python3/anaconda3/lib/python3.6/site-packages/torch/cuda/__init__.py", line 127, in __enter__
    torch._C._cuda_setDevice(self.idx)
RuntimeError: cuda runtime error (10) : invalid device ordinal at torch/csrc/cuda/Module.cpp:84

What’s weightspath? How was the model saved? If it was saved as a state_dict(), you may need to reconstruct the class that generated the model first before loading it.

Thanks for your reply.
yes, it is saved as a state_dict,
weights_dict = torch.load(weightspath) simply loads it as a dictionary.

It seems to me that if the model is trained using GPU #3 on another machine, the saved model can not be loaded by a different machine with only 2 gpus.

search on forum for loading gpu model on cpiu

1 Like