Accelerating ViT Inference on FPGA through Static and Dynamic Pruning

Dhruv Parikh, Shouyi Li, Bingyi Zhang, Rajgopal Kannan, Carl E. Busart, Viktor K. Prasanna

Abstract

Vision Transformers (ViTs) have achieved state-of-the-art performance in computer vision tasks but face significant deployment challenges due to their high computational complexity. This paper presents a hardware-algorithm codesign framework that optimizes ViT inference by combining static weight pruning with dynamic token pruning. By leveraging the reconfigurable nature of FPGAs, the proposed architecture addresses the irregular computation patterns inherent in dual-pruning strategies. Experimental results on the ImageNet dataset using DeiT-Small demonstrate that this approach achieves up to a 12.8× speedup over high-end CPUs and a 3.2× speedup over modern GPUs, while maintaining a competitive accuracy profile through knowledge distillation.

Introduction

Vision Transformers (ViTs) have revolutionized computer vision by applying the transformer architecture to image patches. However, their Multi-head Self-Attention (MSA) mechanism introduces a "computational tax" that scales quadratically with the number of input tokens. This makes real-time deployment on resource-constrained edge devices or even high-performance servers difficult.

To mitigate these costs, researchers typically employ two strategies: weight pruning (removing redundant model parameters) and token pruning (discarding less informative image patches). While effective individually, combining these techniques creates highly irregular data access and computation patterns. Standard processors, such as CPUs and GPUs, are optimized for dense, predictable workloads and often experience significant performance degradation when faced with such sparsity. This paper introduces a specialized hardware-algorithm codesign that enables efficient dual-pruning on Field-Programmable Gate Arrays (FPGAs).

Methodology

The proposed solution rests on a two-pillar approach: optimizing the model structure for hardware friendliness and designing a custom hardware architecture to handle the resulting sparsity.

1. Algorithmic Innovations

To ensure the pruned model remains performant on hardware, the authors implemented three key algorithmic strategies:

  • Static Block-Pruning: Rather than pruning individual weights at random, which leads to fine-grained sparsity that hardware cannot easily accelerate, the authors prune weights in structured blocks. This maintains a level of regularity that allows for efficient parallel processing.
  • Dynamic Token Pruning: The researchers integrated a Token Dropping Module (TDM). This module evaluates attention scores during inference to identify and fuse "inattentive" tokens. By discarding redundant tokens on the fly, the model significantly reduces the workload for subsequent layers.
  • Knowledge Distillation: To compensate for the potential accuracy loss associated with aggressive pruning, a "teacher-student" training regime was employed. A full-sized, pre-trained ViT (the teacher) guides the training of the pruned model (the student), helping it retain critical features.

2. Hardware Architecture (FPGA)

The flexibility of FPGAs allows for a customized data path that can handle the irregularities of dual-pruning. The hardware design includes:

  • Multi-level Parallelism Compute Array (MPCA): A custom compute engine designed to manage the non-linear data access patterns caused by block-pruning.
  • Dynamic Load Balancing: Because different parts of the weight matrix have varying levels of sparsity, the hardware dynamically redistributes tasks across processing elements. This ensures high utilization (over 85%) and prevents bottlenecks where some units are idle while others are overloaded.
  • Token Dropping Hardware Module (TDHM): This specialized unit handles the sorting and reordering of tokens in real-time. This is a critical component, as the shuffling and management of dynamic tokens is a task where traditional GPUs typically struggle due to fixed pipeline constraints.

Experimental Results

The framework was evaluated using the DeiT-Small model on the ImageNet dataset, which consists of 1.2 million images across 1,000 categories.

Performance and Efficiency

The hardware-algorithm codesign yielded substantial improvements in inference speed and efficiency:

  • Latency: The FPGA implementation achieved a 12.8× speedup compared to an AMD EPYC CPU and a 3.2× speedup over an NVIDIA RTX 6000 Ada GPU.
  • Compression: The approach reduced overall computational complexity by 3.4× and achieved a model compression ratio of 1.6×.
  • Accuracy: These efficiency gains were achieved with a manageable accuracy trade-off, resulting in approximately a 3% drop from the baseline model.

Discussion and Future Work

The "aha moment" of this research lies in the synergy between the algorithm and the hardware fabric. While GPUs rely on rigid, high-throughput pipelines, the FPGA's ability to implement a specific "shuffling engine" allows it to handle dynamic token pruning without the latency penalties that usually negate the benefits of pruning on other platforms.

One identified limitation is the training duration; the models were trained for only 30 epochs. The authors suggest that longer training cycles could further bridge the accuracy gap, as pruned models typically require more time to converge.

Looking forward, the team aims to develop a design automation framework. This tool would allow users to input a specific ViT model and a target FPGA, automatically generating the optimal pruning configuration and hardware bitstream, thereby democratizing high-performance ViT inference for non-specialists.

Summary updated

Abstract

Vision Transformers (ViTs) have achieved state-of-the-art accuracy on various computer vision tasks. However, their high computational complexity prevents them from being applied to many real-world applications. Weight and token pruning methods are well-known in reducing ViT model complexity. However, naively combining and integrating both the methods results in irregular computation patterns leading to accuracy drops and difficulties in hardware acceleration. This limits the net complexity reduction offered by integrating such pruning methods. To address the above challenges, we propose a comprehensive algorithm-hardware codesign for accelerating ViT on FPGA through simultaneous pruning - combining static weight pruning and dynamic token pruning. For algorithm design, we systematically combine a hardware-aware structured block-pruning method for pruning model parameters and a dynamic token pruning method for removing unimportant token vectors. Moreover, we design a novel training algorithm to reduce the accuracy drop due to such simultaneous pruning. For hardware design, we develop a novel hardware accelerator for executing the pruned model. The proposed hardware design employs multi-level parallelism with a load-balancing strategy to efficiently deal with the irregular computation pattern presented by the two pruning approaches. Moreover, we develop an efficient hardware mechanism for executing the on-the-fly token pruning. We apply our codesign approach to the widely used DeiT-Small model. We implement the proposed accelerator on a state-of-the-art FPGA. The evaluation results show that the proposed algorithm reduces computation complexity by up to 3.4× with ≈ 3% accuracy drop and a model compression ratio of up to 1.6×. Compared with state-of-the-art implementation on CPU, GPU, and FPGA, our codesign on FPGA achieves an average latency reduction of 12.8×, 3.2×, and 0.7 – 2.1×, respectively.
BibTeX
@inproceedings{parikh2024accelerating,
  author = {Dhruv Parikh and Shouyi Li and Bingyi Zhang and Rajgopal Kannan and Carl E. Busart and Viktor K. Prasanna},
  title = {{Accelerating ViT Inference on FPGA through Static and Dynamic Pruning}},
  booktitle = {FCCM},
  year = {2024},
  url = {https://openreview.net/forum?id=UDP2hbocAO},
}
Figure