Post-Training Quantization for Vision Transformer

TL;DR

Proposed a post-training quantization algorithm for vision transformers, achieving 81.29% top-1 accuracy on ImageNet with DeiT-B model.

cs.CV 🔴 Advanced 2021-06-27 3 views
Zhenhua Liu Yunhe Wang Kai Han Siwei Ma Wen Gao
Vision Transformer Post-Training Quantization Mixed Precision Attention Mechanism Model Compression

Key Findings

Methodology

The paper introduces a mixed-precision post-training quantization method, integrating similarity-aware quantization and ranking loss to optimize quantization intervals for vision transformers. It analyzes feature diversity across layers using nuclear norm to dynamically allocate bit-widths while preserving attention mechanism functionality.

Key Results

  • Achieved 81.29% top-1 accuracy on ImageNet with DeiT-B model, outperforming existing post-training quantization algorithms.
  • On CIFAR-10, the 8-bit quantized ViT-B model achieved 97.79% accuracy.
  • On COCO2017, the 8-bit quantized DETR model achieved 41.7 mAP.

Significance

This study significantly reduces memory and computational costs for vision transformers, making them more suitable for deployment on resource-constrained devices. It provides performance comparable to full-precision models without additional training, advancing transformer applications in industrial environments.

Technical Contribution

Building on existing quantization methods, the paper introduces a mixed-precision strategy combining ranking loss for attention mechanisms and nuclear norm analysis, offering new insights and technical guarantees for compressing vision transformers.

Novelty

This is the first to introduce ranking loss into the quantization process of vision transformers to preserve the relative order of attention mechanisms and dynamically adjust layer bit-widths using nuclear norm.

Limitations

  • Performance may significantly degrade at extremely low bit-widths, especially in complex tasks.
  • The method relies on nuclear norm calculations, which may increase computational complexity.

Future Work

Future research could explore applications in more vision tasks, such as video understanding and semantic segmentation, and optimize the efficiency of nuclear norm calculations.

AI Executive Summary

Transformers have recently achieved remarkable success in computer vision, but their complex architectures make deployment on mobile devices challenging. This paper presents an effective post-training quantization algorithm to reduce the memory and computational costs of vision transformers. By introducing a ranking loss to preserve the functionality of the attention mechanism and analyzing feature diversity across layers using nuclear norm, the paper explores a mixed-precision quantization scheme. Experimental results demonstrate that this method outperforms existing post-training quantization algorithms across several benchmark models and datasets. For instance, an 81.29% top-1 accuracy was achieved on the ImageNet dataset using the DeiT-B model with approximately 8-bit quantization. This research provides new insights for compressing vision transformers, promoting their application in industrial environments. However, the method may face performance degradation at extremely low bit-widths, and future work could further optimize nuclear norm calculations and explore applications in more vision tasks.

Deep Analysis

Background

Transformers initially succeeded in natural language processing and have recently been applied to computer vision tasks such as image classification, object detection, and image super-resolution. Compared to traditional convolutional neural networks, vision transformers have more complex architectures, often requiring large amounts of parameters and computational resources, posing challenges for deployment on resource-constrained devices.

Core Problem

The complexity of vision transformers makes them difficult to deploy on mobile devices, particularly when memory and computational resources are limited. The challenge is to compress transformer models to meet the needs of edge devices without significantly degrading model performance.

Innovation

The paper's innovation lies in proposing a mixed-precision post-training quantization method that combines ranking loss and nuclear norm analysis. Ranking loss is used to maintain the relative order of the attention mechanism, while nuclear norm analysis dynamically adjusts layer bit-widths, achieving efficient model compression without additional training.

Methodology

  • �� Introduced a mixed-precision quantization method combining similarity-aware quantization and ranking loss.
  • �� Analyzed feature diversity across layers using nuclear norm to dynamically allocate bit-widths.
  • �� Introduced bias correction during quantization to reduce cumulative quantization error.
  • �� Employed an alternating search strategy to optimize quantization intervals.

Experiments

