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

model_utils.py's make_and_restore_model fails without cuda #15

Closed
RylanSchaeffer opened this issue Oct 30, 2019 · 7 comments
Closed

model_utils.py's make_and_restore_model fails without cuda #15

RylanSchaeffer opened this issue Oct 30, 2019 · 7 comments

Comments

@RylanSchaeffer
Copy link

RylanSchaeffer commented Oct 30, 2019

I'm running pytorch version '1.2.0+cpu'. I'm trying to get the introductory example with pretrained models to work with the CIFAR10 L2-norm (ResNet50) ε = 0.0 model, but I receive the following error

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/torch/serialization.py", line 386, in load
    return _load(f, map_location, pickle_module, **pickle_load_args)
  File "/usr/local/lib/python3.6/dist-packages/torch/serialization.py", line 573, in _load
    result = unpickler.load()
  File "/usr/local/lib/python3.6/dist-packages/dill/_dill.py", line 472, in load
    obj = StockUnpickler.load(self)
  File "/usr/local/lib/python3.6/dist-packages/torch/serialization.py", line 536, in persistent_load
    deserialized_objects[root_key] = restore_location(obj, location)
  File "/usr/local/lib/python3.6/dist-packages/torch/serialization.py", line 119, in default_restore_location
    result = fn(storage, location)
  File "/usr/local/lib/python3.6/dist-packages/torch/serialization.py", line 95, in _cuda_deserialize
    device = validate_cuda_device(location)
  File "/usr/local/lib/python3.6/dist-packages/torch/serialization.py", line 79, 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.

It appears that the appropriate place to modify torch.load() is line 71` of model_utils.py.

@RylanSchaeffer
Copy link
Author

RylanSchaeffer commented Oct 30, 2019

The following change successfully avoids the runtime error:

if ch.cuda.is_available():
  checkpoint = ch.load(resume_path, pickle_module=dill)
else:
  checkpoint = ch.load(resume_path, pickle_module=dill, map_location=ch.device('cpu'))

@RylanSchaeffer RylanSchaeffer changed the title make_and_restore_model fails without cuda model_utils.py's make_and_restore_model fails without cuda Oct 30, 2019
@RylanSchaeffer
Copy link
Author

But a subsequent error (AssertionError("Torch not compiled with CUDA enabled")) is raised on Line 83's model.cuda().

Did I miss something in the README or requirements.txt that cuda is required?

@RylanSchaeffer
Copy link
Author

Same assertion error when trying to generate an adversarial image:

_, im_adv = model(im, label, make_adv=True, **kwargs)

Stack trace:

    _, im_adv = model(im, label, make_adv=True, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 547, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/parallel/data_parallel.py", line 140, in forward
    return self.module(*inputs, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 547, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/robustness/attacker.py", line 305, in forward
    adv = self.attacker(inp, target, **attacker_kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 547, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/robustness/attacker.py", line 136, in forward
    orig_input = orig_input.cuda()
  File "/usr/local/lib/python3.6/dist-packages/torch/cuda/__init__.py", line 178, in _lazy_init
    _check_driver()
  File "/usr/local/lib/python3.6/dist-packages/torch/cuda/__init__.py", line 92, in _check_driver
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

@andrewilyas
Copy link
Collaborator

Hello,

Currently cuda is required and CPU support is not on our timeline, as training models on CPU tends to be extremely impractical for the vast majority of use cases. I’ve updated the README to reflect this as well.

@RylanSchaeffer
Copy link
Author

@andrewilyas , I understand not wanting to train models on CPU, but what about using models on CPU? This seems quite reasonable.

@RylanSchaeffer
Copy link
Author

Looking at the AttackerModel and Attacker classes, is a GPU practically required?

@dtsip
Copy link
Contributor

dtsip commented Oct 30, 2019

Both classes require gradient access to the model (backprop) which takes significantly longer on a CPU. Given that the common use case is using a GPU for inference, we don't plan to implement CPU support.

That being said, you can fork the project and make the necessary adjustments (it should not be too much work, just not something we have the bandwidth to do at the moment).

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