Deep LearningActivation Functions and Comparisons

How do Leaky ReLU and PReLU differ in handling negative activations?

Question 307 of 314 · Updated

On this page

Leaky ReLU uses a fixed negative-side slope; PReLU learns that slope during training. Both preserve a small gradient for negative inputs, unlike ordinary ReLU, which outputs zero for every negative input. The difference is whether the negative slope is a hyperparameter you choose or a parameter the network learns from data.

  • Leaky ReLU: (f(x)=x) for (xgeq0), otherwise (f(x)=alpha x), where (alpha) is fixed (commonly 0.01).
  • PReLU: uses the same piecewise function, but (alpha) is a learnable parameter, shared across the layer or learned separately per channel.

The choice is a trade-off between simplicity and adaptivity. PReLU can learn a useful negative slope, but adds parameters and a little optimization complexity. Leaky ReLU is deterministic, inexpensive, and often a strong baseline.

1. Why do we need a negative slope?#

A neural network repeatedly applies linear transformations and nonlinear activation functions. The activation function controls which information and gradients can flow through the network.

The standard ReLU function is:

ReLU(x)=max(0,x)

For positive inputs, ReLU returns the input. For negative inputs, it returns zero.

Consider these values:

Input xReLU output
-40
-20
-10
00
11
33

For a negative input, the local gradient is zero. If a neuron remains in the negative region for all examples it receives, its gradient through that activation can remain zero. This is commonly called the dying ReLU problem.

Leaky ReLU and PReLU address this by allowing a small, non-zero slope on the negative side.

2. What is Leaky ReLU?#

Leaky ReLU is defined as:

f(x)=\begin{cases}x,&x\geq0\\\alpha x,&x<0\end{cases}

Here, (alpha) is a fixed negative slope selected by the practitioner. A commonly used default is 0.01.

An equivalent expression is:

LaTeX

Numerical example#

Let .

Input xCalculationOutput
-40.1 × -4-0.4
-20.1 × -2-0.2
-10.1 × -1-0.1
000
222
444

Notice that negative inputs are not discarded. They are scaled by a small factor.

For example, if a neuron produces -3 and the negative slope is 0.1, Leaky ReLU outputs -0.3 instead of zero.

The slope is fixed during training. Backpropagation updates the network's ordinary weights, but does not learn this Leaky ReLU slope.

3. What is PReLU?#

PReLU stands for Parametric Rectified Linear Unit. It uses the same piecewise shape, but the negative slope is a learnable parameter.

f(x)=\begin{cases}x,&x\geq0\\ax,&x<0\end{cases}

The parameter a is learned through backpropagation along with the other network parameters.

Equivalent form:

f(x)=max(0,x)+a min(0,x)

Numerical example#

Suppose PReLU starts with a=0.25.

Input xCalculationOutput
-40.25 × -4-1.00
-20.25 × -2-0.50
-10.25 × -1-0.25
000
222
444

During training, gradient descent may update a from 0.25 to 0.18, 0.12, or another value, depending on the task and gradients.

For example, if the learned value becomes 0.05, an input of -4 produces -0.2. If it becomes 0.4, the same input produces -1.6.

The model adapts how much negative information should pass through the activation.

4. Leaky ReLU vs PReLU: key differences#

DimensionLeaky ReLUPReLU
Full nameLeaky Rectified Linear UnitParametric Rectified Linear Unit
Negative slopeFixedLearnable
Slope notationαa
Typical starting/default value0.01 in PyTorch0.25 in PyTorch
Gradient for negative xFixed αLearned a
Additional trainable parametersNone for activation slopeOne or one per channel
Adaptation to dataNoYes
Implementation complexityLowerSlightly higher
Overfitting/regularization concernNo slope parametersSlope parameters can be affected by regularization
Compute overheadVery smallVery small, plus parameter-gradient updates
Good starting pointStrong simple baselineWhen adaptive negative slopes are worth testing

Both functions preserve the input shape and are piecewise linear. Both have a non-zero negative-side gradient when their negative slope is non-zero.

5. What are the gradients?#

Gradients explain why these activations can help optimization.

Leaky ReLU gradient#

