【发布时间】:2022-11-06 10:29:37
【问题描述】:
我正在运行 python 代码以在我的 m1 mac 上实现稳定的扩散,并在我的 text2img 函数中出现此错误。我了解到 Pytorch 最近开始支持 m1 GPU。我收到此错误(RuntimeError:torch.Generator() api 不支持设备类型 MPS。) 我把代码放在下面并突出显示给我错误的行。将不胜感激任何帮助,让这个工作,谢谢!
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, guidance_scale=guidance_scale,
generator=generator).images[0]
return [[image], seed]
错误引用的主要代码行如下:generator = torch.Generator(device='mps').manual_seed(int(seed))
【问题讨论】: