tencent-ailab / IP-Adapter

The image prompt adapter is designed to enable a pretrained text-to-image diffusion model to generate images with image prompt.
Apache License 2.0
4.48k stars 293 forks source link

cross_attention_kwargs ['ip_adapter_masks'] are not expected by AttnProcessor2_0 and will be ignored. #335

Open cthulhu-tww opened 2 months ago

cthulhu-tww commented 2 months ago

What error message is this, but it won't cause the task to fail, it will only keep printing,thank you。

Ekundayo39283 commented 2 months ago

Could you elaborate more on this error, maybe share a screenshot or the code along with the error

cthulhu-tww commented 2 months ago

image

cthulhu-tww commented 2 months ago

import torch from diffusers import StableDiffusionXLPipeline from diffusers.image_processor import IPAdapterMaskProcessor from diffusers.utils import load_image from transformers import CLIPVisionModelWithProjection

image_encoder = CLIPVisionModelWithProjection.from_pretrained( "./repository/h94-IP-Adapter", subfolder="models/image_encoder", torch_dtype=torch.float16 ) pipeline = StableDiffusionXLPipeline.from_pretrained("./repository/stable-diffusion-xl-base-1.0", image_encoder=image_encoder, torch_dtype=torch.float16, use_safetensors=True, ).to("cuda") pipeline.enable_model_cpu_offload() pipeline.load_ip_adapter("./repository/h94-IP-Adapter", subfolder="sdxl_models", weight_name=["ip-adapter-plus_sdxl_vit-h.safetensors"] 2) pipeline.set_ip_adapter_scale([0.6] 2) generator = torch.Generator(device="cpu").manual_seed(4) mask1 = load_image( "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/ip_mask_mask1.png") mask2 = load_image( "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/ip_mask_mask2.png") output_height = 1024 output_width = 1024 processor = IPAdapterMaskProcessor() masks = processor.preprocess([mask1, mask2, ]) face_image1 = load_image( "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/ip_mask_girl1.png") face_image2 = load_image( "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/ip_mask_girl2.png") ip_images = [[face_image1], [face_image2]] image = pipeline( prompt="2 girls", ip_adapter_image=ip_images, negative_prompt="monochrome, lowres, bad anatomy, worst quality, low quality", num_inference_steps=20, num_images_per_prompt=1, generator=generator, cross_attention_kwargs={"ip_adapter_masks": masks} ).images[0] image.save("test.png")

cthulhu-tww commented 2 months ago

Both my local machine and the linux server have this error message

cthulhu-tww commented 2 months ago

I checked the source code and I don't understand why the initialized unet's attribute attn_processors down up mid blocks will have two types similar to 'down_blocks.1.attentions.0.transformer_blocks.0.attn1.processor', 'down_blocks.1.attentions. 0.transformer_blocks.0.attn2.processor' And attn2 will be converted into IPAdapterAttnProcessor in the following code. Maybe my initialization parameters are wrong? I'm a beginner and many thanks for helping me with my dilemma

xiaohu2015 commented 2 months ago

https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py#L738-L739 the new version of diffusers input more parameters, you can ignore that.

cthulhu-tww commented 2 months ago

Sorry, I still don't quite understand, what do I need to do now, regardless of this error message?

xiaohu2015 commented 2 months ago

I updated the code, you can try

Ekundayo39283 commented 2 months ago

Sorry, I still don't quite understand, what do I need to do now, regardless of this error message?

You can re run your code @xiaohu2015 has updated diffuser It should be able to receive kwargs now

cthulhu-tww commented 2 months ago

ohhhhhh!!! thank you

cthulhu-tww commented 2 months ago

I tried replacing the two files you updated and tried again, but the problem still exists。

xiaohu2015 commented 2 months ago

your diffuser version? can you test with diffusers==0.22.1?

cthulhu-tww commented 2 months ago

image image If I set diffusers==0.22.1 I can't use the IPAdapterMaskProcessor, as far as I understand the IPAdapterMaskProcessor was introduced with diffusers >= 0.27

xiaohu2015 commented 2 months ago

if you use higher version, you can use the IP-Adapter implemented in diffusers repo (not this repo)

cthulhu-tww commented 2 months ago

ok thank you