Quasar-ViT: Hardware-Oriented Quantization-Aware Architecture Search for Vision Transformers

Zhengang Li, Alec Lu, Yanyue Xie, Zhenglun Kong, Mengshu Sun, Hao Tang, Zhong Jia Xue, Peiyan Dong, Caiwen Ding, Yanzhi Wang, Xue Lin, Zhenman Fang

Quasar-ViT: Making Vision Transformers Edge-Ready via Hardware-Algorithm Co-Design

TL;DR

Quasar-ViT is a hardware-oriented framework that optimizes Vision Transformers (ViTs) for resource-constrained edge devices using a co-design approach. By combining a novel "weight entanglement" training strategy with flexible row-wise mixed-precision quantization and specialized FPGA hardware acceleration, it achieves up to 251.6 FPS on an AMD/Xilinx ZCU102 with high accuracy.

What Problem Does This Paper Address?

Vision Transformers (ViTs) have surpassed Convolutional Neural Networks (CNNs) in accuracy for many tasks, but they are notoriously "heavy." Their reliance on massive matrix multiplications (MatMuls) makes them difficult to deploy on edge devices like FPGAs, which have limited memory and compute resources.

The authors identify two main gaps:

  1. Quantization Inefficiency: Standard quantization (reducing bit-widths) is often either too coarse (layer-wise) to maintain accuracy or too irregular (kernel-wise) for hardware to process efficiently.
  2. The NAS-Quantization Silo: Neural Architecture Search (NAS) and quantization are typically treated as separate steps, leading to suboptimal models that don't fully exploit the hardware's specific capabilities.

Methods

Quasar-ViT introduces an end-to-end pipeline that bridges the gap between high-level architecture and low-level hardware:

  • Row-Wise Flexible Mixed-Precision: Instead of quantizing an entire layer to one bit-width, Quasar-ViT allows different rows (channels) within a layer to have different precisions (e.g., a mix of 4-bit and 8-bit). This provides fine-grained accuracy control while remaining hardware-friendly.
  • Mixed-Precision Weight Entanglement: To train a "supernet" (a large model containing many smaller "subnets"), the authors developed a strategy where different subnets share weights even if they use different quantization levels. This prevents "bit-width conflicts" during training and reduces memory costs.
  • Supernet Layer Scaling (SLS): They adapted the layer scaling technique from CaiT to the supernet level, improving training stability and final model accuracy.
  • Hardware-Oriented Evolution Search: The search for the best model architecture is guided by a real-world latency and resource model of the target FPGA, rather than just theoretical FLOPs.
  • Hybrid DSP Packing: On the hardware side, they implemented a custom GEMM (General Matrix Multiply) engine that "packs" three or four 4-bit multiplications into a single DSP block on the FPGA, drastically increasing throughput.

Datasets

  • ImageNet-1k: The primary benchmark for evaluating the accuracy and efficiency of the searched ViT models.
  • WikiText-2: Used in a secondary experiment to demonstrate the framework's scalability to Large Language Models (LLMs) like LLaMA-7B.

Key Insights and Ideas

  • MatMuls are the Bottleneck: Profiling showed that matrix multiplications account for 87% to 95% of a ViT's execution cycles. Targeting these specifically yields the highest ROI for optimization.
  • Hardware-Algorithm Symmetry: The "aha moment" is the unification of atomic computation. By designing hardware units that handle 4-bit operations natively and decomposing 8-bit operations into these 4-bit units, the system maintains high hardware utilization regardless of the mixed-precision ratio chosen by the NAS.
  • Co-design is Mandatory: The paper demonstrates that you can't just "search then quantize." The quantization scheme must be baked into the search space and the training process to reach the Pareto front of accuracy vs. speed.

Key Results

The authors produced three main models (Quasar-S, L1, and L2) evaluated on an AMD/Xilinx ZCU102 FPGA:

  • Quasar-L2: Achieved 80.4% Top-1 accuracy at 101.5 FPS. This is 2.6× faster than a standard DeiT-S while being 0.5% more accurate.
  • Quasar-S: Achieved 74.9% Top-1 accuracy at a blistering 251.6 FPS.
  • Efficiency: Compared to prior state-of-the-art FPGA accelerators like Auto-ViT-Acc, Quasar-ViT achieves 1.7% better accuracy at similar speeds, or 1.6× better speed at similar accuracy levels.
  • LLM Scalability: When applied to LLaMA-7B, their quantization method reduced the model size from 26.8GB to 4.8GB with minimal impact on perplexity.

Limitations and Future Work

  • CPU Dependency: While the heavy MatMuls are on the FPGA, lightweight non-linear functions (like Softmax and LayerNorm) are still executed on the ARM CPU. While their impact is currently small, they could become a bottleneck as the GEMM engine gets even faster.
  • Hardware Specificity: The DSP packing optimizations are specifically tailored for the AMD/Xilinx DSP48E2 architecture. Porting these to other FPGA vendors or ASICs would require re-engineering the packing logic.
  • Future Direction: The authors suggest exploring even lower bit-widths (2-bit or binary) and expanding the co-design to include text-to-image and video applications.

Summary updated

BibTeX
@inproceedings{li2024quasar,
  author = {Zhengang Li and Alec Lu and Yanyue Xie and Zhenglun Kong and Mengshu Sun and Hao Tang and Zhong Jia Xue and Peiyan Dong and Caiwen Ding and Yanzhi Wang and Xue Lin and Zhenman Fang},
  title = {{Quasar-ViT: Hardware-Oriented Quantization-Aware Architecture Search for Vision Transformers}},
  booktitle = {ICS},
  year = {2024},
  doi = {10.1145/3650200.3656622},
}

Loading related content...

Figure