Repository navigation
Normalize smoothed KL mean by non-padding targets - #3115
Open
kocean9-freedom wants to merge 1 commit into
Open
kocean9-freedom wants to merge 1 commit into
kocean9-freedom wants to merge 1 commit into
Conversation
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.
What does this PR do?
Fix the
meanreduction inkldiv_losswhen label smoothing is enabled. It currently runsloss.sum().mean(), so it returns a sum. Duplicating a batch increases the supposedly averaged loss and gradients. The unsmoothed path uses an actual token mean. The small-smoothing limit is checked on unpadded inputs; the existing difference between its length mask and the smoothed path'spad_idxmask is outside this change.Divide the summed KL divergence by the number of non-
pad_idxtargets. Keep all-padding input at zero, and document this reduction explicitly. The smoothing distribution,sum,batchmean,batch, and existing length handling are unchanged. Behavior change: smoothedmeanvalues and gradients are now normalized; callers relying on the old sum should requestsumexplicitly. The bundled LibriSpeech Transformer configuration usesbatchmeanand retains its behavior.On two bundled speech samples through the existing MFCC/CRDNN/attention ASR example, 60 valid target tokens produce a loss of 153.60635 before and 2.56011 after, matching an independent
torch.distributionsKL reference. With the fix, one publicBrain.fit_batchSGD step matches independently calculated updates for all 31 trainable parameters on CPU and MPS. This validates loss scaling, not recognition accuracy.Validation (Python 3.12.14, torch/torchaudio 2.10.0, macOS arm64):
test_fallback_when_all_failassumesos.sched_getaffinity, andtest_run_shellassumes shellecho -nbehavior.ASR_seq2seqintegration test passed. All configured pre-commit hooks passed. Built sdist/wheel with the declared setuptools backend; the extracted wheel passed the same real-audio CPU training-step check.CUDA, large-scale training, and online model tests were not run. AI assistance: implementation, tests, validation, review, and PR preparation used OpenAI Codex; no independent human review is claimed.
Before submitting
PR review
Reviewer checklist