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

Fix min-snr-gamma for v-prediction and ZSNR. #934

Merged
merged 1 commit into from
Nov 25, 2023

Conversation

feffy380
Copy link
Contributor

@feffy380 feffy380 commented Nov 7, 2023

Based on the discussion in #673
Matches the reference implementation from the paper's author.

Note: With this PR, you should use --min_snr_gamma without --scale_v_pred_loss_like_noise_pred

The old implementation with apply_snr_weight and scale_v_prediction_loss_like_noise_prediction splits the calculation into two steps:

loss *= min(snr, gamma) / snr
loss *= snr / (snr+1)

The problem here is that with --zero_terminal_snr it is possible for the first step to divide by zero.
This PR simplifies the weight calculation to min(snr, gamma)/(snr+1) to avoid dividing by zero.
This makes scale_v_prediction_loss_like_noise_prediction unnecessary, but I did not remove it yet to avoid breaking existing workflows and GUIs. Maybe a deprecation notice should be added to it?

This fixes min-snr for vpred+zsnr by dividing directly by SNR+1.
The old implementation did it in two steps: (min-snr/snr) * (snr/(snr+1)), which causes division by zero when combined with --zero_terminal_snr
@kohya-ss
Copy link
Owner

Thank you for this! I didn't fully catch the discussion in the issue, but I believe this works fine. I will merge this sooner. Sorry for waiting a long time.

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.

2 participants