支援窗口注意力及金字塔結構之高效端對端Transformer加速器設計

An Efficient End-to-End Transformer Accelerator Supporting Window Attention and Pyramid Structure

檔案

全文將於 2029年8月28日 起公開。

日期

2024

類型

語言

英文

摘要

於2020年,Google首次在電腦視覺領域成功應用了Transformer架構,取得了顯著的成效。這一創新促使越來越多基於Transformer的模型被開發出來。為了克服傳統柱狀Transformer在處理視覺任務時的限制,如視角的單一性和高解析度計算帶來的運算資源和記憶體龐大需求,金字塔結構的Transformer因應而生。到了2021年,為進一步解決高解析度計算的挑戰並克服全局注意力機制在專注局部訊息上的不足,Microsoft提出了窗口注意力機制。此方法透過將特徵圖分割為多個窗口,並在每個窗口內進行自注意計算,有效捕獲局部特徵並降低計算量。
然而,這些機制往往需仰賴額外的CPU計算力進行前後處理來實現,這不僅增加了系統中記憶體資料傳輸的負擔,還可能需要特殊硬體單元來進行資料的重新排列。隨著圖片解析度的提升和自注意力機制(如窗口注意力)的複雜化,這些額外的CPU資料處理和特殊硬體單元皆可能成為系統效能的瓶頸,因而無法達到預期的硬體性能峰值。
本篇論文提出一個支援窗口注意力機制和金字塔結構的高效率Transformer加速器設計。本加速器採用帶狀(Strip)分解的資料流,將輸入和權重特徵圖分解為帶狀後再進行運算,其優點在於當輸入特徵圖解析度低時可確保權重只需被讀取一次,於降低系統匯流排負擔的同時維持矩陣運算引擎的高利用率。在處理高解析度特徵圖的情況,本加速器採用彈性矩陣分解(Flexible Matrix Decomposition),根據輸入和輸出特徵圖的大小及內部SRAM的容量,決定特徵圖分解的方式,以確保輸入特徵圖只需從DRAM中被讀取一次;輸出特徵圖則允許寫回SRAM或透過輸出交替緩衝(Output Ping-Pong Buffer)機制,在計算核心運行的同時將結果寫回DRAM。本加速器支援多運算融合(Multi-Operation Fusion),可將兩個乃至更多的運算透過矩陣分解合併運算,確保多個運算間的矩陣結果不需寫回DRAM,大幅降低對DRAM的存取次數和對資料匯流排的負擔,並同時保持矩陣運算引擎的高利用率。本加速器亦支援列狀(Row)分解資料流,以支援金字塔結構中連接兩不同解析度特徵圖間的下採樣(Down-sample)運算。在考慮DRAM讀寫延遲的情況下,本加速器實際推理DeiT-S與CSwin-S模型時,矩陣運算引擎之利用率分別高達90.04%與78.56%。
本加速器針對多樣化的運算需求,如矩陣分解、窗口注意力和卷積運算,設計了一個多模運算位址產生器(Multi-Mode Address Generator)。在進行矩陣運算時,能根據不同的彈性拆解方式產生相對應的輸入和輸出位址;在運算窗口注意力運算時,能依據不同的矩形窗口大小,取出相對應的權重及輸入輸出位址;在卷積運算中,則根據不同步長、填充和卷積核尺寸,產生器能自動產生相應的資料位址並執行補零操作。該多模運算位址產生器的設計,使本加速器內所有資料處理無需CPU介入,從而實現高效率運算。本加速器亦具備向量運算引擎,處理Softmax、LayerNorm等向量運算,以減少矩陣運算引擎之功耗。本加速器之指令集將多數運算獨立作為單一指令,提供更高的模型支援度和設計彈性。
本加速器亦部署至AMD-Xilinx ZCU106開發板,並建立了人像分割背景疊合系統以展示本加速器之功能完整度與性能。本加速器支援非對稱量化模型,大幅降低計算精確度的損失,且經非對稱量化之人像分割模型相比在浮點數運算下的模型,僅有1.2%的AUC損失。本加速器設計亦充分考量整合需求,所有資料皆透過AXI-4匯流排存取,利於未來晶片整合工作。
本加速器於台積電40奈米製程下進行電路合成、佈局與繞線,操作頻率最高可達1 GHz,效能峰值為每秒3,264 GOPS,核心面積效率與核心能源效率分別為1,866.8 GOPS/mm2和5.46 TOPS/W,表現十分卓越。
In 2020, Google successfully applied the Transformer architecture in the field of computer vision (CV) for the first time, achieving significant results. This innovation spurred the development of an increasing number of Transformer-based CV models. To overcome the limitations of traditional columnar Transformers in processing CV tasks, such as the singularity of perspective and the substantial demand for computational resources and memory due to high-resolution calculations, the pyramid-structured Transformer was thus introduced. In 2021, Microsoft proposed the window attention mechanism to address the challenges of high-resolution computing further and the inadequacies of the global attention mechanism in focusing on local information. This method effectively captures local features by dividing a feature map into multiple windows and performing self-attention calculations within each window, thereby reducing the computational load.
However, these mechanisms often rely on additional CPU pre- and post-processing, which not only increases the burden of memory transfers within the system but may also require specialized hardware units for data reordering. As image resolutions increase and self-attention mechanisms (e.g., window attention) become even more complex, these extra CPU data processing tasks and specialized hardware units could turn into bottlenecks in system performance, preventing the system from reaching its expected peak efficiency.
In this thesis, an efficient Transformer accelerator supporting window attention mechanism and pyramid structure is proposed. The accelerator adopts a strip-based dataflow, decomposing input and weight feature maps into strips for computing. This dataflow is particularly advantageous while handling low-resolution input feature maps, as it ensures weights are read from DRAM only once, thus reducing the system bus load and keeping the matrix computation engine highly utilized. For high-resolution feature maps, the accelerator adopts the Flexible Matrix Decomposition alternatively. This method tailors the decomposition of feature maps according to their size and the available SRAM capacity. It ensures that the input feature map is fetched only once from DRAM; as for the output feature map, there are two efficient handling options: it can either be directly written back to SRAM or written back to DRAM with the Output Ping-Pong Buffer mechanism, which allows data to be written back to DRAM concurrently during the computation, improving the overall system efficiency. Moreover, the accelerator supports the Multi-Operation Fusion, integrating two or more operations through matrix decomposition. This technique prevents the need for intermediate matrix results from multiple operations to be written back to DRAM, dramatically lowering the frequency of DRAM access and data bus load, thereby maintaining high utilization of the matrix engine. Additionally, the accelerator supports the row-based dataflow, which is essential for performing down-sampling operations that connect feature maps of varying resolutions in the pyramid structure.
The accelerator is also equipped with a Multi-Mode Address Generator (MMAG) for diverse computing requirements, such as matrix decomposition, window attention and convolution. During matrix computations, the MMAG generates corresponding input and output addresses based on different flexible decomposition methods. For window attention operations, it determines the addresses of weight, input and output according to the size of various rectangular windows. In convolution computations, the MMAG produces relevant data addresses and executes necessary zero-padding operation based on varying stride, padding, and convolution kernel size. The design of this multi-mode address generator eliminates the need for CPU intervention in all data rearrangement within the accelerator, thereby achieving high-efficiency computations.
Besides, the accelerator includes a vector engine to handle vector operations like Softmax and LayerNorm, which helps reduce the power consumption of the matrix engine. The proposed instruction set handles most operations as single instructions, providing great model support and design flexibility.
The accelerator has been deployed on an AMD-Xilinx ZCU106 evaluation board, where a portrait segmentation system was established to showcase the functional integrity and performance of the proposed accelerator. Furthermore, the accelerator supports asymmetric quantization to minimize the model accuracy loss. Compared with the model under floating point operations, the asymmetrically quantized portrait segmentation model has only 1.2% AUC loss. Additionally, the proposed accelerator takes integration needs into full account. All data are accessed via the AXI-4 bus, which facilitates chip integration work.
The proposed accelerator design has been synthesized and undergone placement and routing with the TSMC 40nm library at the TT corner (0.9V, 25℃) using Synopsys Design Compiler and Cadence Innovus with an operating frequency of 1 GHz. Its peak performance reaches 3,264 GOPS. For core area efficiency and core energy efficiency, it achieves 1,866.8 GOPS/mm² and 5.46 TOPS/W, respectively, showcasing outstanding performance.

所屬典藏

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

引用此條目

Kuo, P.-H. (2024). An Efficient End-to-End Transformer Accelerator Supporting Window Attention and Pyramid Structure. https://thesis.lib.nycu.edu.tw/handle/20.500.14371/4040

BibTeX RIS

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

分享

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