For x>0:

df/dx=1

For x<0:

LaTeX

At exactly zero, the derivative is not uniquely defined mathematically; implementations choose a subgradient convention.

If , the gradient passed through a negative activation is 0.1 instead of zero.

PReLU gradient#

For x>0:

df/dx=1

For x<0:

df/dx=a

The activation also has a gradient with respect to its learnable parameter:

df/da=\begin{cases}0,&x\geq0\\x,&x<0\end{cases}

The parameter's gradient over a batch and feature map is accumulated from the loss gradient:

\frac{\partial L}{\partial a}=\sum_i \frac{\partial L}{\partial f(x_i)}\frac{\partial f(x_i)}{\partial a}

Only negative inputs contribute directly to the slope parameter's gradient.

A small gradient example#

Assume a negative input x=-2, and the upstream gradient from the next layer is .

For Leaky ReLU with :

\frac{\partial L}{\partial x}=3\times0.1=0.3

For PReLU with a=0.25:

\frac{\partial L}{\partial x}=3\times0.25=0.75

The PReLU slope parameter also receives:

\frac{\partial L}{\partial a}=3\times(-2)=-6

The optimizer can use this parameter gradient to update a. The actual update depends on the optimizer, learning rate, accumulated gradients, and other training details.

6. How does PReLU learn its negative slope?#

PReLU's slope is optimized jointly with the rest of the network.

A simplified gradient descent update is:

a_{new}=a_{old}-η\frac{\partial L}{\partial a}

where is the learning rate.

Suppose:

  • Initial slope: 0.25
  • Learning rate: 0.01
  • Gradient for the slope: -2

Then:

a_{new}=0.25-(0.01\times-2)=0.27

The slope increases from 0.25 to 0.27.

This is only a one-step illustration. Real training uses gradients aggregated across examples and may use momentum, Adam, or another optimizer.

Shared versus channel-wise parameters#

PReLU can learn:

  1. One shared parameter: One slope for all channels in a layer.
  2. One parameter per channel: Each channel learns its own negative slope.

For a convolutional layer with 64 output channels:

  • Shared PReLU: 1 additional parameter.
  • Channel-wise PReLU: 64 additional parameters.

This is a small number compared with the weights in most convolutional layers, but the correct choice depends on architecture and data.

7. Initialization: how should the slope start?#

Initialization matters because it determines the initial activation behavior and gradient flow.

  • PyTorch nn.LeakyReLU defaults to a negative slope of 0.01.
  • PyTorch nn.PReLU defaults to an initial learnable slope of 0.25.
  • The original PReLU work used 0.25 as its initialization in its experiments.

A PReLU initial value is not a fixed final value. It is only the starting point for optimization.

He/Kaiming initialization#

For rectifier activations, Kaiming initialization helps preserve signal variance through layers.

For a Leaky ReLU with negative slope , a commonly used gain is:

gain=\sqrt{\frac{2}{1+α^2}}

The corresponding weight initialization standard deviation in fan-in mode is:

std=\frac{gain}{\sqrt{fan\_in}}

In PyTorch, the initialization API supports a negative slope parameter for Leaky ReLU:

PYTHON
import torch.nn as nn layer = nn.Linear(128, 64) nn.init.kaiming_normal_( layer.weight, a=0.1, mode="fan_in", nonlinearity="leaky_relu" )

Do not assume that a particular Kaiming setting is automatically optimal for every PReLU model. The activation's learned slope can change during training, so validate initialization choices for the architecture and training setup.

8. How do they address the dying ReLU problem?#

With ordinary ReLU, a negative input produces zero output and zero local gradient. A neuron that receives only negative pre-activation values can stop receiving useful gradient through that activation.

Leaky ReLU changes the negative-side derivative from zero to a small fixed value. PReLU changes it to a learned value.

Example for input x=-5:

ActivationNegative-side slopeOutputLocal gradient
ReLU000
Leaky ReLU0.01-0.050.01
PReLU0.25-1.250.25

Both alternatives can help keep gradient flow alive for negative activations. However, they do not guarantee that a network cannot suffer from optimization problems or inactive features. Very small slopes still pass very small gradients, and other causes of poor gradient flow remain possible.

