Abstract
Spiking Neural Networks (SNNs) offer a biologically inspired alternative to traditional artificial neural networks, yet they present significant challenges in simulation efficiency and training ease. We introduce SNNAX, a library built on JAX and Equinox designed to bridge the gap between high-performance computing and intuitive model design. SNNAX leverages JAX’s XLA compilation and functional transformations while providing a stateful, object-oriented feel through Equinox. Our benchmarks demonstrate that SNNAX achieves up to a 5x speedup over established PyTorch-based frameworks like snnTorch, particularly in recurrent and convolutional architectures, while maintaining the flexibility required for complex biological modeling.
1. Introduction
Spiking Neural Networks (SNNs) communicate via discrete temporal events, or "spikes," mimicking the energy-efficient processing of biological brains. However, researchers often face a "trilemma" when selecting development tools. Biological simulators like NEST provide high fidelity but lack gradient-based optimization. PyTorch-based libraries like snnTorch offer ease of use but often suffer from performance bottlenecks during long temporal simulations. Conversely, pure JAX implementations provide exceptional speed via XLA but require complex functional programming patterns to manage neuron states, such as membrane potentials.
SNNAX is designed to resolve these tensions. By building on the Equinox framework, SNNAX provides a library that is fast, supports complex recurrence, and remains accessible to researchers familiar with standard deep learning paradigms.
2. Methodology
2.1 The Equinox Framework
The core of SNNAX is its integration with Equinox, which represents neural networks as "PyTrees." This architectural choice allows SNNAX to maintain a familiar object-oriented interface while remaining fully compatible with JAX’s functional transformations, including jit (Just-In-Time compilation), vmap (automatic vectorization), and grad (automatic differentiation). This avoids the extensive boilerplate code often associated with other JAX libraries like Haiku or Flax.
2.2 Step-by-Step Execution and Recurrence
A defining feature of SNNAX is its default step-by-step execution model. While some libraries process an entire layer across all time steps before moving to the next (layer-by-layer), SNNAX processes all layers for a single time step before proceeding. Although layer-by-layer unrolling can be faster for simple feed-forward networks, step-by-step execution is essential for modeling the feedback loops and recurrent connections characteristic of biological neural systems. To facilitate this, SNNAX includes a GraphStructure class, enabling the definition of non-linear, multi-pathway models.
2.3 Training and State Management
To overcome the non-differentiable nature of the spiking function, SNNAX implements surrogate gradients, allowing for standard Backpropagation Through Time (BPTT). Furthermore, the library abstracts the management of internal neuron states. This removes the need for manual state-tracking, a common source of error in native JAX implementations, allowing researchers to focus on architecture and learning rules.
3. Performance Evaluation
To evaluate the efficiency of SNNAX, we conducted benchmarks against snnTorch using an NVIDIA RTX 4090 GPU with a batch size of 32. The evaluation focused on two primary architectures:
- Multi-Layer Perceptron (MLP): A 2-layer network consisting of 2048 Leaky Integrate-and-Fire (LIF) neurons.
- Convolutional Neural Network (LIF-CNN): A 2-layer CNN with 3x3 kernels processing 48x48 pixel inputs.
Additionally, the library was tested using notebooks inspired by the Neurobench initiative to ensure compatibility with community-standard benchmarks.
4. Results
The benchmarking results indicate that SNNAX significantly outperforms compiled PyTorch-based alternatives.
- MLP Performance: SNNAX achieved an execution time of 2.23 ms, compared to 12.98 ms for the compiled version of snnTorch. This performance is competitive with other specialized JAX libraries such as Spyx and Slax.
- CNN Performance: In the LIF-CNN benchmark, SNNAX maintained its advantage with an execution time of 3.74 ms, whereas compiled snnTorch required approximately 15.44 ms.
These results highlight the efficiency of the XLA compiler when applied to the structured PyTree representations provided by Equinox.
5. Discussion and Limitations
While SNNAX offers substantial performance gains, the choice of step-by-step execution introduces a trade-off. In strictly feed-forward scenarios, libraries that utilize layer-by-layer unrolling may achieve higher raw speeds. Furthermore, training SNNs remains memory-intensive; storing neuron states over thousands of time steps for BPTT can strain hardware resources.
SNNAX mitigates some of these issues by leveraging JAX’s advanced automatic differentiation tools, such as gradient checkpointing to reduce memory overhead and forward-mode differentiation for exploring online learning algorithms.
6. Conclusion
SNNAX provides a powerful, flexible, and user-friendly framework for SNN research. By combining the speed of JAX with the structural clarity of Equinox, it enables the simulation of complex recurrent architectures that were previously difficult to implement efficiently. Future work will focus on optimizing execution loops and expanding the library of neuron models to support a broader range of neuromorphic hardware.
Summary updated