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

Modify FlowMatch Scale Noise #8678

Merged
merged 4 commits into from
Jun 27, 2024

Conversation

asomoza
Copy link
Member

@asomoza asomoza commented Jun 24, 2024

What does this PR do?

This PR modifies FlowMatchEulerDiscreteScheduler so it can work with differential diffusion, also fixes StableDiffusion3Img2ImgPipeline to work with the new change.

I just made it analogous the other schedulers, but I found that there's a tiny change in the image to image generation, so I don't know if there's something wrong with what I did.

before after
20240623184339_1860560239 20240624032018_1860560239

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.

@yiyixuxu

@asomoza asomoza requested a review from yiyixuxu June 24, 2024 07:56
@asomoza asomoza changed the title initial fix FlowMatch Scale Noise Jun 24, 2024
@asomoza asomoza changed the title FlowMatch Scale Noise [Fix] FlowMatch Scale Noise Jun 24, 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.

@@ -852,7 +852,7 @@ def __call__(
# 4. Prepare timesteps
timesteps, num_inference_steps = retrieve_timesteps(self.scheduler, num_inference_steps, device, timesteps)
timesteps, num_inference_steps = self.get_timesteps(num_inference_steps, strength, device)
latent_timestep = timesteps[:1].repeat(batch_size * num_inference_steps)
latent_timestep = timesteps[:1].repeat(batch_size * num_images_per_prompt)
Copy link
Collaborator

Choose a reason for hiding this comment

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

😱😱😱😱
thanks for the fix!

@asomoza
Copy link
Member Author

asomoza commented Jun 26, 2024

@yiyixuxu

I copied the almost the same logic than the EulerDiscreteScheduler as suggested, LMK if you want me to make it simpler with just with what diff-diff needs or if it's ok like this.

@asomoza asomoza changed the title [Fix] FlowMatch Scale Noise Modify FlowMatch Scale Noise Jun 26, 2024
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.

looks good to me! left one more comment and let's run slow test for sd3 img2img to make sure it works

@@ -129,7 +129,31 @@ def scale_noise(
if self.step_index is None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can also remove this here

Let's remove it and run the example for img2img to see if the results match from main and this branch

@asomoza
Copy link
Member Author

asomoza commented Jun 27, 2024

Slow test fails for me with this branch but also with main:

This branch:
AssertionError: Outputs are not close enough, got [[0.55029297 0.47314453 0.578125 ]

Main:
AssertionError: Outputs are not close enough, got [[0.55029297 0.47314453 0.578125 ]

But I can tell that at least the slices are the same in both, probably something with my env?

I also get the same results than the initial comment, the pear has a tiny difference but mostly the same (they're identical with the latest changes and from the initial commit for each branch though)

main this branch
20240626223910_1860560239 20240626223948_1860560239

Should I look into what's making the difference between them? Or this is negligible?

Edit: I forgot, probably the visual difference is because of the fix in the pipeline

@yiyixuxu
Copy link
Collaborator

the test look good! since you got same results from main and branch
let's merge :)

@yiyixuxu
Copy link
Collaborator

Should I look into what's making the difference between them? Or this is negligible?
Edit: I forgot, probably the visual difference is because of the fix in the pipeline

I don't think the fix in the pipeline will affect the output, but I can't tell the difference, and the test slice is the same so I think we are fine

@yiyixuxu
Copy link
Collaborator

ohh wait a second .... let's not merge just yet

@yiyixuxu
Copy link
Collaborator

where is the difference in the image?

@asomoza
Copy link
Member Author

asomoza commented Jun 27, 2024

you can open each one in a different tab and circle between them. The pear is a little bigger to the left and the stem is also a little higher

@asomoza
Copy link
Member Author

asomoza commented Jun 27, 2024

pear.mp4

if self.step_index is None:
self._init_step_index(timestep)
# Make sure sigmas and timesteps have the same device and dtype as original_samples
sigmas = self.sigmas.to(device=sample.device, dtype=sample.dtype)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the difference comes from casting simgas dtype
do you think the quality is worse when we cast the sigmas to fp16? (this branch)

Copy link
Member Author

@asomoza asomoza Jun 27, 2024

Choose a reason for hiding this comment

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

no, IMO is not worse, probably if I didn't use an example with a single fruit against a black background, I wouldn’t have even noticed the difference.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok let's merge then :)

@asomoza asomoza merged commit 3b01d72 into huggingface:main Jun 27, 2024
15 checks passed
@asomoza asomoza deleted the fix-flow-match-scale-noise branch June 27, 2024 04:36
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

3 participants