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

RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. #7

Open
SssTwins opened this issue Mar 26, 2024 · 2 comments

Comments

@SssTwins
Copy link

when i use comfy_pixelization, i got an error

ERROR:root:!!! Exception during processing !!!
ERROR:root:Traceback (most recent call last):
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\execution.py", line 152, in recursive_execute
output_data, output_ui = get_output_data(obj, input_data_all)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\execution.py", line 82, in get_output_data
return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\execution.py", line 75, in map_node_over_list
results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfy_pixelization_init_.py", line 264, in pixelize
model.load()
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfy_pixelization_init_.py", line 150, in load
self.G_A_net = define_G(3, 3, 64, "c2pGen", "instance", False, "normal", 0.02, [0])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfy_pixelization\pixelization\models\networks.py", line 138, in define_G
net = C2PGen(input_nc, output_nc, ngf, 2, 4, 256, 256, activ='relu', pad_type='reflect')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfy_pixelization\pixelization\models\c2pGen.py", line 79, in init
self.PBEnc = PixelBlockEncoder(input_dim, dim, style_dim, norm='none', activ=activ, pad_type=pad_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfy_pixelization\pixelization\models\c2pGen.py", line 124, in init
vgg19.load_state_dict(torch.load('./pixelart_vgg19.pth'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfy_pixelization_init_.py", line 118, in load
return torch.load(filename, map_location='cpu', *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\serialization.py", line 1026, in load
return _load(opened_zipfile,
^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\serialization.py", line 1438, in _load
result = unpickler.load()
^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\serialization.py", line 1408, in persistent_load
typed_storage = load_tensor(dtype, nbytes, key, _maybe_decode_ascii(location))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\serialization.py", line 1382, in load_tensor
wrap_storage=restore_location(storage, location),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\serialization.py", line 391, in default_restore_location
result = fn(storage, location)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\serialization.py", line 266, in _cuda_deserialize
device = validate_cuda_device(location)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\serialization.py", line 250, 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.

These are my pc device parameters

cpu: AMD Ryzen™ 7 5700X
gpu: AMD Radeon™ RX 6650 XT

What have I tried?

change ComfyUI\custom_nodes\comfy_pixelization_init_.py
line 36, from 'return torch.device(get_optimal_device_name())' to 'return torch.device("cpu")'
line 118, from 'return torch.load(filename, *args, **kwargs)' to 'return torch.load(filename, map_location='cpu', *args, **kwargs)'
line 153 from 'G_A_state = torch.load(path_160_net_G_A)' to 'G_A_state = torch.load(path_160_net_G_A, map_location=device)'
line 158 from 'alias_state = torch.load(path_alias_net)' to 'alias_state = torch.load(path_alias_net,map_location=device)'

Look forward to hearing from you

@SssTwins
Copy link
Author

when i use comfy_pixelization, i got an error

ERROR:root:!!! Exception during processing !!!
ERROR:root:Traceback (most recent call last):
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\execution.py", line 152, in recursive_execute
output_data, output_ui = get_output_data(obj, input_data_all)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\execution.py", line 82, in get_output_data
return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\execution.py", line 75, in map_node_over_list
results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfy_pixelization__init__.py", line 264, in pixelize
model.load()
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfy_pixelization__init__.py", line 150, in load
self.G_A_net = define_G(3, 3, 64, "c2pGen", "instance", False, "normal", 0.02, [0])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfy_pixelization\pixelization\models\networks.py", line 138, in define_G
net = C2PGen(input_nc, output_nc, ngf, 2, 4, 256, 256, activ='relu', pad_type='reflect')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfy_pixelization\pixelization\models\c2pGen.py", line 79, in init
self.PBEnc = PixelBlockEncoder(input_dim, dim, style_dim, norm='none', activ=activ, pad_type=pad_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfy_pixelization\pixelization\models\c2pGen.py", line 124, in init
vgg19.load_state_dict(torch.load('./pixelart_vgg19.pth'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfy_pixelization__init__.py", line 118, in load
return torch.load(filename, map_location='cpu', *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\serialization.py", line 1026, in load
return _load(opened_zipfile,
^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\serialization.py", line 1438, in _load
result = unpickler.load()
^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\serialization.py", line 1408, in persistent_load
typed_storage = load_tensor(dtype, nbytes, key, _maybe_decode_ascii(location))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\serialization.py", line 1382, in load_tensor
wrap_storage=restore_location(storage, location),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\serialization.py", line 391, in default_restore_location
result = fn(storage, location)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\serialization.py", line 266, in _cuda_deserialize
device = validate_cuda_device(location)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\serialization.py", line 250, 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.

These are my pc device parameters

cpu: AMD Ryzen™ 7 5700X
gpu: AMD Radeon™ RX 6650 XT

What have I tried?

change ComfyUI\custom_nodes\comfy_pixelization__init__.py
line 36, from 'return torch.device(get_optimal_device_name())' to 'return torch.device("cpu")'
line 118, from '**return torch.load(filename, *args, kwargs)' to '**return torch.load(filename, map_location='cpu', *args, kwargs)'
line 153 from 'G_A_state = torch.load(path_160_net_G_A)' to 'G_A_state = torch.load(path_160_net_G_A, map_location=device)'
line 158 from 'alias_state = torch.load(path_alias_net)' to 'alias_state = torch.load(path_alias_net,map_location=device)'

Look forward to hearing from you

comfy run as cpu mode

@filipemeneses
Copy link
Owner

Awesome, thanks for reaching out, I'll try later with the following (used this as guide)

            G_A_state = torch.load(path_160_net_G_A, map_location={'cuda:0': device})
...
            alias_state = torch.load(path_alias_net, map_location={'cuda:0': device})

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

2 participants