Fix three bugs in vocoder loss computation#797
Open
Mr-Neutr0n wants to merge 1 commit intomozilla:masterfrom
Open
Fix three bugs in vocoder loss computation#797Mr-Neutr0n wants to merge 1 commit intomozilla:masterfrom
Mr-Neutr0n wants to merge 1 commit intomozilla:masterfrom
Conversation
1. Boolean logic error in GeneratorLoss.forward(): the condition `if self.use_hinge_gan_loss and not scores_fake is not None` evaluates as `(not scores_fake) is not None` due to operator precedence, which is always True. This caused the hinge loss block to execute even when scores_fake was None. Fixed to `and scores_fake is not None`. Applied same fix to the feat_match_loss guard which had an analogous issue. 2. Variable shadowing in _apply_D_loss(): the loop unpacking `total_loss, real_loss, fake_loss = loss_func(...)` shadows the accumulator variables real_loss and fake_loss, so `real_loss += real_loss` just doubles the current iteration's value instead of accumulating across scales. Renamed the unpacked variables to cur_real_loss and cur_fake_loss. 3. Feature loss normalization in MelganFeatureLoss.forward(): `loss_feats /= len(fake_feats) + len(real_feats)` divides by 2N instead of N since both lists have the same length. The loss is summed over N pairs, so the denominator should be N. Fixed to `loss_feats /= len(fake_feats)`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes three bugs in
TTS/vocoder/layers/losses.pythat cause incorrect loss values during vocoder training:Boolean logic error in
GeneratorLoss.forward(): The conditionif self.use_hinge_gan_loss and not scores_fake is not Noneevaluates as(not scores_fake) is not Nonedue to Python operator precedence, which is alwaysTrue. This caused the hinge loss block to execute even whenscores_fakewasNone, leading to a runtime error. Fixed toand scores_fake is not None. Applied the same fix to thefeat_match_lossguard which had an analogous issue (and not feats_fake:is falsy for empty lists).Variable shadowing in
_apply_D_loss(): The loop unpackingtotal_loss, real_loss, fake_loss = loss_func(...)shadows the accumulator variablesreal_lossandfake_lossinitialized above. As a result,real_loss += real_lossjust doubles the current iteration's value instead of accumulating across discriminator scales. Renamed the unpacked variables tocur_real_lossandcur_fake_loss.Feature loss normalization in
MelganFeatureLoss.forward():loss_feats /= len(fake_feats) + len(real_feats)divides by2Ninstead ofN, since both feature lists have the same length. The loss is summed overNpairs, so the denominator should beN. Fixed toloss_feats /= len(fake_feats).Test plan
use_hinge_gan_loss=Trueandscores_fakeis provideduse_feat_match_loss=Trueandfeats_fakeis provided_apply_D_losscorrectly accumulatesreal_lossandfake_lossacross multiple discriminator scalesMelganFeatureLossreturns correctly normalized loss values