9. Computational cost and parameter overhead#

Leaky ReLU#

  • One piecewise operation per element.
  • No trainable activation parameter.
  • No parameter-gradient calculation for the slope.
  • Minimal memory overhead.

PReLU#

  • Similar piecewise forward operation.
  • Stores one or multiple slope parameters.
  • Computes gradients for those parameters.
  • Updates them through the optimizer.
  • Adds a small amount of optimizer state when using optimizers such as Adam.

For most modern networks, the arithmetic overhead is small compared with convolution or matrix multiplication. But the parameter and optimizer-state overhead is not literally zero.

The original PReLU paper describes the added computation as negligible in its experiments. Actual impact depends on model shape, hardware, kernel implementation, and deployment constraints.

10. Where are they used?#

CNNs and computer vision#

PReLU was studied in deep convolutional networks for image classification. Channel-wise slopes can adapt to different feature channels.

Leaky ReLU is also used in CNNs where a simple non-zero negative slope is desirable.

GANs#

Leaky ReLU has been widely used in GAN discriminator architectures. It can provide a non-zero gradient for negative discriminator activations.

This does not mean every GAN must use Leaky ReLU. Architecture, normalization, loss, and training stability all matter.

MLPs and dense networks#

Both can be used in fully connected networks. Leaky ReLU is often a straightforward baseline. PReLU is worth testing if a learnable negative response may improve fitting.

Other architectures#

They can be used wherever a piecewise-linear activation is suitable, including some encoder, decoder, and feature-extraction networks. They are not automatically preferable to GELU, SiLU, ReLU, or other activations in Transformers or modern architectures.

11. PyTorch implementations#

A. Leaky ReLU with a fixed slope#

PYTHON
import torch import torch.nn as nn x = torch.tensor([-4.0, -2.0, -1.0, 0.0, 2.0, 4.0]) activation = nn.LeakyReLU(negative_slope=0.1) y = activation(x) print(y) # tensor([-0.4000, -0.2000, -0.1000, 0.0000, 2.0000, 4.0000])

The slope 0.1 remains fixed. It is not an optimizer parameter.

B. PReLU with one shared learnable slope#

PYTHON
import torch import torch.nn as nn x = torch.tensor([-4.0, -2.0, -1.0, 0.0, 2.0, 4.0]) activation = nn.PReLU(num_parameters=1, init=0.25) y = activation(x) print(y) print("learnable slope:", activation.weight)

The slope is stored as a parameter and can be updated by an optimizer.

C. PReLU with a slope per convolutional channel#

PYTHON
import torch.nn as nn channels = 64 model = nn.Sequential( nn.Conv2d(3, channels, kernel_size=3, padding=1), nn.PReLU(num_parameters=channels, init=0.25), nn.Conv2d(channels, 128, kernel_size=3, padding=1), nn.PReLU(num_parameters=128, init=0.25), )

For a 2D convolutional feature map, the channel dimension is dimension 1 in the standard NCHW layout. The PReLU parameter count must match the intended channel sharing.

D. Train PReLU parameters with an optimizer#

PYTHON
import torch import torch.nn as nn model = nn.Sequential( nn.Linear(20, 64), nn.PReLU(num_parameters=1), nn.Linear(64, 2) ) optimizer = torch.optim.Adam(model.parameters(), lr=1e-3) criterion = nn.CrossEntropyLoss() inputs = torch.randn(16, 20) targets = torch.randint(0, 2, (16,)) optimizer.zero_grad() logits = model(inputs) loss = criterion(logits, targets) loss.backward() optimizer.step() print("learned PReLU slope:", model[1].weight.detach())

Because the PReLU slope is a registered model parameter, it is included in model.parameters() and receives gradients during backpropagation.

E. Inspect the learned channel-wise slopes#

PYTHON
prelu = nn.PReLU(num_parameters=4, init=0.25) print("initial slopes:", prelu.weight.detach()) # After training: # print("learned slopes:", prelu.weight.detach())

Inspecting the values can help understand how the network adapted its negative-side response. It does not by itself prove that the learned activation is better; compare validation performance.

