-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Inference with custom inpainting model triggers: RuntimeError: mat1 and mat2 must have the same dtype #5399
Comments
Could you help us reproduce the issue without |
Sure thing @sayakpaul I can confirm I reproduce the issue without Reproductionimport os
import torch
from diffusers import StableDiffusionInpaintPipeline, UNet2DConditionModel, UniPCMultistepScheduler
from diffusers.utils import load_image
# Generation settings
prompts = ["Face of a yellow cat, high resolution, sitting on a park bench"]
negative_prompts = [""]
seed = 1134232903
generator = torch.Generator(device='cuda').manual_seed(seed)
image = load_image("https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png")
mask_image = load_image("https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png")
# Init pipeline
MODEL_PATH_INPAINTING = os.getenv('MODEL_PATH_INPAINTING')
unet = UNet2DConditionModel.from_pretrained(
MODEL_PATH_INPAINTING,
subfolder="unet",
in_channels=9,
low_cpu_mem_usage=False,
ignore_mismatched_sizes=True
)
default_pipeline = StableDiffusionInpaintPipeline.from_pretrained(
MODEL_PATH_INPAINTING,
unet=unet,
torch_dtype=torch.float16
)
default_pipeline.enable_model_cpu_offload()
default_pipeline.scheduler = UniPCMultistepScheduler.from_config(default_pipeline.scheduler.config)
# Run inference
image = default_pipeline(
prompt=prompts,
negative_prompt=negative_prompts,
image=image,
mask_image=mask_image,
strength=0.6,
num_inference_steps=20,
num_images_per_prompt=1,
generator=generator
).images[0] Log
I'm wondering if this could be related to the OneTrainer conversion script doing something fishy... I thought about converting using https://github.com/huggingface/diffusers/blob/main/scripts/convert_original_stable_diffusion_to_diffusers.py but I'm really not sure what to provide in all the arguments... |
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. |
Bump |
We can't reproduce your code snippet above because we don't know which inpainting model you use. When executing your script above one gets:
|
I mentioned in the first post I was using DreamShaper Inpainting model that was converted to Diffusers format using OneTrainer. The last code snippet wouldn't work out of the box since it is fetching the model from a local path contained in an environment variable... I can try to host a copy of the model on Hugging Face to help creating a reproducible piece of code. But I'm actually not sure whether the issue is with Diffuser or with the converted model itself. How would you suggest to troubleshoot to narrow down the issue? |
Same issue when running inference with my custom trained model on text_to_image task.
|
Nvm, I fixed it. Just remove |
@superkido511 , @patrickvonplaten , @alexisrolland Example Doc: https://huggingface.co/docs/diffusers/using-diffusers/weighted_prompts I used Compel library for prompt embedding and the results are not good :/ |
@kadirnar my original example was already using prompt embeddings and I still got the error. If you got something working, would you mind sharing your code snippet please so that we can see the difference? Thanks |
Sorry. I thought it was a bug with the Combel library. I think you are getting this error because you are using a custom model. I'm using the DreamShaper-Turbo model and it's nice. It would be great to test the Inpaint model as well. How did you convert? |
I tested this code and got the same error. The reason for the error is that the .mode values of the image and mask variables are not RGB. It worked after converting. |
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. |
Describe the bug
I have converted DreamShaper v8 Inpainting to diffusers format using OneTrainer and everything went smoothly, but when I call
StableDiffusionInpaintPipeline
I get the error message: RuntimeError: mat1 and mat2 must have the same dtypeReproduction
Logs
Note I also tried without reloading the
UNet2DConditionModel
and instantiatingStableDiffusionInpaintPipeline
triggers the error: ValueError: Cannot load /models/lykon/dreamshaper-v8-inpainting/unet because conv_in.weight expected shape tensor(..., device='meta', size=(320, 4, 3, 3)), but got torch.Size([320, 9, 3, 3]). If you want to instead overwrite randomly initialized weights, please make sure to pass bothlow_cpu_mem_usage=False
andignore_mismatched_sizes=True
. For more information, see also: #1619 (comment) as an example.Reloading the unet as provided in the code above solved it.
System Info
diffusers
version: 0.21.4Who can help?
@yiyixuxu @DN6 @patrickvonplaten @sayakpaul @patrickvonplaten
The text was updated successfully, but these errors were encountered: