Continual Transformers: Redundancy-Free Attention for Online Inference

17 Jan 2022  ·  Lukas Hedegaard, Arian Bakhtiarnia, Alexandros Iosifidis ·

Transformers in their common form are inherently limited to operate on whole token sequences rather than on one token at a time. Consequently, their use during online inference on time-series data entails considerable redundancy due to the overlap in successive token sequences. In this work, we propose novel formulations of the Scaled Dot-Product Attention, which enable Transformers to perform efficient online token-by-token inference on a continual input stream. Importantly, our modifications are purely to the order of computations, while the outputs and learned weights are identical to those of the original Transformer Encoder. We validate our Continual Transformer Encoder with experiments on the THUMOS14, TVSeries and GTZAN datasets with remarkable results: Our Continual one- and two-block architectures reduce the floating point operations per prediction by up to 63x and 2.6x, respectively, while retaining predictive performance.

PDF Abstract
Task Dataset Model Metric Name Metric Value Global Rank Result Benchmark
Online Action Detection THUMOS'14 OadTR mAP 64.2 # 11
MFLOPs per pred 2513.5 # 1
Online Action Detection THUMOS'14 CoOadTR-b1 MFLOPs per pred 10.6 # 6
Online Action Detection THUMOS'14 CoOadTR-b2 mAP 64.4 # 10
MFLOPs per pred 411.9 # 4
Online Action Detection THUMOS'14 OadTR-b1 mAP 63.9 # 12
MFLOPs per pred 673 # 3
Online Action Detection THUMOS'14 OadTR-b2 mAP 64.5 # 9
MFLOPs per pred 1075.7 # 2
Online Action Detection TVSeries OadTR-b2 mCAP 88.3 # 5
Online Action Detection TVSeries CoOadTR-b1 mCAP 87.7 # 8
Online Action Detection TVSeries CoOadTR-b2 mCAP 87.6 # 9
Online Action Detection TVSeries OadTR-b1 mCAP 88.1 # 6
Online Action Detection TVSeries OadTR mCAP 88.6 # 4

Methods