Skip to main content
QUICK REVIEW

[Paper Review] ShiftAddViT: Mixture of Multiplication Primitives Towards Efficient Vision Transformer

Haoran You, Huihong Shi|arXiv (Cornell University)|Jun 10, 2023
Advanced Neural Network ApplicationsComputer Science6 citations
TL;DR

This paper proposes ShiftAddViT, a method to accelerate Vision Transformers by reparameterizing attention and MLP layers using a mixture of multiplication primitives—bitwise shifts and additions—enabling end-to-end inference speedups on GPUs without retraining. It introduces a latency-aware load-balancing loss in a mixture-of-experts framework to dynamically route tokens to efficient shift or accurate multiplication experts, achieving up to 5.18× latency reduction and 42.9% energy savings while preserving model accuracy.

ABSTRACT

Vision Transformers (ViTs) have shown impressive performance and have become a unified backbone for multiple vision tasks. However, both the attention mechanism and multi-layer perceptrons (MLPs) in ViTs are not sufficiently efficient due to dense multiplications, leading to costly training and inference. To this end, we propose to reparameterize pre-trained ViTs with a mixture of multiplication primitives, e.g., bitwise shifts and additions, towards a new type of multiplication-reduced model, dubbed $ extbf{ShiftAddViT}$, which aims to achieve end-to-end inference speedups on GPUs without requiring training from scratch. Specifically, all $ exttt{MatMuls}$ among queries, keys, and values are reparameterized using additive kernels, after mapping queries and keys to binary codes in Hamming space. The remaining MLPs or linear layers are then reparameterized with shift kernels. We utilize TVM to implement and optimize those customized kernels for practical hardware deployment on GPUs. We find that such a reparameterization on attention maintains model accuracy, while inevitably leading to accuracy drops when being applied to MLPs. To marry the best of both worlds, we further propose a new mixture of experts (MoE) framework to reparameterize MLPs by taking multiplication or its primitives as experts, e.g., multiplication and shift, and designing a new latency-aware load-balancing loss. Such a loss helps to train a generic router for assigning a dynamic amount of input tokens to different experts according to their latency. Extensive experiments on various 2D/3D Transformer-based vision tasks consistently validate the effectiveness of our proposed ShiftAddViT, achieving up to $ extbf{5.18$ imes$}$ latency reductions on GPUs and $ extbf{42.9}$% energy savings, while maintaining a comparable accuracy as original or efficient ViTs.

Motivation & Objective

  • To reduce the high hardware latency and energy consumption of Vision Transformers caused by dense multiplications in attention and MLPs.
  • To enable end-to-end inference speedups on GPUs without retraining from scratch by reparameterizing pre-trained ViTs.
  • To maintain model accuracy when replacing multiplications with cheaper shift and add operations through adaptive routing of tokens.
  • To co-optimize attention and MLPs for efficiency by leveraging hardware-friendly primitives and a novel load-balancing mechanism.
  • To design a mixture-of-experts framework where experts differ in computational cost and accuracy, enabling dynamic token allocation based on latency.

Proposed method

  • Reparameterize all matrix multiplications in self-attention using additive kernels after mapping queries and keys to binary codes in Hamming space.
  • Repurpose remaining MLPs and linear layers using shift kernels, replacing multiplications with bitwise shifts and additions.
  • Implement custom CUDA kernels via TVM to optimize shift and add operations for efficient GPU deployment.
  • Introduce a mixture-of-experts (MoE) framework where multiplication and shift operations serve as unbalanced experts with distinct computational costs.
  • Design a latency-aware load-balancing loss that assigns more input tokens to faster experts (e.g., shifts) while preserving accuracy for critical tokens.
  • Use the router to dynamically route important, sensitive tokens to multiplication experts and less critical tokens to shift experts based on latency and importance.

Experimental results

Research questions

  • RQ1Can pre-trained Vision Transformers be accelerated on GPUs without retraining by replacing multiplications with shift and add primitives?
  • RQ2How can accuracy be preserved when replacing dense multiplications with approximate shift-and-add operations in ViTs?
  • RQ3Can a mixture-of-experts framework with unbalanced experts (multiplication vs. shift) achieve better accuracy-efficiency trade-offs than fixed replacement strategies?
  • RQ4Does a latency-aware load-balancing loss effectively balance token routing to minimize synchronization overhead and maximize speedup?
  • RQ5To what extent can hardware-inspired primitives like shifts and adds reduce latency and energy consumption in 2D and 3D Transformer-based vision models?

Key findings

  • ShiftAddViT achieves up to 5.18× latency reduction on GPUs while maintaining accuracy comparable to original or efficient ViTs.
  • The method reduces energy consumption by 42.9% compared to baseline ViTs, demonstrating strong energy efficiency.
  • The latency-aware load-balancing loss enables a 14.6% reduction in latency (from 100% to 85.4%) with only a 0.01% accuracy drop on PVTv2-B0.
  • Visualization confirms that the router successfully dispatches object-containing tokens to multiplication experts and background tokens to shift experts.
  • The reparameterization of attention layers via additive kernels maintains model accuracy, but MLP reparameterization alone causes accuracy drops, necessitating the MoE framework.
  • The MoE framework with unbalanced experts provides a soft replacement strategy, preserving accuracy for critical tokens while accelerating less important ones.

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.