Skip to content

Fix a bug in the state dict judgment in ip_adapter.py. #10095

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

Merged
merged 3 commits into from
Dec 5, 2024
Merged

Fix a bug in the state dict judgment in ip_adapter.py. #10095

merged 3 commits into from
Dec 5, 2024

Conversation

zhangp365
Copy link
Contributor

What does this PR do?

When the ipadapter state dict is in a different order, the current code will raise an exception. Updating the conditional statement will fix this issue.

@yiyixuxu

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Contributor

@hlky hlky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 🤗

Minimal reproduction
from diffusers import StableDiffusionPipeline
from transformers import CLIPVisionModelWithProjection

image_encoder = CLIPVisionModelWithProjection.from_pretrained(
  "openai/clip-vit-large-patch14"
)

pipeline = StableDiffusionPipeline.from_pretrained(
  "stable-diffusion-v1-5/stable-diffusion-v1-5",
  image_encoder=image_encoder,
  variant="fp16",
  safety_checker=None,
)

ip_adapter = {"image_proj": {}, "ip_adapter": {}}
try:
  pipeline.load_ip_adapter(ip_adapter, "", "")
except KeyError:
  pass

# raises ValueError on main
ip_adapter = {"ip_adapter": {}, "image_proj": {}}
try:
  pipeline.load_ip_adapter(ip_adapter, "", "")
except KeyError:
  pass

Note: KeyError is expected in this reproduction because we're passing an empty state dict.

@zhangp365
Copy link
Contributor Author

I didn't understand the "Update branch" button before, and I clicked it. Sorry about that.

@yiyixuxu yiyixuxu merged commit 73dac0c into huggingface:main Dec 5, 2024
15 checks passed
@yiyixuxu
Copy link
Collaborator

yiyixuxu commented Dec 5, 2024

thanks @zhangp365 @hlky

sayakpaul pushed a commit that referenced this pull request Dec 23, 2024
* fix a judging state dict bug in ip_adapter.py

* make

---------

Co-authored-by: hlky <hlky@hlky.ac>
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

Successfully merging this pull request may close these issues.

4 participants