AUTOMATIC1111 / stable-diffusion-webui-pixelization

stable-diffusion-webui-pixelization
MIT License
550 stars 72 forks source link

Can't run on MacBook #14

Open script-money opened 1 year ago

script-money commented 1 year ago
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 commented 1 year ago

Getting the same thing

d3vilh commented 1 year ago

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 %
  3. Restart webui.sh and Pixelize.

Enjoy.

jpfaraco commented 1 year ago

I modified the files and it now generates images, just not as expected:

Screen Shot 2023-05-01 at 13 26 12
chariumaboat commented 1 year ago

I am also having the same problem.

Demacsspider commented 1 year ago

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 commented 6 months ago

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 commented 1 month ago

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