Skip to content
class

DropPathBackward

DropPathBackward

Autograd node for DropPath — per-sample stochastic depth (Huang, Sun, Liu & Weinberger 2016) used in residual / transformer blocks.

A single Bernoulli value is drawn per sample (mask shape (N,1,1,…)(N, 1, 1, \ldots)) and broadcast over every other dimension, so either the entire residual contribution of a sample survives or it is killed entirely. When scale_by_keep is true the surviving samples are pre-scaled by 1/(1−p)1 / (1 - p) so that the expectation of the residual branch matches a deterministic forward.

Attributes

schema_v1OpSchema
Registered schema (name "drop_path", version 1, AmpPolicy::KeepInput).
mask_Storage
Per-sample mask broadcast to the full input shape; saved for the backward.

Static methods

1
static

forward

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

Apply per-sample stochastic depth.

Parameters

aTensorImplPtr
Input tensor of any rank ≥1\geq 1; the first axis is the batch axis.
pdouble
Drop probability in [0,1)[0, 1).
scale_by_keepbool
If true, surviving samples are multiplied by 1/(1−p)1 / (1 - p) to preserve the expectation of the residual branch.
Optional RNG (see DropoutBackward).

Returns

TensorImplPtr

Output tensor with the same shape as a.

Raises

LucidError
If p is outside [0,1)[0, 1) or deterministic mode is on without a Generator.

Methods

3
fn

apply

int apply(int grad_out)

Backward: multiply grad_out by the saved per-sample mask.

fn

apply_for_graph

int apply_for_graph(const int & grad_out)
fn

release_own_saved

void release_own_saved()