dropout(x: Tensor, p: float = 0.5, training: bool = True, inplace: bool = False)Implementing kernel
C++ engine symbols that back this Python API.Element-wise Bernoulli dropout — the canonical Srivastava 2014 form.
During training, each scalar in x is independently zeroed with
probability p and survivors are scaled by
so the expected activation magnitude stays unchanged. At inference
(training=False) the call is a no-op identity.
Parameters
pfloat= 0.5p = 0 short-circuits
to identity. Default 0.5.trainingbool= TrueFalse, returns x unchanged — identity at
inference time. Modules built on top (nn.Dropout) pass
self.training here. Default True.inplacebool= Falsenn.dropout always returns a fresh tensor. Default False.Returns
TensorSame shape and dtype as x.
Notes
For each element , draw an independent and apply
Backward uses the same saved mask, so gradients also propagate
only through surviving positions. For correlated activations
(sequence / image channels) prefer dropout1d /
dropout2d / dropout3d, which drop whole feature
maps and give stronger regularisation.
Compile path routing. When called inside a
lucid.compile._tracing context with training=True and
p > 0, this wrapper allocates a Philox state buffer and routes
through the sibling engine op _C_engine.nn.dropout_stateful.
The captured trace then carries the 2-input/2-output schema the
compile path needs to plumb MPSGraph's stateful Philox RNG —
giving genuinely-per-dispatch varying masks where the stateless
seed path produces dispatch-deterministic ones. Eager-only
callers (no active tracer) keep using the standard nn.dropout.
.. [1] Srivastava et al., Dropout: A Simple Way to Prevent Neural Networks from Overfitting, JMLR 2014.
Examples
>>> import lucid
>>> from lucid.nn.functional import dropout
>>> x = lucid.ones(2, 4)
>>> y = dropout(x, p=0.5, training=True)
>>> # ~50 % of entries are 0; survivors are 2.0 (= 1 / (1 - 0.5))See Also
- lucid.nn.Dropout—
nn.Modulewrapper that owns thetrainingflag. dropout1d—whole-channel variants.dropout2d—whole-channel variants.dropout3d—whole-channel variants.alpha_dropout—SELU-compatible dropout that preserves theself-normalising statistics.