Spiking Neural Networks with Dynamic Time Steps for Vision Transformers

Gourav Datta, Zeyu Liu, Anni Li, Peter A. BeerelarXiv 2023 · DOI

Abstract

This paper introduces a novel training framework for Spiking Neural Networks (SNNs) that dynamically allocates the number of time steps to different modules within a Vision Transformer (ViT). By allowing the network to "skip" unnecessary temporal computations in less sensitive layers, the authors achieve state-of-the-art accuracy on complex vision tasks with significantly lower latency and up to 17x better energy efficiency than non-spiking counterparts.

Introduction

Spiking Neural Networks (SNNs) are brain-inspired models attractive for edge computing due to their use of sparse binary pulses (spikes). This replaces expensive multiply-accumulate (MAC) operations with energy-efficient additions (AC). However, SNNs face a "time problem": achieving high accuracy typically requires multiple time steps, which increases latency. While time-step reduction has worked for Convolutional Neural Networks (CNNs), it often fails for Vision Transformers (ViTs), leading to either inefficiency or accuracy drops. This research identifies that different ViT components (e.g., self-attention vs. MLP blocks) have varying temporal sensitivities, a nuance ignored by fixed-time-step models.

Methodology: Dynamic Time Step Spiking (DTSS)

The core innovation is the Dynamic Time Step Spiking (DTSS) layer. Instead of a fixed duration ($T_{max}$), the framework introduces trainable score tensors that determine a layer's "importance" at each time step. These scores are converted into binary masks ($TM^t_l$); a zero mask allows the layer to skip computation, saving energy.

Overview of the Spiking Transformer architecture and the internal Spiking Block with dynamic masking.

Key refinements include:

  1. Surrogate Gradient Learning: Enables training of non-differentiable binary masks.
  2. Layer Binning: Groups ViT layers (Patch Splitting, QKV, Attention, MLP) to apply dynamic stepping based on sensitivity.
  3. Architectural Adjustments: Replacing Layer Norm with Batch Norm and removing Softmax in attention blocks to maintain spike compatibility. As shown in the architecture, the dot-product attention is scaled without softmax because spiking inputs ensure outputs are non-negative and bounded.

Experimental Results

The DTSS framework was evaluated on CIFAR-10, CIFAR-100, and ImageNet. It consistently outperformed existing SNN-ViT models:

  • ImageNet: Achieved 68.04% accuracy with an average of 1.30 time steps—a 2% improvement over 1-step baselines with 46% fewer steps than 2-step models.
  • CIFAR-100: Reached 78.09% accuracy with 2.73 average time steps, reducing latency by ~36% compared to a 6-step Spikformer.
  • Energy Efficiency: Demonstrated a 16.12x reduction in energy compared to non-spiking ViTs and a 2.98x reduction compared to previous state-of-the-art spiking ViTs.

Key Insights

Analysis of activation maps revealed that "qkv" and "mlp" modules are significantly more sensitive to temporal resolution than "sps" or "attn" modules. Dynamic allocation exploits this "slack" to balance accuracy and efficiency.

Histogram showing the distribution of non-zero activations across different time steps, illustrating temporal sparsity.

Beyond computational savings, skipping time steps reduces memory access for "membrane potentials," addressing a major energy bottleneck in edge hardware. The framework uses a hyperparameter ($\lambda_m$) to allow developers to tune the model for either maximum precision or maximum battery life.

Conclusion and Future Work

While DTSS proves theoretical gains, real-world deployment requires specialized hardware compilers for "zero-gating" logic. Future research will extend this dynamic temporal approach to object detection and video processing, where temporal dynamics are even more critical.

Summary updated

Abstract

Spiking Neural Networks (SNNs) have emerged as a popular spatio-temporal computing paradigm for complex vision tasks. Recently proposed SNN training algorithms have significantly reduced the number of time steps (down to 1) for improved latency and energy efficiency, however, they target only convolutional neural networks (CNN). These algorithms, when applied on the recently spotlighted vision transformers (ViT), either require a large number of time steps or fail to converge. Based on analysis of the histograms of the ANN and SNN activation maps, we hypothesize that each ViT block has a different sensitivity to the number of time steps. We propose a novel training framework that dynamically allocates the number of time steps to each ViT module depending on a trainable score assigned to each timestep. In particular, we generate a scalar binary time step mask that filters spikes emitted by each neuron in a leaky-integrate-and-fire (LIF) layer. The resulting SNNs have high activation sparsity and require only accumulate operations (AC), except for the input embedding layer, in contrast to expensive multiply-and-accumulates (MAC) needed in traditional ViTs. This yields significant improvements in energy efficiency. We evaluate our training framework and resulting SNNs on image recognition tasks including CIFAR10, CIFAR100, and ImageNet with different ViT architectures. We obtain a test accuracy of 95.97% with 4.97 time steps with direct encoding on CIFAR10.
BibTeX
@misc{datta2023spiking,
  author = {Gourav Datta and Zeyu Liu and Anni Li and Peter A. Beerel},
  title = {{Spiking Neural Networks with Dynamic Time Steps for Vision Transformers}},
  year = {2023},
  eprint = {2311.16456},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.16456},
}
Figure