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

Bugs when running on mac #14

Closed
beasteers opened this issue Oct 27, 2023 · 5 comments
Closed

Bugs when running on mac #14

beasteers opened this issue Oct 27, 2023 · 5 comments

Comments

@beasteers
Copy link

Wrong device mapping on checkpoint load

Traceback (most recent call last):
  File "/opt/gh/Cutie/interactive_demo.py", line 75, in <module>
    ex = MainController(cfg)
  File "/opt/gh/Cutie/gui/main_controller.py", line 59, in __init__
    self.initialize_networks()
  File "/opt/gh/Cutie/gui/main_controller.py", line 129, in initialize_networks
    model_weights = torch.load(self.cfg.weights)
  File "/opt/miniconda/envs/cutie/lib/python3.10/site-packages/torch/serialization.py", line 1014, in load
    return _load(opened_zipfile,
  File "/opt/miniconda/envs/cutie/lib/python3.10/site-packages/torch/serialization.py", line 1422, in _load
    result = unpickler.load()
  File "/opt/miniconda/envs/cutie/lib/python3.10/site-packages/torch/serialization.py", line 1392, in persistent_load
    typed_storage = load_tensor(dtype, nbytes, key, _maybe_decode_ascii(location))
  File "/opt/miniconda/envs/cutie/lib/python3.10/site-packages/torch/serialization.py", line 1366, in load_tensor
    wrap_storage=restore_location(storage, location),
  File "/opt/miniconda/envs/cutie/lib/python3.10/site-packages/torch/serialization.py", line 381, in default_restore_location
    result = fn(storage, location)
  File "/opt/miniconda/envs/cutie/lib/python3.10/site-packages/torch/serialization.py", line 274, in _cuda_deserialize
    device = validate_cuda_device(location)
  File "/opt/miniconda/envs/cutie/lib/python3.10/site-packages/torch/serialization.py", line 258, 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.

Fix:

in main controller do:

model_weights = torch.load(self.cfg.weights, map_location=self.device)

autocast seemingly doesn't work with mps

Traceback (most recent call last):
  File "/opt/gh/Cutie/gui/gui.py", line 411, in on_mouse_press
    self.click_fn(action, ex, ey)
  File "/opt/gh/Cutie/gui/main_controller.py", line 152, in click_fn
    with autocast(self.device, enabled=self.amp and self.device != 'mps'):
  File "/opt/miniconda/envs/cutie/lib/python3.10/site-packages/torch/amp/autocast_mode.py", line 241, in __init__
    raise RuntimeError(
RuntimeError: User specified an unsupported autocast device_type 'mps'

Fix

anywhere autocast is used in main_controller, I did this? idk there's probably a more elegant way

with autocast('cpu' if self.device == 'mps' else self.device, enabled=self.amp and self.device != 'mps'):
@hkchengrex
Copy link
Owner

Thank you for letting me know. I don't have a Mac device so those functions are all untested.
Can you create a pull request for this if it works?
Thanks again.

@horsto
Copy link

horsto commented Nov 25, 2023

The same thing happens under Windows when using 'cpu' :

Using device: cpu
Single object: False
Traceback (most recent call last):
  File "C:\CODE\Cutie\interactive_demo.py", line 75, in <module>
    ex = MainController(cfg)
  File "C:\CODE\Cutie\gui\main_controller.py", line 59, in __init__
    self.initialize_networks()
  File "C:\CODE\Cutie\gui\main_controller.py", line 129, in initialize_networks
    model_weights = torch.load(self.cfg.weights)
  File "C:\Users\hoben\miniconda3\envs\cutie\lib\site-packages\torch\serialization.py", line 1014, in load
    return _load(opened_zipfile,
  File "C:\Users\hoben\miniconda3\envs\cutie\lib\site-packages\torch\serialization.py", line 1422, in _load
    result = unpickler.load()
  File "C:\Users\hoben\miniconda3\envs\cutie\lib\site-packages\torch\serialization.py", line 1392, in persistent_load
    typed_storage = load_tensor(dtype, nbytes, key, _maybe_decode_ascii(location))
  File "C:\Users\hoben\miniconda3\envs\cutie\lib\site-packages\torch\serialization.py", line 1366, in load_tensor
    wrap_storage=restore_location(storage, location),
  File "C:\Users\hoben\miniconda3\envs\cutie\lib\site-packages\torch\serialization.py", line 381, in default_restore_location
    result = fn(storage, location)
  File "C:\Users\hoben\miniconda3\envs\cutie\lib\site-packages\torch\serialization.py", line 274, in _cuda_deserialize
    device = validate_cuda_device(location)
  File "C:\Users\hoben\miniconda3\envs\cutie\lib\site-packages\torch\serialization.py", line 258, 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.

@horsto
Copy link

horsto commented Nov 26, 2023

A workaround for running it on Mac with MPS is (all in gui/main_controller.py):

Screenshot 2023-11-26 at 18 03 07

@hkchengrex
Copy link
Owner

Thanks all for the comment. I have updated the autocast and model loading part. Works on Ubuntu CUDA and CPU.

@hkchengrex
Copy link
Owner

Haven't tested this for Mac -- please feel free to re-open if this fix is not sufficient.

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