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

Can't run on MacBook #14

Open
script-money opened this issue Mar 12, 2023 · 8 comments
Open

Can't run on MacBook #14

script-money opened this issue Mar 12, 2023 · 8 comments

Comments

@script-money
Copy link

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.

Is it possible to run on CPU?

@swankwc
Copy link

swankwc commented Mar 31, 2023

Getting the same thing

@d3vilh
Copy link

d3vilh commented Apr 22, 2023

I managed to run it with following modifications:

  1. add map_location='cpu' to all the torch.load functions in:
    1.1 pixelization/models/pixelization_model.py
    1.2 pixelization/models/base_model.py
    1.3 pixelization/models/c2pGen.py
    1.4 scripts/postprocessing_pixelization.py - 2 lines

    Like this:

    pixelization/models/pixelization_model.py:        state_dict = torch.load(load_path, map_location='cpu')
    pixelization/models/base_model.py:                state_dict = torch.load(load_path, map_location='cpu')
    pixelization/models/c2pGen.py:        vgg19.load_state_dict(torch.load('./pixelart_vgg19.pth', map_location='cpu'))
    scripts/postprocessing_pixelization.py:            G_A_state = torch.load(path_160_net_G_A, map_location='cpu')
    scripts/postprocessing_pixelization.py:            alias_state = torch.load(path_alias_net, map_location='cpu')
  2. Patch pixelization/models/networks.py:
    2.1 Comment CUDA availability check
    2.2 Force DataParallel function to use device 'cpu' on line 113

Like this:

stable-diffusion-webui-pixelization % grep -B3 cpu pixelization/models/networks.py
    if len(gpu_ids) > 0:
      #  assert(torch.cuda.is_available())
      #  net.to(gpu_ids[0])
        net = torch.nn.DataParallel(net, 'cpu')  # multi-GPUs
stable-diffusion-webui-pixelization %
  1. Restart webui.sh and Pixelize.

Enjoy.

@jpfaraco
Copy link

jpfaraco commented May 1, 2023

I modified the files and it now generates images, just not as expected:
Screen Shot 2023-05-01 at 13 26 12

@chariumaboat
Copy link

I am also having the same problem.

@Demacsspider
Copy link

I managed to run it with following modifications:

  1. add map_location='cpu' to all the torch.load functions in:
    1.1 pixelization/models/pixelization_model.py
    1.2 pixelization/models/base_model.py
    1.3 pixelization/models/c2pGen.py
    1.4 scripts/postprocessing_pixelization.py - 2 lines
    Like this:
    pixelization/models/pixelization_model.py:        state_dict = torch.load(load_path, map_location='cpu')
    pixelization/models/base_model.py:                state_dict = torch.load(load_path, map_location='cpu')
    pixelization/models/c2pGen.py:        vgg19.load_state_dict(torch.load('./pixelart_vgg19.pth', map_location='cpu'))
    scripts/postprocessing_pixelization.py:            G_A_state = torch.load(path_160_net_G_A, map_location='cpu')
    scripts/postprocessing_pixelization.py:            alias_state = torch.load(path_alias_net, map_location='cpu')
  2. Patch pixelization/models/networks.py:
    2.1 Comment CUDA availability check
    2.2 Force DataParallel function to use device 'cpu' on line 113

Like this:

stable-diffusion-webui-pixelization % grep -B3 cpu pixelization/models/networks.py
    if len(gpu_ids) > 0:
      #  assert(torch.cuda.is_available())
      #  net.to(gpu_ids[0])
        net = torch.nn.DataParallel(net, 'cpu')  # multi-GPUs
stable-diffusion-webui-pixelization %
  1. Restart webui.sh and Pixelize.

Enjoy.

I tried altering the files exactly as you described, after a complete restart of Automatic1111 and terminal, the pixelation option disappear's from the webui (in the extras tab). Any idea what's happening or what I can do to get it to run (on an M1 Mac)?

@DarshanAdroja
Copy link

I managed to run it with following modifications:

  1. add map_location='cpu' to all the torch.load functions in:
    1.1 pixelization/models/pixelization_model.py
    1.2 pixelization/models/base_model.py
    1.3 pixelization/models/c2pGen.py
    1.4 scripts/postprocessing_pixelization.py - 2 lines
    Like this:
    pixelization/models/pixelization_model.py:        state_dict = torch.load(load_path, map_location='cpu')
    pixelization/models/base_model.py:                state_dict = torch.load(load_path, map_location='cpu')
    pixelization/models/c2pGen.py:        vgg19.load_state_dict(torch.load('./pixelart_vgg19.pth', map_location='cpu'))
    scripts/postprocessing_pixelization.py:            G_A_state = torch.load(path_160_net_G_A, map_location='cpu')
    scripts/postprocessing_pixelization.py:            alias_state = torch.load(path_alias_net, map_location='cpu')
  2. Patch pixelization/models/networks.py:
    2.1 Comment CUDA availability check
    2.2 Force DataParallel function to use device 'cpu' on line 113

Like this:

stable-diffusion-webui-pixelization % grep -B3 cpu pixelization/models/networks.py
    if len(gpu_ids) > 0:
      #  assert(torch.cuda.is_available())
      #  net.to(gpu_ids[0])
        net = torch.nn.DataParallel(net, 'cpu')  # multi-GPUs
stable-diffusion-webui-pixelization %
  1. Restart webui.sh and Pixelize.

Enjoy.

This worked perfectly for me, Thanks!

@zamzamz3
Copy link

zamzamz3 commented Jun 5, 2024

I could not get it to work this way
Did the code change?

@leouofa
Copy link

leouofa commented Dec 10, 2024

Worked for me 👍

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

9 participants