feat(nn): implement stochastic masking in Dropout#867
Open
michalharakal wants to merge 1 commit into
Open
Conversation
|
📖 Documentation Preview The documentation has been built successfully for this PR. Generated Files:
Artifacts:
This comment will be updated automatically when the PR is updated. |
Dropout was an identity placeholder in both phases. It now applies inverted dropout under a training-phase context: each element is zeroed with probability p and survivors are scaled by 1/(1-p), so the expected activation is preserved and inference needs no rescaling. The mask is a constant tensor combined with an element-wise multiply, so gradients flow to surviving inputs without a dedicated autograd rule. An injectable Random enables reproducible masks. Identity paths stay in lang-core tests; value-level masking behavior is tested on the real CPU backend (the lang-core default context uses the shape-only Void ops). Closes #861
michalharakal
force-pushed
the
feature/861-dropout
branch
from
July 23, 2026 21:04
e97014c to
67431c8
Compare
|
📖 Documentation Preview The documentation has been built successfully for this PR. Generated Files:
Artifacts:
This comment will be updated automatically when the PR is updated. |
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.
Closes #861.
What
sk.ainet.lang.nn.layers.Dropoutwas an identity placeholder in both phases (its own KDoc said so). It now implements inverted dropout:ctx.inTraining,trainingflag,p > 0): each element is zeroed with probabilityp, survivors are scaled by1 / (1 - p)— expected activation preserved, no rescaling needed at inference.training = false, orp == 0): exact identity, as before.ops.multiply, so gradients flow to the surviving inputs only — standard dropout backward with no dedicated autograd rule.random: Random = Random.Default(defaulted, source-compatible) for reproducible masks.UnsupportedOperationException(mirrorsCrossEntropyLoss's float-only contract).Tests
DropoutTest,DropoutPhaseTest): identity paths now assert values, masked path asserts shape. Note: the lang-core default context runs on the shape-onlyVoidTensorOpsbackend (every op returns zeros), which is why the value-level assertions can't live there — and, incidentally, why the placeholder behavior was never caught.DropoutMaskingTest, new): every output element is0or1/(1-p)with both present; mean over 10k elements stays ≈ 1 (p = 0.3); seeded masks are bit-reproducible; eval phase is an exact identity.apiDump, android mirrored by hand — no Android SDK on this machine).Motivation
Any model using
Dropoutfor regularization currently trains without it, silently. Found while porting a GPT training pipeline (attention-weight dropout) to SKaiNET 0.36.0 — details in #861.