Skip to content

Improve SD XL #3968

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 7 commits into from
Jul 6, 2023
Merged

Improve SD XL #3968

merged 7 commits into from
Jul 6, 2023

Conversation

patrickvonplaten
Copy link
Contributor

@patrickvonplaten patrickvonplaten commented Jul 6, 2023

What does this PR do?

This PR makes sure diffusers Stable Diffusion XL can generate images of any size. We also make sure that both single file format and diffusers format can be loaded.

Diffusers format:

from diffusers import StableDiffusionXLPipeline, StableDiffusionXLImg2ImgPipeline
import torch

use_refiner = True

pipe = StableDiffusionXLPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-0.9", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
pipe.to("cuda")

if use_refiner:
    refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-0.9", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
    refiner.to("cuda")

prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
image = pipe(prompt=prompt, output_type="latent" if use_refiner else "pil").images[0]

if use_refiner:
    image = refiner(prompt=prompt, image=image[None, :]).images[0]

Single File Format:

from diffusers import StableDiffusionXLPipeline, StableDiffusionXLImg2ImgPipeline
import torch

use_refiner = True

pipe = StableDiffusionXLPipeline.from_single_file("https://huggingface.co/stabilityai/stable-diffusion-xl-base-0.9/blob/main/sd_xl_base_0.9.safetensors", torch_dtype=torch.float16, use_safetensors=True)
pipe.to("cuda")

if use_refiner:
    refiner = StableDiffusionXLImg2ImgPipeline.from_single_file("https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-0.9/blob/main/sd_xl_refiner_0.9.safetensors", torch_dtype=torch.float16, use_safetensors=True)
    refiner.to("cuda")

prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
image = pipe(prompt=prompt, output_type="latent" if use_refiner else "pil").images[0]

if use_refiner:
    image = refiner(prompt=prompt, image=image[None, :]).images[0]

Before submitting

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.

steps_offset=1,
timestep_spacing="leading",
)
scheduler = EulerDiscreteScheduler.from_config(scheduler_dict)
Copy link
Contributor

Choose a reason for hiding this comment

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

can we pass a scheduler in? i would like to be able to convert it and attach DDIM, as that's a better sampler for SDXL even though it's divergent from their upstream impl.

Copy link

Choose a reason for hiding this comment

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

I like the idea of being able to customize the scheduler. I like Euler, but I usually customize the settings of the scheduler.

Comment on lines -634 to +635
original_size: Tuple[int, int] = (1024, 1024),
original_size: Tuple[int, int] = None,
crops_coords_top_left: Tuple[int, int] = (0, 0),
target_size: Tuple[int, int] = (1024, 1024),
target_size: Tuple[int, int] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this now defaulting to None? can you explain a bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will then later be set to the passed height and width this makes sure we generate correct outputs for different input sizes than 1024

Copy link
Contributor

@bghira bghira left a comment

Choose a reason for hiding this comment

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

thank you for fixing the CKPT converter.

@patrickvonplaten patrickvonplaten changed the title improve sd xl Improve SD XL Jul 6, 2023
@Mark-divinci
Copy link

i want to increase the batch_size to get larger throughput,but i got linear growth of latency.if i run some incorrect settings?

yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* improve sd xl

* correct more

* finish

* make style

* fix more
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
* improve sd xl

* correct more

* finish

* make style

* fix more
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