mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2024-06-07 21:20:49 +00:00
Add workaround for using MPS with torchsde
This commit is contained in:
parent
98ca437edf
commit
21effd629d
@ -6,6 +6,7 @@ import tqdm
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
import inspect
|
import inspect
|
||||||
import k_diffusion.sampling
|
import k_diffusion.sampling
|
||||||
|
import torchsde._brownian.brownian_interval
|
||||||
import ldm.models.diffusion.ddim
|
import ldm.models.diffusion.ddim
|
||||||
import ldm.models.diffusion.plms
|
import ldm.models.diffusion.plms
|
||||||
from modules import prompt_parser, devices, processing, images
|
from modules import prompt_parser, devices, processing, images
|
||||||
@ -367,6 +368,19 @@ class TorchHijack:
|
|||||||
return torch.randn_like(x)
|
return torch.randn_like(x)
|
||||||
|
|
||||||
|
|
||||||
|
# MPS fix for randn in torchsde
|
||||||
|
def torchsde_randn(size, dtype, device, seed):
|
||||||
|
if device.type == 'mps':
|
||||||
|
generator = torch.Generator(devices.cpu).manual_seed(int(seed))
|
||||||
|
return torch.randn(size, dtype=dtype, device=devices.cpu, generator=generator).to(device)
|
||||||
|
else:
|
||||||
|
generator = torch.Generator(device).manual_seed(int(seed))
|
||||||
|
return torch.randn(size, dtype=dtype, device=device, generator=generator)
|
||||||
|
|
||||||
|
|
||||||
|
torchsde._brownian.brownian_interval._randn = torchsde_randn
|
||||||
|
|
||||||
|
|
||||||
class KDiffusionSampler:
|
class KDiffusionSampler:
|
||||||
def __init__(self, funcname, sd_model):
|
def __init__(self, funcname, sd_model):
|
||||||
denoiser = k_diffusion.external.CompVisVDenoiser if sd_model.parameterization == "v" else k_diffusion.external.CompVisDenoiser
|
denoiser = k_diffusion.external.CompVisVDenoiser if sd_model.parameterization == "v" else k_diffusion.external.CompVisDenoiser
|
||||||
|
Loading…
Reference in New Issue
Block a user