diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2022-12-24 05:34:46 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-24 05:34:46 +0000 |
commit | 3bfc6c07ae9197bdbd9144cb0b82a137e3e94247 (patch) | |
tree | 34ecc6fa817b80d2a5430687959c82427d610c82 /modules/devices.py | |
parent | f0dfed2a1714f05aa3d87ad475b2615ee9c7972c (diff) | |
parent | cca16373def60bfc6d159a3c2dca91d0ba48112a (diff) | |
download | stable-diffusion-webui-gfx803-3bfc6c07ae9197bdbd9144cb0b82a137e3e94247.tar.gz stable-diffusion-webui-gfx803-3bfc6c07ae9197bdbd9144cb0b82a137e3e94247.tar.bz2 stable-diffusion-webui-gfx803-3bfc6c07ae9197bdbd9144cb0b82a137e3e94247.zip |
Merge pull request #5810 from brkirch/fix-training-mps
Training fixes for MPS
Diffstat (limited to 'modules/devices.py')
-rw-r--r-- | modules/devices.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/modules/devices.py b/modules/devices.py index f8cffae1..800510b7 100644 --- a/modules/devices.py +++ b/modules/devices.py @@ -125,7 +125,16 @@ def layer_norm_fix(*args, **kwargs): return orig_layer_norm(*args, **kwargs) +# MPS workaround for https://github.com/pytorch/pytorch/issues/90532 +orig_tensor_numpy = torch.Tensor.numpy +def numpy_fix(self, *args, **kwargs): + if self.requires_grad: + self = self.detach() + return orig_tensor_numpy(self, *args, **kwargs) + + # PyTorch 1.13 doesn't need these fixes but unfortunately is slower and has regressions that prevent training from working if has_mps() and version.parse(torch.__version__) < version.parse("1.13"): torch.Tensor.to = tensor_to_fix torch.nn.functional.layer_norm = layer_norm_fix + torch.Tensor.numpy = numpy_fix |