Abstract
Spiking neural networks (SNNs) offer a promising paradigm for modeling brain dynamics and developing neuromorphic intelligence, yet an online learning system capable of training rich spiking dynamics over long horizons with low memory footprints has been missing. Here, we introduce BrainTrace, a model-agnostic, linear-memory, and automated online learning system for spiking neural networks. BrainTrace standardizes model specification to encompass diverse neuronal and synaptic dynamics; implements a linear-memory online learning rule by exploiting intrinsic properties of spiking dynamics; and provides a compiler that automatically generates optimized online-learning code for arbitrary user-defined models. Across diverse dynamics and tasks, BrainTrace achieves strong learning performance with a low memory footprint and high computational throughput. Critically, these properties enable online fitting of a whole-brain-scale Drosophila SNN that recapitulates region-level functional activity. By reconciling generality, efficiency, and usability, BrainTrace establishes a foundation for spiking network modeling at scale.
The Challenge of Temporal Credit Assignment
Spiking Neural Networks (SNNs) are highly promising for modeling biological brain dynamics and building ultra-efficient neuromorphic AI. However, training them is notoriously difficult due to the "temporal credit assignment" problem—determining which past spikes contributed to a current error.
The standard solution, Backpropagation Through Time (BPTT), is an offline method requiring the storage of the entire history of network states. Because SNNs operate at millisecond resolution, a single second of data can require thousands of simulation steps, causing memory requirements to scale linearly with time ($O(T)$) and quickly exceeding the capacity of standard GPUs. While online learning algorithms update weights on the fly to avoid history storage, they have historically faced a trilemma: they either suffer from quadratic memory growth relative to network size ($O(N^2)$), sacrifice biological fidelity by using oversimplified neuron models, or require manual derivation of complex mathematical updates for every new architecture.
The BrainTrace Framework
BrainTrace is an end-to-end compiler built on JAX that functions as an "autograd" ecosystem specifically for SNN online learning. It allows researchers to write high-level SNN code while the system automatically generates optimized, numerically stable online updates.
To achieve generality, BrainTrace standardizes model specifications into two primary configurations: AlignPre and AlignPost. These configurations allow the system to encompass a wide variety of neuronal and synaptic dynamics, ensuring that the automated learning rules remain model-agnostic.
Algorithmic Innovations: From $O(N^2)$ to Linear Memory
To overcome the memory bottleneck, BrainTrace utilizes a progression of algorithmic approximations:
- D-RTRL (Diagonal-approximated Real-Time Recurrent Learning): This method reduces memory complexity from $O(N^3)$ to $O(N^2)$ by ignoring the gradient flow through recurrent connections, relying instead on the intrinsic dynamics of the neurons. This is justified by the inherent sparsity of biological firing.
- pp-prop (pre-post eligibility trace propagation): This is the core algorithmic breakthrough that further reduces memory to linear complexity ($O(N)$). It tracks pre-synaptic and post-synaptic activities as two separate, lightweight variables, updating them locally.
The mathematical foundation of pp-prop relies on two key insights. First, biological neurons fire sparsely, allowing for a highly accurate "diagonal approximation" of the Jacobian matrix. Second, because spikes are binary and non-negative, the summation of complex matrices can be approximated by a simple outer product of vectors (a rank-one approximation). This biological property is what allows pp-prop to achieve linear memory scaling.
Key Results and Scaling
BrainTrace was evaluated across neuromorphic classification (N-MNIST, SHD, DVS Gesture), cognitive tasks (Delayed match-to-sample), and biological simulations.
- Efficiency: On the DVS Gesture dataset,
pp-propmaintained a constant memory footprint regardless of sequence length, proving 35x more memory-efficient than the quadratic D-RTRL baseline and running 10x faster. - Accuracy: Despite the approximations,
pp-propmatched or exceeded exact BPTT performance. On the SHD dataset, it achieved 95.33% accuracy, surpassing the strongest online baseline by over 10%. - Whole-Brain Scaling: The system successfully trained a connectome-constrained Drosophila model with over 125,000 neurons and 50 million synapses. This feat required only 8.9 GB of GPU memory; for comparison, BPTT and D-RTRL both exceeded the 32 GB hardware limit.
Conclusion
By reconciling generality, efficiency, and usability, BrainTrace establishes a foundation for spiking network modeling at scale. While the approximation relies on sparse firing regimes, it unlocks the ability to train massive, biologically realistic models on standard hardware, bridging the gap between computational neuroscience and scalable neuromorphic AI.
Summary updated