diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

getattr() attribute name must be a string

Open Lalats12 opened this issue 2 years ago • 3 comments

Describe the bug

When executing the file, save_onnx.py, I encountered this error

Traceback (most recent call last):
  File "C:\Users\jpyea\Desktop\For fun\Stable Diffuse\diffusers\examples\inference\save_onnx.py", line 16, in <module>
    pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", scheduler=lms, use_auth_token=True)
  File "C:\Users\jpyea\Desktop\For fun\Stable Diffuse\diffusers\src\diffusers\pipeline_utils.py", line 240, in from_pretrained
    load_method = getattr(class_obj, load_method_name)
TypeError: getattr(): attribute name must be string

Reproduction

Logs

No response

System Info

Python 3.10.6
Diffuser version: 1.4

Lalats12 avatar Dec 12 '22 05:12 Lalats12

Additional notes

I found this while modifying the code

<class 'diffusers.pipelines.stable_diffusion.safety_checker.StableDiffusionSafetyChecker'> from_pretrained <class 'diffusers.models.vae.AutoencoderKL'> from_pretrained <class 'transformers.models.clip.modeling_clip.CLIPTextModel'> from_pretrained <class 'transformers.models.clip.image_processing_clip.CLIPImageProcessor'> None Traceback (most recent call last): File "C:\Users\jpyea\Desktop\For fun\Stable DIffusion\diffusers\examples\inference\save_onnx.py", line 16, in pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", scheduler=lms, use_auth_token=True) File "C:\Users\jpyea\Desktop\For fun\Stable DIffusion\diffusers\src\diffusers\pipeline_utils.py", line 241, in from_pretrained load_method = getattr(class_obj, load_method_name) TypeError: getattr(): attribute name must be string

Lalats12 avatar Dec 12 '22 10:12 Lalats12

This worked for me:

This getattr() error is caused by the latest update on the transformers package (4.25.1/4.25.0: Dec.2, 2022). To fix it, simply downgrade the transformers package to an earlier version, e.g., pip install transformers==4.24.0, then everything goes fine.

https://huggingface.co/CompVis/stable-diffusion-v1-4/discussions/158#638eb290e160c226bac9d428

redwolf2 avatar Dec 12 '22 23:12 redwolf2

i was having the same problem and when i downgraded i ran into the problem where the module CLIPImageprocessor was missing. The solution is to upgrade transformers to the latest version 4.29.2 and then upgrade diffusers with the command pip install -U diffusers. Im currently running version 0.16.1

anomaliesintent112 avatar Jun 04 '23 07:06 anomaliesintent112