Skip to content
class

DropoutBackward

DropoutBackward

Python wrappers

Public Python APIs implemented by this engine symbols.

Autograd node for standard element-wise (inverted) dropout.

During training, each scalar element of the input is independently masked with probability p and surviving elements are rescaled by 1/(1−p)1 / (1 - p). The already-scaled mask is saved in mask_ so the backward needs only one multiply — no extra scaling step. When p == 0 or training == false the node is wired with an empty mask and apply clones grad_out unchanged.

Attributes

schema_v1OpSchema
Registered schema (name "dropout", version 1, AmpPolicy::KeepInput). Marked non-deterministic because the mask depends on the Generator state.
p_double
Drop probability used by the forward; stored for the backward. 0 indicates pass-through.
mask_Storage
The scaled Bernoulli mask m⋅1/(1−p)m \cdot 1/(1 - p) saved for backward. Empty when p_ == 0.

Static methods

1
static

forward

→TensorImplPtr
int forward(const int & a, double p, bool training, Generator * gen)

Sample the Bernoulli mask and apply inverted-dropout scaling.

Math

\dfrac{x_i}{1 - p} & \text{with probability } 1 - p\\[4pt] 0 & \text{with probability } p \end{cases}$$

Parameters

aTensorImplPtr
Input tensor of any shape.
pdouble
Drop probability in [0,1)[0, 1). Must be strictly less than 1 (probability 1 would zero everything and produce NaN under the 1/(1−p)1 / (1 - p) scaling).
trainingbool
If false, the forward is a pass-through.
Optional explicit RNG. nullptr selects the process-wide default_generator(); under deterministic mode the call raises if gen == nullptr and p > 0.

Returns

TensorImplPtr

Output tensor of the same shape and dtype as a.

Raises

LucidError
If p is outside [0,1)[0, 1), or under deterministic mode if no Generator is provided.

Methods

3
fn

apply

int apply(int grad_out)

Apply the saved mask to grad_out.

Returns {grad_out * mask_} when a mask is stored; otherwise (pass-through case) returns {clone(grad_out)}.

fn

apply_for_graph

int apply_for_graph(const int & grad_out)
fn

release_own_saved

void release_own_saved()