Repository navigation
Preserve finite gradients when Smooth L1 beta is zero - #194
Open
Afloat (Afloat16) wants to merge 1 commit into
Open
Afloat (Afloat16) wants to merge 1 commit into
Afloat (Afloat16) wants to merge 1 commit into
Conversation
|
Afloat (@Afloat16) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
This branch has not been deployed
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.
With
beta=0, the currenttorch.wherecomputes the quadratic branch with a zero denominator even though the forward result selects L1. Backward can then produce NaN gradients, including for exact predictions.Use PyTorch's native Smooth L1 implementation, which defines the zero-beta L1 limit while preserving the existing positive-beta mean reduction.
Regression tests check zero-beta values and gradients (including all exact matches), and compare positive-beta values/gradients with an explicit piecewise oracle. Run
python -m unittest discover -s tests -p test_trellis2_smooth_l1_zero.py -v.Validation: native CPU regression tests pass on this branch; the same tests fail against the pinned original source. Validation run.
Exact-head validation: all 3 native CPU regression tests pass at
bda7c9bdc428167a5398a919abaf5441ae8079e4. Restoring the original production files at75fbf0183001ed9876c8dbb35de6b68552ee08bdmakes the same complete suite fail on the original behavior, with no skipped tests or import failures. Candidate and original-source logs.