Repository navigation
Conversation
In training mode the kernel zeroed the dropped elements but returned the kept ones unchanged. Multiply them by 1 / (1 - p), with the scale rounded to the input dtype first as ATen does.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25900
Note: Links to docs will display an error until the docs builds have been completed.
|
Contributor
Author
|
@pytorchbot label "release notes: ops & kernels" |
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.
Summary
In training mode the portable
native_dropout.outkernel zeroed the dropped elements but returned the kept ones unchanged, while ATen scales them by1 / (1 - p)(reproduction in #25899). This multiplies the kept elements by that scale, rounded to the input dtype first as eager does. For the same mask, kept elements then match eager exactly in all four floating dtypes. Dropped elements stay +0, as before, where eager can give -0 (negative input) or NaN (inf or NaN input, or a float16 scale that overflows whenpis above about 0.99998); I left that unchanged.Fixes #25899
Test plan
KeptElementsAreScaledinkernels/test/op_native_dropout_test.cppchecks, forp= 0.2, 0.25 and 0.5 and the four floating dtypes, that kept elements equal the input times the scale in the input dtype and dropped ones are zero. It failed before the change, andp= 0.25 also fails if the multiply uses an unrounded scale.From Python, for the four dtypes and
pin {0.2, 0.25, 0.5}, the runtime output equalsx * mask * dtype(1 / (1 - p))computed in eager on the returned mask, which is what eager'snative_dropoutcomputes.This PR was authored with the help of Claude Code (Anthropic); I reviewed and tested it.
cc @nil-is-all