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

[Scheduler] Move predict epsilon to init #1155

Merged
merged 7 commits into from Nov 8, 2022

Conversation

patrickvonplaten
Copy link
Contributor

@patrickvonplaten patrickvonplaten commented Nov 6, 2022

This PR cleans up the different implementations of predict_epsilon that we currently have.

@@ -190,10 +191,10 @@ def parse_args():
)

parser.add_argument(
"--predict_mode",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's try to align naming all over the codebase

@@ -220,9 +223,9 @@ def step(
model_output: torch.FloatTensor,
timestep: int,
sample: torch.FloatTensor,
predict_epsilon=True,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

predict_epsilon is an inherent config parameter just like beta_start that should not change during inference

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint.

@lukovnikov
Copy link
Contributor

i was wondering whether we should store this flag on the model because it's a characteristic of the model

Copy link
Member

@pcuenca pcuenca left a comment

Choose a reason for hiding this comment

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

Very nice! I left a very minor docstring suggestion and have two general comments:

  • How are we going to deal with additional objectives like v-prediction?
  • For the property name, I wonder if we should call it model_predicts_epsilon instead. It's probably not worthwhile changing, but it might be a more clear indication that this is something that has to be configured depending on the model being used, and does not really affect the scheduling per se.

src/diffusers/schedulers/scheduling_ddpm.py Outdated Show resolved Hide resolved
src/diffusers/schedulers/scheduling_ddpm.py Show resolved Hide resolved
src/diffusers/schedulers/scheduling_ddpm_flax.py Outdated Show resolved Hide resolved
Copy link
Contributor

@patil-suraj patil-suraj 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 !

@patil-suraj
Copy link
Contributor

i was wondering whether we should store this flag on the model because it's a characteristic of the model

The model actually doesn't know what it's predicting. It depends on what are computing the loss against (noise or x0) and most of the changes to handle x0 prediction need to be in the scheduler, so I think this should go in scheduler config as in this PR.

@patrickvonplaten
Copy link
Contributor Author

Regarding naming, I think model_predicts_epsilon is not a super nice fit for a scheduler config parameter - I'd try to disentangle a model and a scheduler as much as possible.

Maybe compute_epsilon is more accurate as there is no real prediction going on the scheduler, but on the other hand we will have predict_epsilon for training like we already have now, so I think it's best to align naming and stick to predict_epsilon .

Regarding general v-prediction I think we can just add it just like we've added it in DDPM.

Copy link
Member

@anton-l anton-l left a comment

Choose a reason for hiding this comment

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

Makes sense!

@patrickvonplaten patrickvonplaten merged commit 249d9bc into main Nov 8, 2022
@patrickvonplaten patrickvonplaten deleted the move_predict_eps_to_init branch November 8, 2022 17:08

if predict_epsilon is not None:
new_config = dict(self.scheduler.config)
new_config["predict_epsilon"] = predict_epsilon
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pcuenca note that now you should change this into:

new_config["prediction_type"] = "predict_epsilon"

Here and everywhere else

yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* [Scheduler] Move predict epsilon to init

* up

* uP

* uP

* Apply suggestions from code review

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>

* up

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
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

6 participants