我正在运行 python 代码来在我的 m1 mac 上实现稳定扩散,并在我的 text2img 函数中收到此错误。据我了解,Pytorch 最近开始支持 m1 GPU。我收到此错误(RuntimeError: Device type MPS is not support for torch.Generator() api.)我将代码放在下面并突出显示给我错误的行。非常感谢任何帮助使其正常工作,谢谢!
def txt2img(prompt, width, height, guidance_scale, steps, seed):
global pipe, pipe_type
if pipe_type != 'txt2img':
pipe = None
clear_memory()
pipe_type = 'txt2img'
pipe = StableDiffusionPipeline.from_pretrained(
"CompVis/stable-diffusion-v1-4",
revision="fp16",
torch_dtype=torch.float16,
use_auth_token=YOUR_TOKEN # use huggingface token for private model
).to("mps")
seed = random.randint(0, 2**32) if seed == -1 else seed
generator = torch.Generator(device='mps').manual_seed(int(seed))
pipe.enable_attention_slicing()
with autocast("mps"):
image = pipe(prompt=prompt,
height=height, width=width,
num_inference_steps=steps, …Run Code Online (Sandbox Code Playgroud)