Training event-based neural networks with exact gradients via Differentiable ODE Solving in JAX
Organizations: CITEC, Bielefeld University, Bielefeld, Germany · Department of Computer Science, Royal Holloway, University of London, Egham, United Kingdom
Abstract
Existing frameworks for gradient-based training of spiking neural networks face a trade-off: discrete-time methods using surrogate gradients support arbitrary neuron models but introduce gradient bias and constrain spike-time resolution, while continuous-time methods that compute exact gradients require analytical expressions for spike times and state evolution, restricting them to simple neuron types such as Leaky Integrate and Fire (LIF). We introduce the Eventax framework, which resolves this trade-off by combining differentiable numerical ODE solvers with event-based spike handling. Built in JAX, our frame-work uses Diffrax ODE-solvers to compute gradients that are exact with respect to the forward simulation for any neuron model defined by ODEs . It also provides a simple API where users can specify just the neuron dynamics, spike conditions, and reset rules. Eventax prioritises modelling flexibility, supporting a wide range of neuron models, loss functions, and network architectures, which can be easily extended. We demonstrate Eventax on multiple benchmarks, including Yin-Yang and MNIST, using diverse neuron models such as Leaky Integrate-and-fire (LIF), Quadratic Integrate-and-fire (QIF), Exponential integrate-and-fire (EIF), Izhikevich and Event-based Gated Recurrent Unit (EGRU) with both time-to-first-spike and state-based loss functions, demonstrating its utility for prototyping and testing event-based architectures trained with exact gradients. We also demonstrate the application of this framework for more complex neuron types by implementing a multi-compartment neuron that uses a model of dendritic spikes in human layer 2/3 cortical Pyramidal neurons for computation. Code available at https://github.com/efficient-scalable-machine-learning/eventax.
Figures & tables
| Library | Time scale | Backend(s) | State evolution | Spike detection | Event gradients | Supported models |
|---|---|---|---|---|---|---|
| Eventax (ours) | continuous | JAX / Equinox / Diffrax | numerical ODE solver | root-finding | backprop through solver | model-agnostic (no closed forms required) |
| SNNAX [ 1 ] | discrete | JAX / Equinox | discrete (Euler) | grid threshold | surrogate | model-agnostic |
| Norse [ 8 ] | discrete | PyTorch | discrete (Euler) | grid threshold | surrogate / closed form (LIF) | model-agnostic; optional LIF closed form |
| snnTorch [ 2 ] | discrete | PyTorch | discrete (Euler) | grid threshold | surrogate | model-agnostic |
| Holberg & Salvi [ 7 ] | continuous | JAX / Equinox / Diffrax | numerical SDE solver | root-finding | backprop through solver | model-agnostic (single model demonstrated) |
| EventProp [ 4 ] | continuous | PyTorch / C++ | analytical (closed-form) | root-finding | closed-form | LIF only |
| Parameter | Symbol | LIF | QIF a | EIF | Izhikevich |
|---|---|---|---|---|---|
| Membrane time constant | – | ||||
| Synaptic time constant | |||||
| Spike threshold | or | 1.00 | |||
| Exponential threshold | – | – | 1.00 | – | |
| Reset voltage | or | 0.00 | 0.00 | ||
| Leak reversal | – | – | 0.00 | – |
| Parameter | Yin–Yang | MNIST |
|---|---|---|
| Network architecture | 5–50–3 a | 784–200–10 a |
| Batch size | 256 | 1024 |
| Epochs | 100 | 100 |
| Optimizer | AdamW b | AdamW b |
| Learning rate (TTFS) | 0.005 | 0.005 |
| Learning rate (state-based) | 0.005 (LIF) | 0.005 |
| Neuron | Loss | Accuracy [%] | Max Firing a | Dead Neurons b | Fire Count c | TTFS [ ] d |
|---|---|---|---|---|---|---|
| LIF | TTFS (AMOS) e | (90.90) | (1.00) | (2.50) | (33.06) | (15.71) |
| Max | (95.20) | (3.88) | (8.00) | (67.93) | – | |
| Integral | (96.70) | (3.49) | (15.00) | (58.57) | – | |
| Exp-Integral | (97.10) | (3.88) | (7.00) | (60.28) | – | |
| QIF | TTFS | (98.70) | (1.00) | (1.00) | (45.43) | (27.23) |
| Max | (98.60) | (1.23) | (0.00) | (43.06) | – |
Spiking Neural Networks
Spiking neural networks process information through discrete, time-dependent neural events, aiming for efficient computation and biologically inspired learning.
See all 351 papers