Experiments were conducted on CIFAR-10, CIFAR-100, ImageNet, and COCO2017 datasets using vision transformer models like ViT and DeiT. A subset of training data was randomly selected as a calibration dataset, and different bit-widths were set for quantization experiments, compared against existing quantization methods.

Results

On ImageNet, the 8-bit quantized DeiT-B model achieved 81.29% top-1 accuracy, outperforming existing methods. On CIFAR-10, the 8-bit quantized ViT-B model achieved 97.79% accuracy. On COCO2017, the 8-bit quantized DETR model achieved 41.7 mAP.

Applications

This method is suitable for deploying vision transformer models on resource-constrained devices like smartphones and IoT devices. By reducing memory and computational requirements, it enables efficient model compression without significantly degrading performance.

Limitations & Outlook

Performance may significantly degrade at extremely low bit-widths, especially in complex tasks. The method relies on nuclear norm calculations, which may increase computational complexity. Future research could further optimize nuclear norm calculations and explore applications in more vision tasks.

Plain Language Accessible to non-experts

Imagine a factory that originally requires a large number of workers to complete complex production tasks. To save costs, we decide to have each worker handle multiple tasks simultaneously without compromising product quality. We introduce a new management method that analyzes each worker's efficiency to allocate tasks reasonably, allowing the factory to maintain high efficiency while reducing the number of workers. This is like the quantization method proposed in the paper, which dynamically adjusts computational precision by analyzing feature diversity at each layer, reducing computational resources while maintaining high model performance.

ELI14 Explained like you're 14

Imagine you're playing a massive multiplayer online game with many characters, each with their own skills and equipment. To make the game run smoothly on your phone, you need to reduce its memory usage. You can decide which skills can be implemented with fewer resources without affecting the gaming experience by analyzing the importance of each character's skills. This is like the quantization method in the paper, which dynamically adjusts computational precision by analyzing feature diversity at each layer, reducing computational resources while maintaining high model performance.

Glossary

Vision Transformer

A vision model based on the Transformer architecture capable of processing image data.

Used for tasks like image classification and object detection.

Post-Training Quantization

Compresses a model by using lower bit-widths without changing the architecture.

Used to reduce memory and computation costs of vision transformers.

Mixed-Precision Quantization

A quantization method that dynamically allocates bit-widths based on feature diversity.

Used to improve quantized model performance.

Ranking Loss

A loss function used to maintain the relative order of attention mechanisms after quantization.

Used in the quantization process of vision transformers.

Nuclear Norm

The sum of singular values of a matrix, representing data relevance.

Used to analyze feature diversity across layers.

Open Questions Unanswered questions from this research

  • 1 How to maintain model performance at extremely low bit-widths? Existing methods may significantly degrade in complex tasks.
  • 2 How to optimize the efficiency of nuclear norm calculations? Computational complexity may affect practical applications.

Applications

Immediate Applications

Smartphone Applications

By reducing memory and computational requirements, vision transformers can run efficiently on smartphones.

Long-term Vision

IoT Devices

Deploy efficient vision transformers on IoT devices for intelligent monitoring and analysis.

Abstract

Recently, transformer has achieved remarkable performance on a variety of computer vision applications. Compared with mainstream convolutional neural networks, vision transformers are often of sophisticated architectures for extracting powerful feature representations, which are more difficult to be developed on mobile devices. In this paper, we present an effective post-training quantization algorithm for reducing the memory storage and computational costs of vision transformers. Basically, the quantization task can be regarded as finding the optimal low-bit quantization intervals for weights and inputs, respectively. To preserve the functionality of the attention mechanism, we introduce a ranking loss into the conventional quantization objective that aims to keep the relative order of the self-attention results after quantization. Moreover, we thoroughly analyze the relationship between quantization loss of different layers and the feature diversity, and explore a mixed-precision quantization scheme by exploiting the nuclear norm of each attention map and output feature. The effectiveness of the proposed method is verified on several benchmark models and datasets, which outperforms the state-of-the-art post-training quantization algorithms. For instance, we can obtain an 81.29\% top-1 accuracy using DeiT-B model on ImageNet dataset with about 8-bit quantization.

cs.CV