mikeizbicki / cmc-csci181-deeplearning

deep learning course materials
15 stars 6 forks source link

Problems with loading in the pre-trained model (Model Compatibility on my personal machine) #32

Open benfig1127 opened 4 years ago

benfig1127 commented 4 years ago

I am having trouble loading the model for Part 1 of the project, the first problem I ran into was the fact that the args file contains command line arguments I did not specify in my original names.py I attempted to solve this problem by just adding dummy command line arguments that do not do anything in order to let the pretained model load. For example

parser_opt.add_argument('--dropout',type=float, default=1.0)

In my actual code this line does nothing other than seem to fix the problem of warm starting from a model with new arguments. However, after fixing this error message I am greeted with an error message I have no idea how to solve. It looks like this model was trained using CUDA while my machine is a CPU only machine which throws the following error:

Imports Successful
warm starting model from models/gru_512x8
Traceback (most recent call last):
  File "names.py", line 214, in <module>
    model_dict = torch.load(os.path.join(args.warm_start,'model'))
  File "/home/ben/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 529, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "/home/ben/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 702, in _legacy_load
    result = unpickler.load()
  File "/home/ben/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 665, in persistent_load
    deserialized_objects[root_key] = restore_location(obj, location)
  File "/home/ben/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 156, in default_restore_location
    result = fn(storage, location)
  File "/home/ben/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 132, in _cuda_deserialize
    device = validate_cuda_device(location)
  File "/home/ben/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 116, in validate_cuda_device
    raise RuntimeError('Attempting to deserialize object on a CUDA '
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

I am not sure how to fix this problem and would appreciate any help on any of this! Thanks :)

mikeizbicki commented 4 years ago

I recommend using the names.py file included in the project folder, as this code is guaranteed to work. If you want to use your own code, however, changing the line in your warmstart section that loads the model from

    model_dict = torch.load(os.path.join(args.warm_start,'model'))

to


    model_dict = torch.load(os.path.join(args.warm_start,'model'), map_location='cpu')

should fix the cuda problem.

benfig1127 commented 4 years ago

Fantastic, thanks I didn't realize you included your own names.py in the project folder lol. Thanks for the help :).

benfig1127 commented 4 years ago

Maybe I should have watched the YouTube videos first before asking stupid questions haha sorry 😅.