Spike-Driven Transformer (NeurIPS2023)
Man Yao, Jiakui Hu, Zhaokun Zhou, Li Yuan, Yonghong Tian, Bo Xu, Guoqi Li
BICLab, Institute of Automation, Chinese Academy of Sciences
π π π News:
- Jul. 04, 2023: Release the code for training and testing.
- Sep. 22, 2023: Accepted as poster in NeurIPS2023.
- Sep. 30, 2023: Release the configs and pre-trained parameters on IN1K.
- Feb. 15. 2024: The Spike-Driven Transformer V2, which achieves 80.0% acc on IN1K, is now available.
Spiking Neural Networks (SNNs) provide an energy-efficient deep learning option due to their unique spike-based event-driven (i.e., spike-driven) paradigm. In this paper, we incorporate the spike-driven paradigm into Transformer by the proposed Spike-driven Transformer with four unique properties: i) Event-driven, no calculation is triggered when the input of Transformer is zero; ii) Binary spike communication, all matrix multiplications associated with the spike matrix can be transformed into sparse additions; iii) Self-attention with linear complexity at both token and channel dimensions; iv) The operations between spike-form Query, Key, and Value are mask and addition. Together, there are only sparse addition operations in the Spike-driven Transformer. To this end, we design a novel Spike-Driven Self-Attention (SDSA), which exploits only mask and addition operations without any multiplication, and thus having up to 87.2Γ lower computation energy than vanilla self-attention. Especially in SDSA, the matrix multiplication between Query, Key, and Value is designed as the mask operation. In addition, we rearrange all residual connections in the vanilla Transformer before the activation functions to ensure that all neurons transmit binary spike signals. It is shown that the Spike-driven Transformer can achieve 77.1% top-1 accuracy on ImageNet-1K, which is the state-of-the-art result in the SNN field.
timm == 0.6.12
1.10.0 <= pytorch < 2.0.0
cupy
spikingjelly == 0.0.0.0.12
tensorboard
!!! Please install the spikingjelly and tensorboard correctly before raising issues about requirements. !!!
model | T | layers | channels | Top-1 Acc | Power(mj) | Models |
---|---|---|---|---|---|---|
Spike-Driven Transformer | 4 | 8 | 384 | 72.28 | 3.90 | link |
Spike-Driven Transformer | 4 | 6 | 512 | 74.11 | 3.56 | link |
Spike-Driven Transformer | 4 | 8 | 512 | 74.57 | 4.50 | link |
Spike-Driven Transformer | 4 | 10 | 512 | 74.66 | 5.53 | link |
Spike-Driven Transformer | 4 | 8 | 768 | 77.07 | 6.09 | link |
The hyper-parameters are in ./conf/
.
Train:
CUDA_VISIBLE_DEVICES=0 python -m torch.distributed.launch --nproc_per_node=1 --master_port 29501 train.py -c /the/path/of/conf --model sdt --spike-mode lif
Test:
CUDA_VISIBLE_DEVICES=0 python -m torch.distributed.launch --nproc_per_node=1 --master_port 29501 firing_num.py -c /the/path/of/conf --model sdt --spike-mode lif --resume /the/path/of/parameters --no-resume-opt
# for 288 x 288 resolution
CUDA_VISIBLE_DEVICES=0 python -m torch.distributed.launch --nproc_per_node=1 --master_port 29501 firing_num.py -c /the/path/of/conf --model sdt --spike-mode lif --resume /the/path/of/parameters --no-resume-opt --large-valid
Result and explainability:
- use
PyTorch
to load the CIFAR10 and CIFAR100 dataset. - use
SpikingJelly
to prepare and load the Gesture and CIFAR10-DVS dataset.
Tree in ./data/
.
.
βββ cifar-100-python
βββ cifar-10-batches-py
βββ cifar10-dvs
β βββ download
β βββ events_np
β βββ extract
β βββ frames_number_10_split_by_number
β βββ frames_number_16_split_by_number
βββ cifar10-dvs-tet
β βββ test
β βββ train
βββ DVSGesturedataset
βββ download
βββ events_np
β βββ test
β βββ train
βββ extract
β βββ DvsGesture
βββ frames_number_10_split_by_number
β βββ download
β βββ test
β βββ train
βββ frames_number_16_split_by_number
βββ test
βββ train
ImageNet with the following folder structure, you can extract imagenet by this script.
βimagenet/
βββtrain/
β βββ n01440764
β β βββ n01440764_10026.JPEG
β β βββ n01440764_10027.JPEG
β β βββ ......
β βββ ......
βββval/
β βββ n01440764
β β βββ ILSVRC2012_val_00000293.JPEG
β β βββ ILSVRC2012_val_00002138.JPEG
β β βββ ......
β βββ ......
@inproceedings{yao2023spikedriven,
title={Spike-driven Transformer},
author={Man Yao and JiaKui Hu and Zhaokun Zhou and Li Yuan and Yonghong Tian and Bo XU and Guoqi Li},
booktitle={Thirty-seventh Conference on Neural Information Processing Systems},
year={2023},
url={https://openreview.net/forum?id=9FmolyOHi5}
}
For help or issues using this git, please submit a GitHub issue.
For other communications related to this git, please contact manyao@ia.ac.cn
and jkhu29@stu.pku.edu.cn
.