diff options
author | brkirch <brkirch@users.noreply.github.com> | 2023-03-24 06:58:18 +0000 |
---|---|---|
committer | brkirch <brkirch@users.noreply.github.com> | 2023-03-24 08:04:20 +0000 |
commit | c5142e2fbecb50531a55aa804ea132c5d870858c (patch) | |
tree | e4737cadfc641c6ee7074ff3e95cddb2ededecdf /modules | |
parent | a9fed7c364061ae6efb37f797b6b522cb3cf7aa2 (diff) | |
download | stable-diffusion-webui-gfx803-c5142e2fbecb50531a55aa804ea132c5d870858c.tar.gz stable-diffusion-webui-gfx803-c5142e2fbecb50531a55aa804ea132c5d870858c.tar.bz2 stable-diffusion-webui-gfx803-c5142e2fbecb50531a55aa804ea132c5d870858c.zip |
Add workaround for broken nn.Linear on macOS 13.2
Credit to danieldk (https://github.com/explosion/curated-transformers/pull/124) for the workaround this is based on.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/mac_specific.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/modules/mac_specific.py b/modules/mac_specific.py index 18e6ff72..3a170f60 100644 --- a/modules/mac_specific.py +++ b/modules/mac_specific.py @@ -1,4 +1,5 @@ import torch +import platform from modules import paths from modules.sd_hijack_utils import CondFunc from packaging import version @@ -32,6 +33,10 @@ if has_mps: # MPS fix for randn in torchsde CondFunc('torchsde._brownian.brownian_interval._randn', lambda _, size, dtype, device, seed: torch.randn(size, dtype=dtype, device=torch.device("cpu"), generator=torch.Generator(torch.device("cpu")).manual_seed(int(seed))).to(device), lambda _, size, dtype, device, seed: device.type == 'mps') + if platform.mac_ver()[0].startswith("13.2."): + # MPS workaround for https://github.com/pytorch/pytorch/issues/95188, thanks to danieldk (https://github.com/explosion/curated-transformers/pull/124) + CondFunc('torch.nn.functional.linear', lambda _, input, weight, bias: (torch.matmul(input, weight.t()) + bias) if bias is not None else torch.matmul(input, weight.t()), lambda _, input, weight, bias: input.numel() > 10485760) + if version.parse(torch.__version__) < version.parse("1.13"): # PyTorch 1.13 doesn't need these fixes but unfortunately is slower and has regressions that prevent training from working |