Skip to content

Scale the kept elements in portable native_dropout - #25900

Open
AxelNoun wants to merge 1 commit into
pytorch:mainfrom
AxelNoun:fix/et-t05-1-native-dropout-scale
Open

AxelNoun wants to merge 1 commit into
pytorch:mainfrom
AxelNoun:fix/et-t05-1-native-dropout-scale

Conversation

@AxelNoun

@AxelNoun AxelNoun commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

In training mode the portable native_dropout.out kernel zeroed the dropped elements but returned the kept ones unchanged, while ATen scales them by 1 / (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 when p is above about 0.99998); I left that unchanged.

Fixes #25899

Test plan

KeptElementsAreScaled in kernels/test/op_native_dropout_test.cpp checks, for p = 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, and p = 0.25 also fails if the multiply uses an unrounded scale.

cmake --build cmake-out --target portable_kernels_test
./cmake-out/kernels/test/portable_kernels_test --gtest_filter='OpNativeDropoutTest.*'   # 4 tests passed
ctest --output-on-failure                                                              # 90/90 passed

From Python, for the four dtypes and p in {0.2, 0.25, 0.5}, the runtime output equals x * mask * dtype(1 / (1 - p)) computed in eager on the returned mask, which is what eager's native_dropout computes.

This PR was authored with the help of Claude Code (Anthropic); I reviewed and tested it.

cc @nil-is-all

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.
@pytorch-bot

pytorch-bot Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

🔗 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.

⚠️ 18 Awaiting Approval

As of commit 3ffc913 with merge base f748232 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 1, 2026
@AxelNoun

AxelNoun commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: ops & kernels"

@pytorch-bot pytorch-bot Bot added the release notes: ops & kernels Changes to the opset and any new / changed kernel implementations label Dec 1, 2026
@executorch-triage executorch-triage Bot added the community: contribution PRs coming from community (excluding hardware partners) label Dec 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. community: contribution PRs coming from community (excluding hardware partners) release notes: ops & kernels Changes to the opset and any new / changed kernel implementations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

native_dropout does not scale the kept elements in training mode

1 participant