Dropout (deterministic spec) #
Dropout is traditionally randomized: each element is kept with probability keep = 1 - p.
In this repository we often want a deterministic spec that still documents the intended meaning,
so downstream models can choose explicit inference-time or mask-driven dropout semantics.
We therefore expose two deterministic variants:
dropoutInferenceSpec p x = x, matching evaluation mode for inverted dropout.dropoutMaskedSpec p mask xA fully deterministic "training-style" dropout that takes the mask explicitly. We use safe scaling bymax(keep, ε)so it is always defined even ifp ≈ 1.
How this differs from PyTorch:
torch.nn.Dropout(p)uses inverted dropout during training:y = mask * x / (1 - p), and becomes identity during evaluation (y = x).- The spec layer here avoids randomness. If you want something close to PyTorch training
semantics,
use
dropoutMaskedSpecand pass the mask explicitly. For evaluation semantics, usedropoutInferenceSpec.
Gradients:
- We treat
pandmaskas non-differentiable inputs. The backward specs only return the gradient with respect tox.
Deterministic training-style dropout with an explicit mask.
If mask[i] = true, keep element x[i], otherwise drop it to 0.
We use inverted-dropout scaling x / keepSafe with keepSafe = max(1 - p, ε).
Instances For
Backward/VJP for dropoutMaskedSpec with respect to x.
This mirrors the forward: gradients are masked and (in the kept positions) scaled by 1/keepSafe.