Erros in loadding model.pth

  weights_dict = torch.load(weightspath)
  File "/home/user/local/python3/anaconda3/lib/python3.6/site-packages/torch/", line 229, in load
    return _load(f, map_location, pickle_module)
  File "/home/user/local/python3/anaconda3/lib/python3.6/site-packages/torch/", line 377, in _load
    result = unpickler.load()
  File "/home/user/local/python3/anaconda3/lib/python3.6/site-packages/torch/", line 348, in persistent_load
    data_type(size), location)
  File "/home/user/local/python3/anaconda3/lib/python3.6/site-packages/torch/", line 85, in default_restore_location
    result = fn(storage, location)
  File "/home/user/local/python3/anaconda3/lib/python3.6/site-packages/torch/", line 67, in _cuda_deserialize
    return obj.cuda(device_id)
  File "/home/user/local/python3/anaconda3/lib/python3.6/site-packages/torch/", line 57, in _cuda
    with torch.cuda.device(device):
  File "/home/user/local/python3/anaconda3/lib/python3.6/site-packages/torch/cuda/", line 127, in __enter__
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