Skip to content
fn

leaky_relu

→Tensor
leaky_relu(input: Tensor, negative_slope: float = 0.01, inplace: bool = False)

Implementing kernel

C++ engine symbols that back this Python API.

Leaky rectified linear unit activation.

A simple modification of relu that lets a small, non-zero gradient pass through for negative inputs. This avoids the dying ReLU problem where neurons stuck on the negative side stop updating because their gradient is exactly zero.

Parameters

inputTensor
Input tensor of any shape; activation is applied element-wise.
negative_slopefloat= 0.01
Slope α\alpha of the linear branch for negative inputs. Default 0.01.
inplacebool= False
If True, write the result into input and return input.

Returns

Tensor

Activated tensor with the same shape as input.

Notes

LeakyReLU(x)=max⁡(0,x)+αmin⁡(0,x)\text{LeakyReLU}(x) = \max(0, x) + \alpha \min(0, x)

The derivative is 11 for x>0x > 0 and α\alpha for x≤0x \le 0. Unlike relu, the derivative is everywhere non-zero (assuming α≠0\alpha \ne 0), so gradient signal continues to flow through inactive units. Use Leaky ReLU when ReLU networks are showing many permanently dead neurons; for a learnable slope, see prelu.

Examples

>>> import lucid
>>> from lucid.nn.functional import leaky_relu
>>> x = lucid.tensor([-2.0, -1.0, 0.0, 1.0])
>>> leaky_relu(x, negative_slope=0.1)
tensor([-0.2, -0.1, 0., 1.])

Used by 2