Large Language Models Inference Engines based on Spiking Neural Networks
Balaji, Madireddy, Balaprakash
Foundational models based on the transformer architecture are currently the state-of-the-art in general language modeling, as well as in scientific areas such as material science and climate. However, training and deploying these models is computationally challenging as the time and space complexity has a quadratic relation to the input sequence length. Several efforts exploring efficient computational paradigms and model architectures to address these limitations have been made. In this work, we explore spiking neural networks (SNNs) to design transformer models. A challenge in training large-scale SNNs, using existing surrogate learning methods is inefficient and time-consuming. On the other hand, techniques to convert existing transformer-based models to their SNN equivalent are not scalable, as achieving optimal performance comes at the cost of a large number of spike time-steps, i.e. increased latency. To address this, we propose NeurTransformer, a methodology for designing transformer-based SNN for inference using a supervised fine-tuning approach with existing conversion methods. The proposed methodology works by: (1) replacing the self-attention mechanism with a spike-based self-attention (SSA), (2) converting the feed-forward block of the trained transformer model to its equivalent SNN, and (3) fine-tuning the SSA block using SNN-based surrogate learning algorithms. We benchmark the proposed methodology and demonstrate its accuracy and scalability using three variants of the GPT-2 model of increasing model size. We observe that the converted GPT-2 small models demonstrate a 5-12% loss in cosine similarity and a 9.7% reduction in perplexity. Finally, we demonstrate the energy efficiency of the SSA block compared to the ASA block and show between 64.71% and 85.28% reductions in estimated energy consumption when implementing the self-attention mechanism on a digital hardware.
academic
Large Language Models Inference Engines based on Spiking Neural Networks
Foundation models based on the Transformer architecture represent the current state-of-the-art in general language modeling and scientific domains such as materials science and climate science. However, training and deploying these models presents significant computational challenges due to their quadratic time and space complexity with respect to input sequence length. This paper explores the use of Spiking Neural Networks (SNNs) to design Transformer models. Existing surrogate learning methods for training large-scale SNNs are inefficient and time-consuming, while techniques for converting existing Transformer models to equivalent SNNs lack scalability. To address this, the authors propose the NeuTransformer method, which designs SNN-based Transformer inference engines through supervised fine-tuning combined with existing conversion methods. The approach includes: (1) replacing the self-attention mechanism with spike-based self-attention (SSA), (2) converting feedforward blocks to equivalent SNNs, and (3) fine-tuning SSA blocks using SNN surrogate learning algorithms. Experiments demonstrate that the converted GPT-2 Small model incurs a 5-12% loss in cosine similarity, achieves a 9.7% reduction in perplexity, and SSA blocks achieve 64.71%-85.28% energy consumption reduction compared to ASA blocks.
Computational Complexity Issue: The self-attention mechanism in Transformer models exhibits O(n²) time and space complexity, where n is the sequence length. This causes computational and memory requirements to increase dramatically when processing long sequences.
Energy Consumption Problem: Traditional Transformer models require expensive GPUs or custom accelerators for training and inference, resulting in massive energy consumption.
SNN Training Difficulties: Existing SNN training methods have two major limitations:
Direct training of large-scale SNNs using backpropagation learning rules is inefficient
ANN-SNN conversion methods require numerous spike time steps to achieve optimal performance, leading to increased inference latency
The authors aim to leverage the bio-inspired characteristics and event-driven computing advantages of spiking neural networks to design Transformer models that can execute efficiently on neuromorphic hardware, thereby achieving data-efficient, low-energy, and resource-efficient large language model inference.
Proposes NeuTransformer Method: A method for designing SNN-based Transformers from pre-trained Transformer models, combining supervised fine-tuning to enhance model performance.
Designs Sparse Spike-Based Self-Attention Mechanism: Replaces energy and latency-intensive matrix multiplication and softmax operations in traditional self-attention with sparse spike-based computations.
Implements Large-Scale SNN-based LLM: Successfully converts GPT-2 and its variants to SNN versions. To the authors' knowledge, GPT-2 Large is the largest parameter SNN-based Transformer model to date.
Comprehensive Performance Evaluation: Evaluates model performance across multiple dimensions including application accuracy, cosine similarity, perplexity, and bits per byte, while analyzing energy consumption and throughput performance.
Convert pre-trained Transformer models to equivalent spiking neural network versions while maintaining acceptable performance degradation and achieving significant energy consumption reduction and hardware efficiency improvements.
On the Graphcore platform, the SNN version demonstrates superior throughput performance compared to the baseline ANN in most configurations, with particular advantages in handling irregular and sparse data access patterns.
Compared to existing methods, NeuTransformer avoids the computational overhead of training SNNs from scratch, achieving large-scale SNN-based LLM construction through a conversion plus fine-tuning strategy.
Recent SNN-based Transformer research (Li et al., 2024; Zhou et al., 2023)
Surrogate gradient learning methods (Eshraghian et al., 2023)
Summary: This paper proposes an innovative method for converting large-scale language models to spiking neural network versions, achieving significant energy consumption reduction while maintaining acceptable performance. Despite scale limitations, it provides valuable technical contributions to the fields of low-power AI inference and neuromorphic computing.