fix: use return value of torch.clamp for weight clamping - #4401
Closed
Mr-Neutr0n wants to merge 1 commit into
Closed
fix: use return value of torch.clamp for weight clamping#4401Mr-Neutr0n wants to merge 1 commit into
Mr-Neutr0n wants to merge 1 commit into
Conversation
torch.clamp() is not in-place and returns a new tensor. The previous code called torch.clamp(self.w, 1e-6) without using the return value, so the weight parameter was never actually clamped. This affected both GE2ELoss and AngleProtoLoss classes. Replace with self.w.data.clamp_(1e-6) which correctly clamps the parameter's data in-place.
Author
|
closing this out — saw the note about the repo being unmaintained. will redirect to the active fork if still relevant |
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
torch.clamp()is not in-place — it returns a new tensor. In bothGE2ELoss.forward()andAngleProtoLoss.forward()inTTS/encoder/losses.py, the calltorch.clamp(self.w, 1e-6)discards the return value, so the weight parameterself.wis never actually clamped to a minimum of1e-6.self.w.data.clamp_(1e-6)which correctly clamps the parameter's underlying data in-place, ensuring the weight scaling factor stays positive as intended.Details
The bug exists in two locations in
TTS/encoder/losses.py:GE2ELoss.forward()(line 115):AngleProtoLoss.forward()(line 159):Without this fix, if
self.wbecomes negative during training (via gradient updates), the cosine similarity matrix scaling would be inverted, potentially destabilizing speaker encoder training.Test plan
self.wstays non-negative during GE2E loss trainingself.wstays non-negative during AngleProto loss training