Skip to content

Conversation

@bghira
Copy link
Contributor

@bghira bghira commented Sep 19, 2023

What does this PR do?

Flooring the SNR weights to 1 results in a solution for the Inf position that arises with a zero-terminal SNR model.

As such, we can safely remove this check and the parameter can be even used by default with the value of 5.

Before submitting

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.

@bghira
Copy link
Contributor Author

bghira commented Sep 19, 2023

the first curve is a normal loss calc. and then, followed by using snr gamma value of 5 while training v_prediction and zero-terminal SNR SDXL:

image

i've now trained with this for about 6,000 steps and it's great. works very well.

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.

Good to merge when the comments are addressed.

Thanks for spotting and fixing.

…ut the application of the epsilon code to sample prediction
@bghira
Copy link
Contributor Author

bghira commented Sep 19, 2023

@sayakpaul thanks. done

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.

Much better readability now. Thanks much!

@sayakpaul
Copy link
Member

Let's fix the code quality issues here.

@bghira
Copy link
Contributor Author

bghira commented Sep 19, 2023

@sayakpaul ah, i'm used to pre-commit hooks doing this for me :D done

@sayakpaul
Copy link
Member

Failing tests are flaky!

@sayakpaul sayakpaul merged commit 74e43a4 into huggingface:main Sep 19, 2023

if noise_scheduler.config.prediction_type == "v_prediction":
# Velocity objective needs to be floored to an SNR weight of one.
mse_loss_weights = base_weight + 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't we do:

mse_loss_weights = max(base_weight, 1) 

if we want to "floor" the SNR weight?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

max would be ceil, here we're just adding one to ensure a value of zero is a minimum of 1. we don't want to blindly overwrite minimal values with 1's, we want to scale all of them.

Copy link
Contributor

Choose a reason for hiding this comment

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

mse_loss_weights = max(base_weight, 1) in that case works more like floor - e.g. mse_loos_weights is equal to at least 1 or higher.

Can you explain in a bit more detail why we want to add 1 here all the time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

certainly. when using v-prediction, there is an infinite SNR at the final timestep. if you do not floor the weight of this to 1, it will lead to a NaN loss value and the model fails to produce useable predictions.

this was observed in the original min-SNR paper, and has since been implemented in the reference code upstream.

AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
…uggingface#5096)

* Resolve v_prediction issue for min-SNR gamma weighted loss function

* Combine MSE loss calculation of epsilon and velocity, with a note about the application of the epsilon code to sample prediction

* style

---------

Co-authored-by: bghira <bghira@users.github.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
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.

3 participants