Skip to content
fn

dropout

→Tensor
dropout(input: 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 input is independently zeroed with probability p and survivors are scaled by 1/(1−p)1 / (1 - p) so the expected activation magnitude stays unchanged. At inference (training=False) the call is a no-op identity.

Parameters

inputTensor
Input activations of any shape.
pfloat= 0.5
Drop probability in [0,1][0, 1]. p = 0 short-circuits to identity; p = 1 returns input * 0 in training. Default 0.5.
trainingbool= True
When False, returns input unchanged — identity at inference time. Modules built on top (nn.Dropout) pass self.training here. Default True.
inplacebool= False
If True, write the result into input and return input. Default False.

Returns

Tensor

Same shape and dtype as input.

Notes

For each element xix_i, draw an independent mi∼Bernoulli(1−p)m_i \sim \mathrm{Bernoulli}(1 - p) and apply

yi=mi1−p xi.y_i = \frac{m_i}{1 - p}\, x_i.

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.Module wrapper that owns the training flag.
  • dropout1d—whole-channel variants.
  • dropout2d—whole-channel variants.
  • dropout3d—whole-channel variants.
  • alpha_dropout—SELU-compatible dropout that preserves the
  • self-normalising statistics.

Used by 4