diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2022-09-07 19:29:44 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-07 19:29:44 +0000 |
commit | 296d012423f8d1862a63680443bb88b7d904ba4e (patch) | |
tree | f0dcc162fb3b3fa97d84d9c9ac7922203fc11df9 | |
parent | ee29bb77bfe3d2095bc08861bcdebeea20b890f1 (diff) | |
parent | ba1124b326280202cb583bbdc669fb5303bbd3e3 (diff) | |
download | stable-diffusion-webui-gfx803-296d012423f8d1862a63680443bb88b7d904ba4e.tar.gz stable-diffusion-webui-gfx803-296d012423f8d1862a63680443bb88b7d904ba4e.tar.bz2 stable-diffusion-webui-gfx803-296d012423f8d1862a63680443bb88b7d904ba4e.zip |
Merge pull request #108 from xeonvs/mps-support
Added support for launching on Apple Silicon M1/M2
-rw-r--r-- | modules/esrgan_model.py | 7 | ||||
-rw-r--r-- | modules/lowvram.py | 9 | ||||
-rw-r--r-- | modules/sd_hijack.py | 2 | ||||
-rw-r--r-- | modules/shared.py | 9 |
4 files changed, 18 insertions, 9 deletions
diff --git a/modules/esrgan_model.py b/modules/esrgan_model.py index 3dcef5a6..2ed1d273 100644 --- a/modules/esrgan_model.py +++ b/modules/esrgan_model.py @@ -14,8 +14,11 @@ import modules.images def load_model(filename):
# this code is adapted from https://github.com/xinntao/ESRGAN
-
- pretrained_net = torch.load(filename)
+ if torch.has_mps:
+ map_l = 'cpu'
+ else:
+ map_l = None
+ pretrained_net = torch.load(filename, map_location=map_l)
crt_model = arch.RRDBNet(3, 3, 64, 23, gc=32)
if 'conv_first.weight' in pretrained_net:
diff --git a/modules/lowvram.py b/modules/lowvram.py index 4b78deab..bd117491 100644 --- a/modules/lowvram.py +++ b/modules/lowvram.py @@ -2,9 +2,12 @@ import torch module_in_gpu = None
cpu = torch.device("cpu")
-gpu = torch.device("cuda")
-device = gpu if torch.cuda.is_available() else cpu
-
+if torch.has_cuda:
+ device = gpu = torch.device("cuda")
+elif torch.has_mps:
+ device = gpu = torch.device("mps")
+else:
+ device = gpu = torch.device("cpu")
def setup_for_low_vram(sd_model, use_medvram):
parents = {}
diff --git a/modules/sd_hijack.py b/modules/sd_hijack.py index 2d26b5f7..1084e248 100644 --- a/modules/sd_hijack.py +++ b/modules/sd_hijack.py @@ -232,7 +232,7 @@ class FrozenCLIPEmbedderWithCustomWords(torch.nn.Module): z = outputs.last_hidden_state
# restoring original mean is likely not correct, but it seems to work well to prevent artifacts that happen otherwise
- batch_multipliers = torch.asarray(np.array(batch_multipliers)).to(device)
+ batch_multipliers = torch.asarray(batch_multipliers).to(device)
original_mean = z.mean()
z *= batch_multipliers.reshape(batch_multipliers.shape + (1,)).expand(z.shape)
new_mean = z.mean()
diff --git a/modules/shared.py b/modules/shared.py index beb6f9bb..e529ec27 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -36,9 +36,12 @@ parser.add_argument("--opt-split-attention", action='store_true', help="enable o parser.add_argument("--listen", action='store_true', help="launch gradio with 0.0.0.0 as server name, allowing to respond to network requests")
cmd_opts = parser.parse_args()
-cpu = torch.device("cpu")
-gpu = torch.device("cuda")
-device = gpu if torch.cuda.is_available() else cpu
+if torch.has_cuda:
+ device = torch.device("cuda")
+elif torch.has_mps:
+ device = torch.device("mps")
+else:
+ device = torch.device("cpu")
batch_cond_uncond = cmd_opts.always_batch_cond_uncond or not (cmd_opts.lowvram or cmd_opts.medvram)
parallel_processing_allowed = not cmd_opts.lowvram and not cmd_opts.medvram
|