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 pipeline]: A new Pixart-based inpainting pipeline. #7929

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

eightmusic
Copy link

We add a pixart model-based inpaint method that works similarly to pipeline_stable_diffusion_inpaint. @sayakpaul @yiyixuxu @DN6

@sayakpaul
Copy link
Member

Could we see some results here to decide if it's worth adding as a core pipeline?

Cc: @lawrence-cj

@yiyixuxu
Copy link
Collaborator

cc @asomoza here too!

@eightmusic
Copy link
Author

Could we see some results here to decide if it's worth adding as a core pipeline?

Cc: @lawrence-cj

prompt='Face of a yellow cat, high resolution, sitting on a park bench'
res
prompt=''
res1
This is an image of the effects of a different prompt, which the pipeline has merged with the official PixArt repository.@sayakpaul @yiyixuxu @DN6 @lawrence-cj

@sayakpaul sayakpaul requested a review from yiyixuxu May 17, 2024 07:28
@sayakpaul
Copy link
Member

@lawrence-cj could you review this too?

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

@@ -0,0 +1,1097 @@
# Copyright 2023 PixArt-Alpha Authors and The HuggingFace Team. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Copyright 2023 PixArt-Alpha Authors and The HuggingFace Team. All rights reserved.
# Copyright 2024 PixArt-Alpha Authors and The HuggingFace Team. All rights reserved.

>>> 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 = download_image(img_url).resize((512, 512))
Copy link
Member

Choose a reason for hiding this comment

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

Could replace this with diffusers.utils.load_image(). Less lines of code. WDYT?

```
"""

ASPECT_RATIO_1024_BIN = {
Copy link
Member

Choose a reason for hiding this comment

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

Do we wanna move these constants to the init of pixart as these are now access by two pipelines? WDYT?

Cc: @lawrence-cj WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

It sounds reasonable for me.

Comment on lines 281 to 294
def encode_prompt(
self,
prompt: Union[str, List[str]],
do_classifier_free_guidance: bool = True,
negative_prompt: str = "",
num_images_per_prompt: int = 1,
device: Optional[torch.device] = None,
prompt_embeds: Optional[torch.FloatTensor] = None,
negative_prompt_embeds: Optional[torch.FloatTensor] = None,
prompt_attention_mask: Optional[torch.FloatTensor] = None,
negative_prompt_attention_mask: Optional[torch.FloatTensor] = None,
clean_caption: bool = False,
**kwargs,
):
Copy link
Member

Choose a reason for hiding this comment

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

We should use the same method from the PixArtAlpha implementation and use a # Copied from ... statement here.

extra_step_kwargs["generator"] = generator
return extra_step_kwargs

def check_inputs(
Copy link
Member

Choose a reason for hiding this comment

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

If this copied from the text-to-image pipeline implementation, let's use the # Copied from ... statement here. Applies here and elsewhere.

But here, I think the function should also validate the input image and the mask image. Here's a reference:

Comment on lines 693 to 701
def classify_height_width_bin(height: int, width: int, ratios: dict) -> Tuple[int, int]:
"""Returns binned height and width."""
ar = float(height / width)
closest_ratio = min(ratios.keys(), key=lambda ratio: abs(float(ratio) - ar))
default_hw = ratios[closest_ratio]
return int(default_hw[0]), int(default_hw[1])

@staticmethod
def resize_and_crop_tensor(samples: torch.Tensor, new_width: int, new_height: int) -> torch.Tensor:
Copy link
Member

Choose a reason for hiding this comment

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

# Copied from ... statement missing.

Copy link
Author

Choose a reason for hiding this comment

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

Recommits have been made in the appropriate format.@sayakpaul

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

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

The pipeline implementation looks very nice to me, thank you so much!

I think what's pending for this PR to get merged is the following:

  • Docs
  • Test

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 for adding this pipeline!
+1 on @sayakpaul 's comments about doc and tests

If `return_dict` is `True`, [`~pipelines.ImagePipelineOutput`] is returned, otherwise a `tuple` is
returned where the first element is a list with the generated images
"""
if "mask_feature" in kwargs:
Copy link
Collaborator

Choose a reason for hiding this comment

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

we don't need to deprecate for new pipeline

@sayakpaul
Copy link
Member

@eightmusic let's get the comments resolved and we would be happy to include in the new release we're cooking.

@eightmusic
Copy link
Author

@eightmusic let's get the comments resolved and we would be happy to include in the new release we're cooking.
ruff check examples scripts src tests utils benchmarks setup.py
src/diffusers/pipelines/pixart_alpha/pipeline_pixart_inpaint.py:15:1: I001 [] Import block is un-sorted or un-formatted
src/diffusers/pipelines/pixart_alpha/pipeline_pixart_inpaint.py:23:31: F401 [
] torch.nn.functional imported but unused
src/diffusers/pipelines/pixart_alpha/pipeline_pixart_inpaint.py:454:1: W293 [] Blank line contains whitespace
src/diffusers/pipelines/pixart_alpha/pipeline_pixart_inpaint.py:509:1: W293 [
] Blank line contains whitespace
src/diffusers/pipelines/pixart_alpha/pipeline_pixart_inpaint.py:1092:49: W292 [] No newline at end of file
Found 5 errors.
[
] 5 fixable with the --fix option.
make: *** [Makefile:43: quality] Error 1
These problems have been solved.@sayakpaul

@sayakpaul
Copy link
Member

sayakpaul commented May 21, 2024

Thank you!

There are still open comments left to be addressed. Additionally, we need to have docs and tests for this to get merged.

@eightmusic
Copy link
Author

Thank you!

There are still open comments left to be addressed. Additionally, we need to have docs and tests for this to get merged.

The previous comments should be resolved, is there anything else I need to do?

@sayakpaul
Copy link
Member

Well, the tests are failing. We need to get them sorted. And then there are comments still open, e.g.: #7929 (review), #7929 (comment).

And then we need to add tests for the pipeline and documentation. LMK if there's anything unclear.

@eightmusic
Copy link
Author

#7929 (review), #7929 (comment) problem has just been solved.'We need to get them sorted.' What do I need to do here. Are there any references to test and docs? I don't know what this is.@sayakpaul

@sayakpaul
Copy link
Member

Are there any references to test and docs?

Quality tests can be fixed by running make style && make quality. Refer to the contribution guidelines for more details.

@lawrence-cj
Copy link
Contributor

Sry to disturb you, but I found I can't push a commit to this branch, any suggestions? @sayakpaul

@sayakpaul
Copy link
Member

I think you will need for submit a PR to https://github.com/eightmusic/diffusers/. Perhaps @eightmusic could add you as a collaborator to the repo?

@lawrence-cj
Copy link
Contributor

lawrence-cj commented May 22, 2024

Agree. I can help adding the make style and test part. Is it possible to add me as a collaborator to your forked diffusers repo? @eightmusic

@eightmusic
Copy link
Author

Agree. I can help adding the make style and test part. Is it possible to add me as a collaborator to your forked diffusers repo? @eightmusic

of course.

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.

None yet

5 participants