Skip to main content
QUICK REVIEW

[Paper Review] Slide-Transformer: Hierarchical Vision Transformer with Local Self-Attention

Xuran Pan, Tianzhu Ye|arXiv (Cornell University)|Apr 9, 2023
Advanced Memory and Neural ComputingEngineering3 citations
TL;DR

This paper proposes Slide-Attention, a novel local self-attention mechanism for Vision Transformers that replaces inefficient Im2Col operations with depthwise convolutions for high efficiency and generalizability across hardware. By reinterpreting local attention from a row-based perspective and introducing a re-parameterized deformed shifting module, Slide-Attention achieves state-of-the-art performance on image classification, segmentation, and detection benchmarks while enabling 1.7x faster inference on mobile devices like iPhone 12.

ABSTRACT

Self-attention mechanism has been a key factor in the recent progress of Vision Transformer (ViT), which enables adaptive feature extraction from global contexts. However, existing self-attention methods either adopt sparse global attention or window attention to reduce the computation complexity, which may compromise the local feature learning or subject to some handcrafted designs. In contrast, local attention, which restricts the receptive field of each query to its own neighboring pixels, enjoys the benefits of both convolution and self-attention, namely local inductive bias and dynamic feature selection. Nevertheless, current local attention modules either use inefficient Im2Col function or rely on specific CUDA kernels that are hard to generalize to devices without CUDA support. In this paper, we propose a novel local attention module, Slide Attention, which leverages common convolution operations to achieve high efficiency, flexibility and generalizability. Specifically, we first re-interpret the column-based Im2Col function from a new row-based perspective and use Depthwise Convolution as an efficient substitution. On this basis, we propose a deformed shifting module based on the re-parameterization technique, which further relaxes the fixed key/value positions to deformed features in the local region. In this way, our module realizes the local attention paradigm in both efficient and flexible manner. Extensive experiments show that our slide attention module is applicable to a variety of advanced Vision Transformer models and compatible with various hardware devices, and achieves consistently improved performances on comprehensive benchmarks. Code is available at https://github.com/LeapLabTHU/Slide-Transformer.

Motivation & Objective

  • Address the inefficiency and limited hardware compatibility of existing local attention modules that rely on Im2Col or CUDA-specific kernels.
  • Overcome the limitations of sparse global and window-based attention mechanisms in capturing local features and enabling cross-window communication.
  • Develop a local attention mechanism that combines the local inductive bias of convolutions with the dynamic feature selection of self-attention.
  • Ensure high efficiency and broad hardware compatibility by replacing computationally heavy operations with standard depthwise convolutions.
  • Enable flexible, deformable local feature aggregation through a re-parameterized shifting module without sacrificing inference speed.

Proposed method

  • Reinterpret the Im2Col operation from a row-based perspective, where each row corresponds to a shifted version of the input feature map.
  • Replace the column-based Im2Col with depthwise convolution to efficiently compute local key and value matrices, reducing computation and memory overhead.
  • Introduce a deformed shifting module that allows dynamic, learnable key/value positions within local receptive fields using re-parameterization.
  • Use re-parameterization to merge multiple convolutional branches into a single inference-time kernel, preserving model capacity while maintaining efficiency.
  • Integrate Slide-Attention into existing Vision Transformer architectures such as Swin, PVT, and CSwin, enabling plug-and-play deployment.
  • Design the module to be hardware-agnostic, supporting devices without CUDA support, including Apple's MPS and mobile GPUs.

Experimental results

Research questions

  • RQ1Can a local attention mechanism be designed to be both computationally efficient and compatible across diverse hardware platforms?
  • RQ2Does replacing Im2Col with depthwise convolution in local attention improve inference speed without sacrificing performance?
  • RQ3Can a re-parameterized deformed shifting module enhance feature representation in local attention while maintaining inference efficiency?
  • RQ4How does Slide-Attention compare to global and window-based attention in terms of accuracy and speed on standard vision benchmarks?
  • RQ5Can Slide-Attention be effectively deployed on mobile and edge devices without requiring specialized hardware?

Key findings

  • Slide-Attention achieves consistent performance gains across image classification, semantic segmentation, and object detection tasks when replacing attention modules in advanced Vision Transformers.
  • On iPhone 12 with MPS support, a Slide-Attention-based Swin-small model outperforms the vanilla Swin-base model while achieving 1.7x faster inference speed.
  • The method demonstrates high efficiency and generalizability, performing well on devices without CUDA support, such as Apple's Metal Performance Shader.
  • The re-parameterized deformed shifting module increases model capacity and flexibility without increasing inference time.
  • Slide-Attention achieves state-of-the-art results on ImageNet-1K, ADE20K, and COCO benchmarks when integrated into Swin, PVT, and CSwin architectures.
  • The ablation study confirms that the row-based re-interpretation and depthwise convolution substitution significantly reduce computation cost compared to standard Im2Col-based implementations.

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.