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

Fix attention layers map for SD-2-1-Base #971

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pranav4501
Copy link

The safetensors are not mapped correctly for attention layers of SD-2-1-base.

if "query" in key:
key = key.replace("query", "query_proj")
if "value" in key:
key = key.replace("value", "value_proj")
Copy link
Member

Choose a reason for hiding this comment

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

These don't look correct given that they will result in value_proj_proj and query_proj_proj and to_k. Am I missing sth?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I missed that. I didn't check for sdxl turbo. It should be fine now if we first check for query and then for to_q.
Also, why are we not using load_weights here? Doesn't it help with such mapping issues?

@angeloskath
Copy link
Member

Hi @pranav4501 could you give an example of what wasn't working and what this fixes? I will take a closer look but I would appreciate sth like image2image.py is not working for this model or some weights and the corresponding model file sth that clearly shows the problem.

Thanks and sorry if I am putting extra work on you.

@pranav4501
Copy link
Author

pranav4501 commented Oct 3, 2024

Hi @angeloskath , Sorry for the late response. You will have to make a couple changes to model_io.py of stable diffusion

  1. Update this line(L-175) to
model.load_weights(list(weights),strict=True)
  1. Comment out this line(L-262), Positions ids in CLIP is not implemented, I will try to look into it
  2. Run The image generation
python3 txt2image.py "A photo of an astronaut riding a horse on Mars." --n_images 1 --steps 1 --model sd
  1. You should encounter something like
ValueError: Received parameters not in model: encoder.mid_blocks.1.proj_attn.weight encoder.mid_blocks.1.value.bias decoder.mid_blocks.1.proj_attn.bias decoder.mid_blocks.1.value.bias

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.

2 participants