我正在运行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))
发布于 2022-11-06 02:29:37
由于您只需要一个随机数,所以只需在CPU中生成它:
generator = torch.Generator().manual_seed(int(seed))发布于 2022-10-11 23:08:36
我也发现了这个问题。如果我使用torch.has_mps.manual_seed(SEED),它将显示AttributeError:'bool‘对象没有属性'manual_seed’
https://stackoverflow.com/questions/73897738
复制相似问题