Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diffusers=0.3.0 no longer loads models correctly #22

Open
zakrzewki opened this issue Dec 18, 2023 · 2 comments
Open

diffusers=0.3.0 no longer loads models correctly #22

zakrzewki opened this issue Dec 18, 2023 · 2 comments

Comments

@zakrzewki
Copy link

Hi, I added it as a comment in previous issue, but I think it's nice to raise it as a separate ticket - an issue there was it'd be nice to update diffusers package to newer version, but nowadays I am unable even to run colab demo due to this error.

I wanted to follow up as presented demo colab is not working at all. When downloading StableDiffusion pipeline I got error

TypeError: getattr(): attribute name must be string

I found an error about it on SO: https://stackoverflow.com/questions/74687769/typeerror-getattr-attribute-name-must-be-string-in-pytorch-diffusers-how

When I force to use 0.24, I got error on importing diffusers_interpret:
ImportError: cannot import name 'preprocess_mask' from 'diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_inpaint' (/usr/local/lib/python3.10/dist-packages/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py)

So I tried to install it with pip again but it downloads diffusers back to 0.3.0

So I can create a pipe for stable diffusion (requires diffusers > 0.4) OR I can use diffusers_interpret (requires 0.3).
Both of them does not work together in demo colab meaning I cannot reproduce your output

@JoaoLages
Copy link
Owner

Hi @zakrzewki! Thanks for reaching out.
The problem is in diffusers as you stated, not in diffusers-interpret. diffusers==0.3.0 no longer loads models correctly from HuggingFace Hub.
I took a look and it would take a lot of effort to change this package to now work with a new version of diffusers. I'm can do it, but after some months HuggingFace will change diffusers again, and it will no longer be compatible.
The only real scalable solution is to have them slightly change the package as I mentioned here, and then do the according changes in this package.

@JoaoLages
Copy link
Owner

If you just want a quick and dirty solution, you cane edit /usr/local/lib/python3.10/dist-packages/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py:

  • remove line 6 that imports preprocess_mask
  • create the preprocess_mask in that file:
def preprocess_mask(mask):
    mask = mask.convert("L")
    w, h = mask.size
    w, h = map(lambda x: x - x % 32, (w, h))  # resize to integer multiple of 32
    mask = mask.resize((w // 8, h // 8), resample=PIL.Image.NEAREST)
    mask = np.array(mask).astype(np.float32) / 255.0
    mask = np.tile(mask, (4, 1, 1))
    mask = mask[None].transpose(0, 1, 2, 3)  # what does this step do?
    mask = 1 - mask  # repaint white, keep black
    mask = torch.from_numpy(mask)
    return mask

I don't guarantee that StableDiffusionPipelineExplainer will work 100% though, because the API versions no longer match.

@JoaoLages JoaoLages changed the title No possibility to run colab demo diffusers=0.3.0 no longer loads models correctly Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants