gpt4 book ai didi

python - PyTorch 扩散器中的 "TypeError: getattr(): attribute name must be string",如何修复?

转载 作者:行者123 更新时间:2023-12-05 05:30:23 26 4
gpt4 key购买 nike

我正在尝试使用 Pytorch 的漫射器在我的 Mac M1 中生成图片。我有一个像这样的简单语法:

modelid = "CompVis/stable-diffusion-v1-4"
device = "cuda"
pipe = StableDiffusionPipeline.from_pretrained(modelid, revision="fp16", torch_dtype=torch.float16, use_auth_token=auth_token)
pipe.to(device)

当我运行我的脚本时,它抛出一个错误,

(meta_ai) ➜  Difussion_Model /Users/urs/miniforge3/envs/meta_ai/bin/python "/Users/urs/Downloads/Difussion_Model/03_StableD
iffusionApp/app trial1.py"
Fetching 19 files: 100%|██████████████████████████████████████████████████████████████████████████████████|

19/19 [00:00<00:00, 10253.70it/s]
Traceback (most recent call last):
File "/Users/urs/Downloads/Difussion_Model/03_StableDiffusionApp/app trial1.py", line 27, in <module>
pipe = StableDiffusionPipeline.from_pretrained(modelid, revision="fp16", torch_dtype=torch.float16, use_auth_token=auth_token)
File "/Users/urs/miniforge3/envs/meta_ai/lib/python3.9/site-packages/diffusers/pipeline_utils.py", line 239, in from_pretrained
load_method = getattr(class_obj, load_method_name)
TypeError: getattr(): attribute name must be string

在 torch_dtype=torch.float16 中,我尝试了所有可用的不同类型: https://pytorch.org/docs/stable/tensor_attributes.html , 但都不起作用。

有人愿意帮忙吗?

12 月 6 日更新:我从专用于 M1 的官方页面复制并粘贴代码, https://huggingface.co/docs/diffusers/optimization/mps代码如下,

# make sure you're logged in with `huggingface-cli login`
from diffusers import StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
pipe = pipe.to("mps")

# Recommended if your computer has < 64 GB of RAM
pipe.enable_attention_slicing()

prompt = "a photo of an astronaut riding a horse on mars"

# First-time "warmup" pass (see explanation above)
_ = pipe(prompt, num_inference_steps=1)

# Results match those from the CPU device after the warmup pass.
image = pipe(prompt).images[0]

但我仍然得到同样的错误:

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[14], line 4
1 # make sure you're logged in with `huggingface-cli login`
2 from diffusers import StableDiffusionPipeline
----> 4 pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
5 pipe = pipe.to("mps")
7 # Recommended if your computer has < 64 GB of RAM

File ~/miniforge3/envs/meta_ai/lib/python3.9/site-packages/diffusers/pipeline_utils.py:239, in DiffusionPipeline.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
236 if issubclass(class_obj, class_candidate):
237 load_method_name = importable_classes[class_name][1]
--> 239 load_method = getattr(class_obj, load_method_name)
241 loading_kwargs = {}
242 if issubclass(class_obj, torch.nn.Module):

TypeError: getattr(): attribute name must be string

最佳答案

设备应该是mps (设备= 'mps')。 Mac M1 没有内置 Nvidia GPU。

此外,我建议您查看 How to use Stable Diffusion in Apple Silicon (M1/M2) HG 博客并确保满足所有要求。

此外,检查您安装的扩散器版本。

import diffusers
print(diffusers.__version__)

如果是<=0.4.0 ,请使用,

pip install --upgrade diffusers transformers scipy

关于python - PyTorch 扩散器中的 "TypeError: getattr(): attribute name must be string",如何修复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74687769/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com