Skip to content

add index_counter to DPMSolverMultistepScheduler #4187

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

Closed
wants to merge 2 commits into from

Conversation

yiyixuxu
Copy link
Collaborator

fix:#4122

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jul 21, 2023

The documentation is not available anymore as the PR was closed or merged.

@patrickvonplaten
Copy link
Contributor

Looks nice!

1.) Could you maybe double-check that this is the correct implementation by running StableDiffusionImg2ImgPipeline with different strength values for SDv1-5? E.g. can you make sure that this code: #1866 (comment) works with your fix.
2.) Could you then propagate this fix also to all other schedulers that require this change (probs all k-diffusion ones expect DDIM, PNDM, DDPM)

@yiyixuxu
Copy link
Collaborator Author

yiyixuxu commented Jul 24, 2023

actually, this didn't work - going to understand the algorithm a little bit more, but currently, having duplicated timesteps, i.e. when we have this timestep is equal to the next (s0=s1 in below code), r0 will be 0, cause the inf values in the calculation

@yiyixuxu
Copy link
Collaborator Author

yiyixuxu commented Jul 25, 2023

@patrickvonplaten

I'm not too sure what to do here -

For this scheduler, the "step" calculation is still based on timesteps; so it won't work when there are duplicated timesteps( when more than one sigma points to the same timestep)
https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py#L486

Should we update the calculation to be based on sigmas?

@patrickvonplaten
Copy link
Contributor

Yes I think updating the computation to be based on sigmas is the move here. Let's just make sure our step(...) API doesn't change :-)

Also gently pinging @LuChengTHU here - do you have any thoughts here maybe?

@LuChengTHU
Copy link
Contributor

Hi all, it seems that this PR wants to fix the repeated time steps? But I'm not sure why the repeated time steps occurs, could you please explain the reason to me so that I could know the bugs in my code :) Thank you so much!

@yiyixuxu
Copy link
Collaborator Author

yiyixuxu commented Jul 26, 2023

@LuChengTHU

The repeated time steps only occurs when we use the sigmas for step size based on the k-diffusion paper. When we convert the sigma to timesteps, sometimes same timestep is mapped to more than one sigmas, hence the repeated timesteps

Basically, this is the part of the code responsible https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py#L269

We currently use a de-duplication logic to address the repeated timesteps, so if you run below code, you will get 95 steps, even though we asked for 100

from diffusers import DPMSolverMultistepScheduler

scheduler = DPMSolverMultistepScheduler(
    beta_start=0.00085,
    beta_end=0.012,
    beta_schedule="scaled_linear",
    prediction_type="epsilon",
    num_train_timesteps=1000,
    trained_betas=None,
    thresholding=False,
    algorithm_type="dpmsolver++",
    solver_type="midpoint",
    lower_order_final=True,
    use_karras_sigmas=True,
)

scheduler.set_timesteps(100, device="cuda")
print(len(scheduler.timesteps))

and this is the timesteps before the de-duplicate

 [999 992 985 978 971 963 956 948 940 933 924 916 908 899 891 882 873 864
 854 845 835 825 815 805 794 783 772 761 749 737 725 713 700 687 674 660
 646 632 618 603 587 572 556 540 523 506 489 472 454 436 418 400 382 364
 345 327 309 291 273 256 239 222 205 190 174 160 146 133 120 108  97  87
  78  69  61  53  47  41  35  31  26  23  19  16  14  12  10   8   7   6
   4   4   3   2   2   1   1   1   0   0]

@patrickvonplaten
Copy link
Contributor

@yiyixuxu let's maybe just give this a try to fix it and see later with design

@github-actions
Copy link
Contributor

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 Aug 31, 2023
@patrickvonplaten
Copy link
Contributor

@yiyixuxu let me know if you need help to get this one finished

@yiyixuxu yiyixuxu removed the stale Issues that haven't received updates label Sep 1, 2023
@yiyixuxu
Copy link
Collaborator Author

it's been worked on this PR #4986

@patrickvonplaten
Copy link
Contributor

Super-seeded by #4986

@yiyixuxu yiyixuxu deleted the add-index-counter branch July 14, 2024 19:28
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