Skip to content

Conversation

@asomoza
Copy link
Member

@asomoza asomoza commented Jul 12, 2024

What does this PR do?

Fixes one specific use case for SDXL image to image where we pass multiple generators but only one image. This PR expands the image tensor so it matches the number of generators.

To reproduce the error without this PR:

import torch

from diffusers import StableDiffusionXLImg2ImgPipeline
from diffusers.utils import load_image


pipe = StableDiffusionXLImg2ImgPipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16"
).to("cuda")
source_image = load_image(
    "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/kolors/bunny_source.png"
)


generator = torch.Generator(device="cpu").manual_seed(43)
generator_2 = torch.Generator(device="cpu").manual_seed(44)

image = pipe(
    prompt="high quality photo",
    image=source_image,
    negative_prompt="",
    guidance_scale=6.5,
    num_inference_steps=25,
    strength=0.5,
    generator=[generator, generator_2],
    num_images_per_prompt=2,
).images[0]

Throws:

RuntimeError: cannot reshape tensor of 0 elements into shape [0, -1, 1, 512] because the unspecified dimension size -1 can be any value and is ambiguous

This error wasn't caught in the tests.

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@asomoza asomoza requested a review from DN6 July 12, 2024 12:56
@asomoza asomoza changed the title initial commit [SDXL] Fix uncaught error with image to image Jul 12, 2024
@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
Collaborator

@yiyixuxu yiyixuxu left a comment

Choose a reason for hiding this comment

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

thanks!
can we add to the sd1.5 too?

@asomoza
Copy link
Member Author

asomoza commented Jul 17, 2024

@yiyixuxu @DN6 applied suggestion and added it to the SD1.5 pipelines, ready for a review again.

Copy link
Collaborator

@yiyixuxu yiyixuxu left a comment

Choose a reason for hiding this comment

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

thanks!

@asomoza asomoza mentioned this pull request Jul 19, 2024
@yiyixuxu yiyixuxu merged commit c009c20 into huggingface:main Jul 19, 2024
@asomoza asomoza deleted the sdxl-fix-multiple-generators-one-image branch July 20, 2024 05:37
sayakpaul pushed a commit that referenced this pull request Dec 23, 2024
* initial commit

* apply suggestion to sdxl pipelines

* apply fix to sd pipelines
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