Surrogate Gradient Learning
Surrogate gradients let spiking networks train with backpropagation by replacing the non-differentiable spike function's derivative with a smooth stand-in.
The non-differentiability problem
A spiking neuron fires when its membrane potential crosses a threshold, an operation described by a step function. The step's derivative is zero everywhere except at the threshold, where it is a spike (a Dirac delta). Backpropagation multiplies gradients along the chain, so a zero derivative blocks the learning signal entirely, and the delta is unusable numerically. This is why spiking neural networks cannot be trained directly with gradient descent.
Surrogate derivatives
The surrogate gradient method keeps the true, hard spike in the forward pass, so the network's computation is unchanged, but during the backward pass it replaces the step's derivative with a smooth, bell-shaped function centered at the threshold. Common choices are the derivative of a fast sigmoid, a triangular function, or a Gaussian. The surrogate is large near the threshold, where a small change in potential could flip the spike, and small far from it, providing a usable gradient without altering the forward behavior.
class SpikeFn(torch.autograd.Function):
@staticmethod
def forward(ctx, v):
ctx.save_for_backward(v)
return (v >= 0).float() # hard spike
@staticmethod
def backward(ctx, grad):
v, = ctx.saved_tensors
surrogate = 1.0 / (1.0 + (5*v.abs()))**2 # smooth stand-in
return grad * surrogate
- Forward pass uses the exact spike, so inference behavior is faithful
- Backward pass uses a smooth surrogate to let gradients flow
- The surrogate's width and shape are tunable hyperparameters
- Enables backpropagation through time across the network's temporal steps
Training through time
Because spiking dynamics unfold over discrete time steps, training uses backpropagation through time: the network is unrolled over its steps and gradients are accumulated across them, with the surrogate applied at every spike. This is the same unrolling used for recurrent networks, combined with the surrogate trick. Surrogate gradient learning has become the dominant way to train accurate deep spiking networks, narrowing the gap with conventional deep learning while preserving the energy advantages of sparse spiking.