12. Should PReLU slope parameters use weight decay?#

A practical detail: PyTorch's PReLU documentation cautions against applying weight decay to its learnable slope parameter for good performance.

Why? Weight decay pushes parameters toward zero. If the PReLU slope is pushed toward zero, the activation becomes more like ordinary ReLU on negative inputs, which may undermine the intended adaptive behavior.

A common approach is to put PReLU parameters in a separate optimizer parameter group without weight decay.

PYTHON
prelu_params = [model[1].weight] prelu_param_ids = {id(parameter) for parameter in prelu_params} other_params = [ parameter for parameter in model.parameters() if id(parameter) not in prelu_param_ids ] optimizer = torch.optim.AdamW( [ {"params": other_params, "weight_decay": 1e-4}, {"params": prelu_params, "weight_decay": 0.0}, ], lr=1e-3 )

In real models, use explicit module/parameter references rather than relying on parameter-name matching, which can be fragile. The example illustrates the parameter-group idea.

13. Common mistakes#

  1. Assuming PReLU and Leaky ReLU are identical. Their equations look alike, but one slope is fixed and the other is learned.
  2. Thinking Leaky ReLU learns its slope. The negative_slope argument is a fixed configuration value.
  3. Thinking PReLU always learns one slope per neuron. PyTorch supports one shared slope or one per channel; select the parameterization intentionally.
  4. Using the wrong number of PReLU parameters. For channel-wise PReLU, match the number of channels and the expected channel dimension.
  5. Applying weight decay indiscriminately to PReLU slopes. Consider excluding these parameters from weight decay.
  6. Assuming a larger negative slope is always better. It changes both negative activations and gradient magnitudes; validate it empirically.
  7. Assuming PReLU always outperforms Leaky ReLU. More flexibility does not guarantee better generalization.
  8. Ignoring initialization. The starting slope affects early optimization; choose and validate it.
  9. Assuming either activation completely solves dying ReLU. They preserve a negative-side gradient, but do not prevent all optimization failures.
  10. Comparing models without controlling other variables. Keep architecture, initialization, optimizer, training schedule, and data splits consistent when testing activations.
  11. Forgetting to save learned PReLU parameters. They are part of the model state and must be included in checkpoints.
  12. Over-interpreting learned slopes. A slope value alone is not a reliable explanation of feature importance or model quality.

14. Practical selection guide#

Choose Leaky ReLU when:

  • You want a simple, low-overhead activation.
  • A fixed negative slope is sufficient.
  • You need a stable baseline for an experiment.
  • You prefer fewer trainable parameters and simpler optimization.
  • You are building a discriminator or CNN and have no evidence that adaptive slopes are necessary.

Choose PReLU when:

  • You want the network to learn the negative-side slope from data.
  • You have enough training data to support the extra flexibility.
  • Channel-specific activation behavior may help.
  • You are experimenting with deep CNNs or feature extractors.
  • You can monitor learned parameters and validate generalization.

A sensible experiment is to compare ReLU, Leaky ReLU (for example, slope 0.01), and PReLU (for example, initialization 0.25) under the same training setup. Evaluate validation loss, task metrics, training stability, and inference performance. Do not select PReLU only because it has more flexibility.

15. Interview-ready summary#

Leaky ReLU and PReLU both allow a small non-zero gradient for negative inputs, helping reduce the zero-gradient behavior of ordinary ReLU. Leaky ReLU uses a fixed negative slope, commonly 0.01. PReLU makes that slope a learnable parameter, either shared across a layer or learned per channel. PReLU is more adaptive and adds a small number of parameters; Leaky ReLU is simpler and requires no slope learning. Choose between them based on validation performance, data size, architecture, and optimization constraints.

  • What is Leaky ReLU? — The fixed-slope activation.
  • What is Parametric ReLU (PReLU)? — The learnable negative slope.
  • How can the dying ReLU problem be prevented? — Gradient flow and inactive neurons.
  • How do ReLU and GELU compare as neural-network activation functions? — A related activation comparison.
  • What are the most common activation functions? — Broader activation-function overview.

Related questions

Explore other topics:Machine LearningLarge Language Models