使用動態剪枝之硬體高效 Vision Transformer 加速器

Hardware Efficient Vision Transformer Accelerator with Dynamic Pruning

檔案

日期

2024

類型

語言

英文

摘要

Transformer模型的出現顯著改變了深度學習的格局。這些模型最初因其在自然語言處理中的成功而受到廣泛關注,隨後也被應用於各種計算機視覺任務,例如圖像分類。早期的加速器設計主要針對自然語言處理任務,近來一些加速器已經進化到同時支持視覺任務和自然語言處理,但重點仍然是優化自注意力機制。這種關注源於自注意力機制在自然語言處理中,尤其是在處理長token序列時,成為明顯的瓶頸,因為它的數據依賴性以及隨著token長度增加,計算複雜度以二次方方式增長。然而,這些設計往往忽略了在視覺應用中,由於token長度通常較短,反而是前饋神經網絡需要更多的計算資源,使其成為此類場景下更為顯著的瓶頸。

本研究提出了一種通過算法與硬體協同設計並結合動態剪枝優化的高效能Vision Transformer加速器。我們採用了一種基於類別注意力和top-k選擇的硬體友好型動態token剪枝方法,在僅損失1.4\%準確度的情況下,將運算量減少了54\%,而且不需要複雜的機制。此外,我們逐層將GELU替換為ReLU,使模型更適合硬體實現,並增加了後激活稀疏性,同時僅帶來0.04\%的準確度損失。這種增強的稀疏性使得我們能夠進一步通過動態FFN2剪枝來優化模型運算,最終實現了全面的模型加速。總體而言,我們的設計在保持準確度損失在2\%以內的情況下,將運算量減少了61.5\%,大大提升了性能和硬體效率。

在我們的硬體設計中,我們採用逐層計算的方法來處理每個Vision Transformer編碼器模塊,其中QKV生成和自注意力機制是通過head-level管線逐個head順序執行的。FFN的計算根據剪枝需求進行動態調整。我們設計了一個具有極小開銷的動態剪枝模塊,它不僅減少了計算負荷,還降低了從外部記憶體獲取數據的量。具體來說,token剪枝使總token數量減少了56.4\%,而FFN2剪枝使所需的FFN2權重減少了59.3\%。在TSMC的28nm CMOS技術下,我們的設計需要496.4K個邏輯閘和232KB的SRAM緩衝區,在1GHz的頻率下達到1024 GOPS的峰值吞吐量,能效為2.31 TOPS/W,面積效率為858.61 GOPS/mm²。
The emergence of transformer models has significantly transformed the deep learning landscape. Initially celebrated for their success in natural language processing (NLP), transformers have since been applied to various computer vision tasks, such as image classification. Early accelerator designs were primarily tailored for NLP tasks, and more recently, some have evolved to support both vision tasks and NLP, with a strong emphasis on optimizing self-attention mechanisms. This focus stems from self-attention being a clear bottleneck in NLP, especially when dealing with large token lengths, due to its data dependencies and quadratic growth in computational complexity relative to token length. However, these designs often overlook the fact that in vision applications, where token lengths are typically shorter, the Feed-Forward Network (FFN) tends to demand more computational resources, making it a more significant bottleneck in such contexts.

This work introduces a hardware-efficient Vision Transformer accelerator, optimized through algorithm-hardware co-design with dynamic pruning. We employed a hardware-friendly dynamic token pruning method based on class attention and top-k selection, reducing MACs by 54\% with just a 1.4\% accuracy loss, without requiring complex mechanisms. Additionally, we replaced GELU with ReLU layer-by-layer, making the model more hardware-compatible and increasing post-activation sparsity, all while maintaining a 0.04\% accuracy loss. This enhanced sparsity enabled further optimization through dynamic FFN2 pruning, leading to comprehensive model acceleration. Overall, our design achieves a 61.5\% reduction in MACs while keeping accuracy loss within 2\%, offering significant improvements in performance and hardware efficiency.

In our hardware design, we employ a layer-by-layer computation approach for each Vision Transformer encoder block, where QKV generation and self-attention are executed using a head-level pipeline, processing each head sequentially. The FFN computations are dynamically adjusted based on the pruning requirements. We designed a dynamic pruning module with minimal overhead, which not only reduces the computational load but also decreases the amount of data fetched from external memory. Specifically, token pruning reduces the total token count by 56.4\%, and FFN2 pruning decreases the required FFN2 weights by 59.3\%. Implemented in TSMC's 28nm CMOS technology, our design requires 496.4K gate count and 232KB of SRAM buffer, achieving a peak throughput of 1024 GOPS at 1GHz, with an energy efficiency of 2.31 TOPS/W and an area efficiency of 858.61 GOPS/mm².

所屬典藏

電子研究所
顯示完整詮釋資料 統計資料

引用此條目

Hsiung, C.-L. (2024). Hardware Efficient Vision Transformer Accelerator with Dynamic Pruning. https://thesis.lib.nycu.edu.tw/handle/20.500.14371/4065

BibTeX RIS

引用文字依 APA 第 7 版格式自動產生,使用前請再核對。

分享

永久網址:https://thesis.lib.nycu.edu.tw/handle/20.500.14371/4065