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

Add PAG Support for Stable Diffusion Inpaint Pipeline #9386

Merged
merged 28 commits into from
Dec 10, 2024

Conversation

darshil0805
Copy link
Contributor

What does this PR do?

Fixes #8710 Partially

Before submitting

Who can review?

@yiyixuxu
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.

Hi, I have written the code and added the relevant tests and ran them, they failed in 3 cases, attached below, I'll need some assistance to test the code using images as I am GPU poor

Screenshot 2024-09-07 at 2 51 55 PM

@yiyixuxu yiyixuxu added the PAG label Sep 9, 2024
@yiyixuxu yiyixuxu self-requested a review September 9, 2024 16:19
@darshil0805
Copy link
Contributor Author

darshil0805 commented Sep 30, 2024

Hi @yiyixuxu @a-r-r-o-w, following up in case you missed this, let me know if there is anything I can do to speed up this process

@asomoza
Copy link
Member

asomoza commented Sep 30, 2024

Hi, can you please resolve the conflicts?

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! very nice!
I left some small feedbacks!

@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
Member

@a-r-r-o-w a-r-r-o-w left a comment

Choose a reason for hiding this comment

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

Could you fix the quality tests using make quality? Could you also add this pipeline to the PAG docs: https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/pipelines/pag.md

@darshil0805
Copy link
Contributor Author

from diffusers import AutoPipelineForInpainting
from diffusers.utils import load_image
import torch

device = "cuda"

# Load the image-to-image pipeline with pre-trained weights
pipe = AutoPipelineForInpainting.from_pretrained("runwayml/stable-diffusion-inpainting", enable_pag=True, torch_dype = torch.float16)
pipe.to(device)
pipe.enable_model_cpu_offload()


img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"

init_image = load_image(img_url).convert("RGB")
mask_image = load_image(mask_url).convert("RGB")

prompt = "A majestic tiger sitting on a bench"


pag_scales =  [0.0, 3.0]
guidance_scales = [7.5]

grid = []
for pag_scale in pag_scales:
    for guidance_scale in guidance_scales:
        generator = torch.Generator(device="cpu").manual_seed(1)
        images = pipe(
            prompt=prompt,
            image=init_image,
            mask_image=mask_image,
            strength=0.8,
            num_inference_steps=50,
            guidance_scale=guidance_scale,
            generator=generator,
            pag_scale=pag_scale,
        ).images
        images[0]

        grid.append(images[0])

# save the grid
from diffusers.utils import make_image_grid
make_image_grid(grid, rows=len(guidance_scales), cols=len(pag_scales)).save("test_out.png")

I was able to get this code running on Colab, this is how the outputs look:
test_out-3

@yiyixuxu
Copy link
Collaborator

yiyixuxu commented Oct 9, 2024

I think CI still not passing
can you run make style?

@darshil0805
Copy link
Contributor Author

I think CI still not passing
can you run make style?

I've ran it and made the change, hopefully it passes now

@@ -55,7 +57,6 @@
from .pipeline_pag_sd import StableDiffusionPAGPipeline
from .pipeline_pag_sd_3 import StableDiffusion3PAGPipeline
from .pipeline_pag_sd_animatediff import AnimateDiffPAGPipeline
from .pipeline_pag_sd_img2img import StableDiffusionPAGImg2ImgPipeline
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this a merge conflict? can yo uadd this line back?

@@ -55,7 +57,6 @@
from .pipeline_pag_sd import StableDiffusionPAGPipeline
from .pipeline_pag_sd_3 import StableDiffusion3PAGPipeline
from .pipeline_pag_sd_animatediff import AnimateDiffPAGPipeline
from .pipeline_pag_sd_img2img import StableDiffusionPAGImg2ImgPipeline
Copy link
Collaborator

Choose a reason for hiding this comment

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

also need to add pag sd inpaint here too -currently CI fail for some import error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@yiyixuxu
Copy link
Collaborator

@darshil0805
Copy link
Contributor Author

I'm still seeing an import error https://github.com/huggingface/diffusers/actions/runs/11266431877/job/31368980510?pr=9386#step:5:250

Not sure why there is an import error, I'm able to test the script through Colab
Here's the notebook: https://colab.research.google.com/drive/1wgqDCNDlX6Fb47BMQN7GzWKtvhpounXD?usp=sharing

Copy link

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.

@github-actions github-actions bot added the stale Issues that haven't received updates label Nov 13, 2024
@yiyixuxu yiyixuxu added close-to-merge contributions-welcome and removed stale Issues that haven't received updates labels Dec 3, 2024
@yiyixuxu
Copy link
Collaborator

yiyixuxu commented Dec 3, 2024

can anyone help look into the import error here?

@ParagEkbote
Copy link
Contributor

Can I please contribute to fixing the import errors?

cc: @yiyixuxu

Copy link
Collaborator

@hlky hlky left a comment

Choose a reason for hiding this comment

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

make fix-copies (after suggested change) should resolve the dependency issue

src/diffusers/pipelines/pag/pipeline_pag_sd_inpaint.py Outdated Show resolved Hide resolved
@yiyixuxu
Copy link
Collaborator

@hlky feel free to merge if it looks good to you!

tests/pipelines/pag/test_pag_sd_inpaint.py Outdated Show resolved Hide resolved
tests/pipelines/pag/test_pag_sd_inpaint.py Outdated Show resolved Hide resolved
@hlky hlky merged commit 65b98b5 into huggingface:main Dec 10, 2024
15 checks passed
@yiyixuxu yiyixuxu added the roadmap Add to current release roadmap label Dec 11, 2024
sayakpaul pushed a commit that referenced this pull request Dec 23, 2024
* using sd inpaint pipeline and sdxl pag inpaint pipeline to add changes

* using sd inpaint pipeline and sdxl pag inpaint pipeline to add changes

* finished the call function

* added auto pipeline

* merging diffusers

* ready to test

* ready to test

* added copied from and removed unnecessary tests

* make style changes

* doc changes

* updating example doc string

* style fix

* init

* adding imports

* quality

* Update src/diffusers/pipelines/pag/pipeline_pag_sd_inpaint.py

* make

* Update tests/pipelines/pag/test_pag_sd_inpaint.py

* slice and size

* slice

---------

Co-authored-by: Darshil Jariwala <[email protected]>
Co-authored-by: Darshil Jariwala <[email protected]>
Co-authored-by: YiYi Xu <[email protected]>
Co-authored-by: hlky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add PAG support to SD1.5
7 participants