Skip to content

Fix boolean operator precedence bugs in GeneratorLoss#4404

Closed
Mr-Neutr0n wants to merge 1 commit intocoqui-ai:devfrom
Mr-Neutr0n:fix/vocoder-loss-bugs
Closed

Fix boolean operator precedence bugs in GeneratorLoss#4404
Mr-Neutr0n wants to merge 1 commit intocoqui-ai:devfrom
Mr-Neutr0n:fix/vocoder-loss-bugs

Conversation

@Mr-Neutr0n
Copy link
Copy Markdown

Summary

  • Fix hinge loss guard: not scores_fake is not None was parsed as (not scores_fake) is not None due to Python operator precedence, which is always True — the hinge loss block ran unconditionally even when scores_fake was None, causing AttributeError at runtime.
  • Fix feature matching loss guard: not feats_fake is None was parsed as (not feats_fake) is None, which is always False — the feature matching loss was silently never applied.
  • Both conditions now use the idiomatic x is not None form, consistent with the existing MSE loss check on the preceding line.

Details

In TTS/vocoder/layers/losses.py, the GeneratorLoss.forward() method had two boolean expressions affected by Python operator precedence:

Line Before (buggy) Parsed as Result
295 not scores_fake is not None (not scores_fake) is not None Always True (bool is never None)
301 not feats_fake is None (not feats_fake) is None Always False (bool is never None)

The not unary operator binds more tightly than is / is not, so these expressions do not test what was intended.

After fix: both lines use scores_fake is not None and feats_fake is not None, matching the pattern already used for the MSE loss guard on line 289.

Test plan

  • Verify hinge GAN loss is now correctly computed when scores_fake is provided
  • Verify feature matching loss is now correctly applied when feats_fake is provided
  • Run existing vocoder tests: python -m pytest tests/vocoder_tests/

Fix two boolean logic errors in GeneratorLoss.forward() caused by
Python operator precedence:

1. `not scores_fake is not None` evaluated as
   `(not scores_fake) is not None`, which is always True since
   bool values are never None. This meant the hinge loss block
   ran unconditionally (even when scores_fake was None), causing
   AttributeError at runtime.

2. `not feats_fake is None` evaluated as
   `(not feats_fake) is None`, which is always False since bool
   values are never None. This meant the feature matching loss
   was silently never applied.

Both conditions now use the idiomatic `x is not None` form,
consistent with the existing MSE loss check on the preceding line.
@stale
Copy link
Copy Markdown

stale Bot commented Apr 18, 2026

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You might also look our discussion channels.

@stale stale Bot added the wontfix This will not be worked on but feel free to help. label Apr 18, 2026
@stale stale Bot closed this Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wontfix This will not be worked on but feel free to help.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants