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

Official callback tests #7930

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

Conversation

asomoza
Copy link
Member

@asomoza asomoza commented May 13, 2024

What does this PR do?

Tests for the official callbacks introduced in #7761

  • official callback test
  • multiple official callbacks test
  • SD tests
  • SD Inpaint tests
  • SDXL tests
  • IP Adapter tests
  • SDXL Controlnet tests
  • SD Controlnet tests

Who can review?

@sayakpaul @yiyixuxu

@asomoza
Copy link
Member Author

asomoza commented May 13, 2024

@yiyixuxu @sayakpaul

I used the normal callback test as a guide, are this tests enough or should I add more?

Also for the 3 official callbacks we have right now, should I add test cases for the specific pipelines? What I mean is if we're going to test all the official callbacks implementations?

@@ -1808,6 +1809,77 @@ def callback_increase_guidance(pipe, i, t, callback_kwargs):
# accounts for models that modify the number of inference steps based on strength
assert pipe.guidance_scale == (inputs["guidance_scale"] + pipe.num_timesteps)

def test_official_callback(self):
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we just test the officially supported callback here?

Copy link
Member Author

@asomoza asomoza May 13, 2024

Choose a reason for hiding this comment

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

can I know here if the pipeline being tested is SD 1.5 or SDXL? Maybe I can check the pipeline class, but still, IMO is a bit inefficient since the official callbacks right now works for a limited number of pipelines.

Copy link
Member

Choose a reason for hiding this comment

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

Oh okay. So, IIUC, you're proposing not to add tests for the official callbacks then?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not quite, it's more like asking for guidance on how to do it following the rest of the code base, so maybe I'll split the questions:

  • Are we're going to make tests for all the official callbacks (I think there's going to be at least 10), some for IP Adapters, SD, SDXL and probably Pixart and SD3. So it's not that I was proposing not to add tests, just adding more context to make the decision.
  • For example, if I want to test the SDXL one, I didn't see any other test that checked the pipeline class. So what would be the best option for diffusers here? create only one test in StableDiffusionXLPipelineFastTests?, on all of them, create a mixin or just write it in the common one? This will be relevant also for the SD 1.5 but not for IP Adapters since they already have a mixin.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for providing the additional context. I think the following could work but please let me know your thoughts too:

Create something like

class IPAdapterTesterMixin:
as you proposed and only add to the pipelines that we know are supported with the official callbacks. I think it's perfectly fine to check against the pipeline class name. Or, we could add an instance variable to the pipeline tester class indicating if the official callback test suite should be run for them or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's what I would have done so I like it, I'll do the other tests then.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree here; we can make a mixin and add to relevant pipeline tests. I think we should at least test SD and SDXL-based pipelines, it will be nice to have more comprehensive coverage to include Kandinsky, pixart, cascade

we also need to figure out a way to find out which callback works with which pipelines

Here in my from_pipe tester mixin, I use this simple logic to figure out which ones are SD-based and which ones are SDXL based, https://github.com/huggingface/diffusers/blob/e0e8c58f64c024e89d125ddb563d0de4cf252dc1/tests/pipelines/test_pipelines_common.py#L626C9-L626C32

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.

Thanks! Maybe we just test the officially supported callbacks?

@asomoza
Copy link
Member Author

asomoza commented May 13, 2024

I'll do the kandinsky special test at the end which is the one failing.

@asomoza
Copy link
Member Author

asomoza commented May 16, 2024

While doing the tests I'm getting an error if I do the test with StableDiffusionInpaintPipeline

The error happens in this line:

latent_model_input = torch.cat([latent_model_input, mask, masked_image_latents], dim=1)

Since the SDCFGCutoffCallback makes the guidance_scale 0.0, I will also need to slice the mask and masked_image_latents but this only happens for this pipeline and the pix2pix one.

I think we have this options:

  • Create an official callback just for these pipelines
  • Skip the test for these pipelines

@sayakpaul @yiyixuxu WDYT?

Is there an alternative that I'm missing?

@sayakpaul
Copy link
Member

I think both the pipelines are important. So, I won't prefer skipping them. Having separate callbacks (Inpainting, Pix2Pix, etc.) seems like the best and cleanest way here. @yiyixuxu WDYT?

@yiyixuxu
Copy link
Collaborator

yiyixuxu commented May 16, 2024

@sayakpaul @asomoza
agree I don't think we should just skip but we can open that task for community!
so alternative is we can skip them for now and open an issue to ask the community to add these separate callbacks (like @sayakpaul did here #7677) , whichever way is easier for you:)

@yiyixuxu
Copy link
Collaborator

ohhhh another way is just handle this in the callbacks. I think you can actually combine the SD and SDXL callbacks with if "add_text_embeds" in callback_kwargs: ...

@yiyixuxu
Copy link
Collaborator

yeah I think try to make the callback work for all pipeline is better, this way it's easier for tests too

@asomoza
Copy link
Member Author

asomoza commented May 16, 2024

yeah, I'll try to do them all in this PR.

@asomoza
Copy link
Member Author

asomoza commented May 17, 2024

ohhhh another way is just handle this in the callbacks. I think you can actually combine the SD and SDXL callbacks with if "add_text_embeds" in callback_kwargs: ...

Now that I analyze this, for the add_text_embeds to be in callback_kwargs I need to add them to the tensor_inputs, but this errors if I add them to the list and aren't in the _callback_tensor_inputs

For this to work I would need to bypass that check and allow the use of any name in tensor_inputs for the official callbacks.

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


inputs = self.get_dummy_inputs(torch_device)
inputs["callback_on_step_end"] = test_callback
inputs["output_type"] = "latent"
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we just do "np" here? some of the pipelines does not support "latent" but they should all support "np"

Suggested change
inputs["output_type"] = "latent"
inputs["output_type"] = "np"

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.

left one comment - looks good to me overall!

@yiyixuxu yiyixuxu requested a review from DN6 May 29, 2024 00:11
@yiyixuxu
Copy link
Collaborator

@DN6 can you do a final review?

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

4 participants