huggingface / diffusers

🤗 Diffusers: State-of-the-art diffusion models for image and audio generation in PyTorch and FLAX.
https://huggingface.co/docs/diffusers
Apache License 2.0
25.43k stars 5.27k forks source link

AttributeError: 'bool' object has no attribute '__module__'. Did you mean: '__mod__'? #6324

Closed Jannchie closed 8 months ago

Jannchie commented 9 months ago

Describe the bug

not_compiled_module could return bool. This causes this example to report an error:

https://github.com/huggingface/diffusers/blob/main/examples/community/README.md?rgh-link-date=2023-12-25T13%3A48%3A18Z#tensorrt-image2image-stable-diffusion-pipeline

Reproduction

https://github.com/huggingface/diffusers/blob/main/examples/community/README.md?rgh-link-date=2023-12-25T13%3A48%3A18Z#tensorrt-image2image-stable-diffusion-pipeline

Logs

Traceback (most recent call last):
  File "C:\Code\diffusers-playground\img2img\sdt.py", line 18, in <module>
    pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
  File "C:\Users\Jannchie\anaconda3\envs\streamdiffusion\lib\site-packages\diffusers\pipelines\pipeline_utils.py", line 1357, in from_pretrained
    model = pipeline_class(**init_kwargs)
  File "C:\Users\Jannchie\.cache\huggingface\modules\diffusers_modules\git\stable_diffusion_tensorrt_img2img.py", line 726, in __init__
    super().__init__(
  File "C:\Users\Jannchie\anaconda3\envs\streamdiffusion\lib\site-packages\diffusers\pipelines\stable_diffusion\pipeline_stable_diffusion_img2img.py", line 276, in __init__
    self.register_modules(
  File "C:\Users\Jannchie\anaconda3\envs\streamdiffusion\lib\site-packages\diffusers\pipelines\pipeline_utils.py", line 566, in register_modules
    library = not_compiled_module.__module__.split(".")[0]
AttributeError: 'bool' object has no attribute '__module__'. Did you mean: '__mod__'?

### System Info

Who can help?

No response

sayakpaul commented 9 months ago

Cc: @asfiyab-nvidia, the original contributor of the pipeline.

github-actions[bot] commented 8 months ago

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

oaramoon commented 7 months ago

I am having the same issue.

federicoBetti commented 7 months ago

I am having the same issue.

I just faced the same problem. Reverting back to a previous version (0.21.1) fixed the problem for me. It is something in between these two versions. Can't tell more than that...

Jannchie commented 7 months ago

I've resolved this issue on my end, and I'll submit a pull request for it later.

jloveric commented 6 months ago

I seem to have had this problem with diffusers==0.27.2 but resolved it bumping back to 0.21.1

sayakpaul commented 6 months ago

Could you provide reproducible code snippet for this?

tiimgreen commented 6 months ago

@sayakpaul I'm getting this error when running:

python convert_original_stable_diffusion_to_diffusers.py --checkpoint_path <safetensors_file> --dump_path <output_dir> --from_safetensors --pipeline_class_name StableDiffusionXLControlNetInpaintPipeline --controlnet

Specifically, the --controlnet flag is the culprit here.

sayakpaul commented 6 months ago

I welcome you to open a new issue with a fully reproducible code snippet.

rezkanas commented 6 months ago

for some reason, I start having this issue too,

 File "/home/anasrezklinux/anas_april/visual_story.py", line 354, in dream_booth_inference
    pipe = StableDiffusionPipeline.from_pretrained(output_dir, safety_checker=True, torch_dtype=torch.float16,
  File "/home/anasrezklinux/anas_april/venv/lib/python3.10/site-packages/diffusers/pipelines/pipeline_utils.py", line 1196, in from_pretrained
    model = pipeline_class(**init_kwargs)
  File "/home/anasrezklinux/anas_april/venv/lib/python3.10/site-packages/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py", line 183, in __init__
    self.register_modules(
  File "/home/anasrezklinux/anas_april/venv/lib/python3.10/site-packages/diffusers/pipelines/pipeline_utils.py", line 519, in register_modules
    library = not_compiled_module.__module__.split(".")[0]
AttributeError: 'bool' object has no attribute '__module__'. Did you mean: '__mod__'?

when running

pipe = StableDiffusionPipeline.from_pretrained(output_dir, safety_checker=True, torch_dtype=torch.float16,
                                                       low_cpu_mem_usage=False, device_map=None).to("cuda")
stevens-Ai commented 5 months ago

I seem to have had this problem with diffusers==0.27.2 but resolved it bumping back to 0.21.1

This worked for me. pip uninstall diffusers pip install diffusers==0.21.1

MaxBer04 commented 5 months ago

Hello there, I was having the same problem when switching vom diffusers 0.21.1 to 0.27.1. The setup was very basic with the following model: SG161222/Realistic_Vision_V2.0

After some digging into the source code, I found that the module registration from the image_encoder in the diffusion pipeline caused the error. After commenting out the registration of the image encoder in the following source code:

` self.register_modules( vae=vae, text_encoder=text_encoder, tokenizer=tokenizer, unet=unet, scheduler=scheduler, safety_checker=safety_checker, feature_extractor=feature_extractor,

image_encoder=image_encoder,

    )

`

in the init-method of the StableDiffusionPipeline on line 249, it works for me with diffusers 0.27.1. I think it has to do with the added image processor (ip)/additional image conditioning support added after 0.21.1. Maybe the image encoder is not defined in older pipelines, causing this wierd error. I may be wrong though... Also, I haven't found a nice solution yet without modifying the source code of diffusers.

YuzhiChen001 commented 4 months ago

tag