diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

Added get_velocity function to EulerDiscreteScheduler.

Open RuiningLi opened this issue 1 year ago • 15 comments

What does this PR do?

This PR adds the get_velocity function to EulerDiscreteScheduler, which is needed for training/fine-tuning with this scheduler if the prediction_type is v_prediction.

Fixes #6359

Before submitting

  • [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • [x] Did you read the contributor guideline?
  • [x] Did you read our philosophy doc (important for complex PRs)?
  • [ ] Was this discussed/approved via a GitHub issue or the forum? Please add a link to it if that's the case.
  • [ ] Did you make sure to update the documentation with your changes? Here are the documentation guidelines, and here are tips on formatting docstrings.
  • [ ] Did you write any new necessary tests?

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

RuiningLi avatar Apr 21 '24 13:04 RuiningLi

cc @yiyixuxu could you take a look here please.

DN6 avatar Apr 22 '24 08:04 DN6

@RuiningLi I don't understand how this is related to https://github.com/huggingface/diffusers/pull/6395 ?

Fixes https://github.com/huggingface/diffusers/pull/6395

yiyixuxu avatar Apr 22 '24 20:04 yiyixuxu

@RuiningLi I don't understand how this is related to #6395 ?

Fixes #6395

Sorry, I meant #6359 .

RuiningLi avatar Apr 22 '24 20:04 RuiningLi

thanks! I would like to understand the use case a little bit more Why do you need to use EulerDiscreteScheduler for training?

yiyixuxu avatar Apr 22 '24 20:04 yiyixuxu

thanks! I would like to understand the use case a little bit more Why do you need to use EulerDiscreteScheduler for training?

Stable Video Diffusion by default uses EulerDiscreteScheduler, so it would be nice to keep it consistent if we fine-tune the model.

RuiningLi avatar Apr 22 '24 21:04 RuiningLi

@RuiningLi we normally use DDPM for training regardless of which scheduler it uses for inference by default

I don't think we have a training script for SVD, do we?

yiyixuxu avatar Apr 23 '24 00:04 yiyixuxu

@yiyixuxu Not yet. Also, SVD itself uses EulerDiscreteScheduler for fine-tuning, and it also uses a continuous sigma sampler rather than a discrete one.

RuiningLi avatar Apr 23 '24 08:04 RuiningLi

EulerDiscreteScheduler is used by internal training done by HuggingFace, for example, the SDXL ControlNet models were trained with --use_euler, but this means you can't train v-prediction models with that.. because the scheduler.get_velocity() is used if prediction_type == "v_prediction"

bghira avatar Apr 25 '24 13:04 bghira

EulerDiscreteScheduler is used by internal training done by HuggingFace, for example, the SDXL ControlNet models were trained with --use_euler, but this means you can't train v-prediction models with that.. because the scheduler.get_velocity() is used if prediction_type == "v_prediction"

What do you mean exactly? If Huggingface internally use this scheduler to train, why does it prevent from having the get_velocity function?

RuiningLi avatar Apr 25 '24 16:04 RuiningLi

that's not the point i was making, they use it internally on epsilon prediction models. it's just that training on Euler isn't unordinary and it's even done inside HF itself. so supporting it in trainers doesn't seem unusual, either. it will unify the internal and example scripts. but this is required to merge before that can be done.

bghira avatar Apr 25 '24 16:04 bghira

that's not the point i was making, they use it internally on epsilon prediction models. it's just that training on Euler isn't unordinary and it's even done inside HF itself. so supporting it in trainers doesn't seem unusual, either. it will unify the internal and example scripts. but this is required to merge before that can be done.

So do you mean that we need to first get this PR merged before we can have example training code for Euler v_prediction? If that is what you meant, then I agree with you!

RuiningLi avatar Apr 25 '24 16:04 RuiningLi

I'm ok with adding this if there is a use case in training for it @sayakpaul what do you think?

yiyixuxu avatar Apr 25 '24 19:04 yiyixuxu

Yes, indeed. This is an important thing to support as we move more and more to Karras-style training. IMO, we should support it.

sayakpaul avatar Apr 26 '24 14:04 sayakpaul

Good for me to merge once the test cases pass. For the quality tests, I think the error messages on the CI should be helpful.

sayakpaul avatar Apr 26 '24 14:04 sayakpaul

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.