Skip to main content
QUICK REVIEW

[Paper Review] EcoFormer: Energy-Saving Attention with Linear Complexity

Jing Liu, Zizheng Pan|arXiv (Cornell University)|Sep 19, 2022
Advanced Neural Network ApplicationsComputer Science16 citations
TL;DR

EcoFormer proposes a linear-complexity, energy-efficient attention mechanism that uses kernelized hashing to map queries and keys into compact binary codes, preserving pairwise similarity while replacing expensive multiply-accumulate operations with low-energy accumulations. It achieves 73% lower on-chip energy consumption than standard attention with only a 0.33% accuracy drop on ImageNet-1K.

ABSTRACT

Transformer is a transformative framework that models sequential data and has achieved remarkable performance on a wide range of tasks, but with high computational and energy cost. To improve its efficiency, a popular choice is to compress the models via binarization which constrains the floating-point values into binary ones to save resource consumption owing to cheap bitwise operations significantly. However, existing binarization methods only aim at minimizing the information loss for the input distribution statistically, while ignoring the pairwise similarity modeling at the core of the attention. To this end, we propose a new binarization paradigm customized to high-dimensional softmax attention via kernelized hashing, called EcoFormer, to map the original queries and keys into low-dimensional binary codes in Hamming space. The kernelized hash functions are learned to match the ground-truth similarity relations extracted from the attention map in a self-supervised way. Based on the equivalence between the inner product of binary codes and the Hamming distance as well as the associative property of matrix multiplication, we can approximate the attention in linear complexity by expressing it as a dot-product of binary codes. Moreover, the compact binary representations of queries and keys enable us to replace most of the expensive multiply-accumulate operations in attention with simple accumulations to save considerable on-chip energy footprint on edge devices. Extensive experiments on both vision and language tasks show that EcoFormer consistently achieves comparable performance with standard attentions while consuming much fewer resources. For example, based on PVTv2-B0 and ImageNet-1K, Ecoformer achieves a 73% on-chip energy footprint reduction with only a 0.33% performance drop compared to the standard attention. Code is available at https://github.com/ziplab/EcoFormer.

Motivation & Objective

  • Address the high energy consumption of standard Transformers, especially on edge devices.
  • Overcome the limitation of conventional binarization methods that ignore pairwise similarity in attention mechanisms.
  • Develop a binarization strategy tailored to the softmax attention mechanism to preserve token-level similarity relations.
  • Achieve linear complexity in attention computation while minimizing performance degradation.
  • Enable scalable deployment of Transformer models on resource-constrained edge devices through energy-efficient hardware-friendly operations.

Proposed method

  • Use kernelized hashing with RBF kernels to map high-dimensional queries and keys into low-dimensional binary codes in Hamming space.
  • Train hash functions in a self-supervised manner to align Hamming affinity (dot product of binary codes) with ground-truth attention scores.
  • Leverage the associative property of matrix multiplication to express attention as a linear-complexity dot product of binary codes.
  • Replace most multiply-accumulate operations with simple accumulations to reduce on-chip energy footprint.
  • Use the similarity matrix from standard attention as supervision signals for hash function learning.
  • Introduce a support sample strategy with hyperparameter $ m $ to improve hash function generalization during training.

Experimental results

Research questions

  • RQ1Can binarization of queries and keys in self-attention be customized to preserve pairwise similarity relations rather than minimizing statistical quantization error?
  • RQ2Can kernelized hashing with RBF kernels enable linear-complexity attention while maintaining competitive performance?
  • RQ3To what extent can energy consumption be reduced in Transformers by replacing FP32/FP16 multiply-accumulate operations with binary accumulations?
  • RQ4How does the number of support samples $ m $ affect the performance and energy efficiency of the proposed method?
  • RQ5Can EcoFormer achieve comparable accuracy to standard attention while significantly reducing computational and energy costs on vision and language benchmarks?

Key findings

  • EcoFormer achieves a 73% reduction in on-chip energy consumption on PVTv2-B0 with only a 0.33% accuracy drop on ImageNet-1K compared to standard attention.
  • On CIFAR-100, EcoFormer with $ m=25 $ support samples achieves 71.23% Top-1 accuracy, outperforming models with fewer support samples.
  • The method reduces computational complexity from $ frac{1}{2}N^2 $ to $ frac{1}{2}N $, enabling linear-time attention computation.
  • EcoFormer shows significantly lower latency and on-chip energy than other efficient attention methods, as validated on multiple benchmarks.
  • Training from scratch on ImageNet-1K shows EcoFormer maintains high performance with 72% fewer multiplications and 72% lower energy consumption on PVTv2-B0.
  • The performance drop from binarization is attributed to gradient approximation in the non-differentiable sign function, which can be mitigated with advanced optimization techniques.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.