MemoryFormer: Minimize Transformer Computation by Removing Fully-Connected Layers

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Ding, Ning, Tang, Yehui, Qin, Haochen, Zhou, Zhenli, Xu, Chao, Li, Lin, Han, Kai, Liao, Heng, Wang, Yunhe
Format: Preprint
Published: 2024
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866918320064692224
author Ding, Ning
Tang, Yehui
Qin, Haochen
Zhou, Zhenli
Xu, Chao
Li, Lin
Han, Kai
Liao, Heng
Wang, Yunhe
author_facet Ding, Ning
Tang, Yehui
Qin, Haochen
Zhou, Zhenli
Xu, Chao
Li, Lin
Han, Kai
Liao, Heng
Wang, Yunhe
contents In order to reduce the computational complexity of large language models, great efforts have been made to to improve the efficiency of transformer models such as linear attention and flash-attention. However, the model size and corresponding computational complexity are constantly scaled up in pursuit of higher performance. In this work, we present MemoryFormer, a novel transformer architecture which significantly reduces the computational complexity (FLOPs) from a new perspective. We eliminate nearly all the computations of the transformer model except for the necessary computation required by the multi-head attention operation. This is made possible by utilizing an alternative method for feature transformation to replace the linear projection of fully-connected layers. Specifically, we first construct a group of in-memory lookup tables that store a large amount of discrete vectors to replace the weight matrix used in linear projection. We then use a hash algorithm to retrieve a correlated subset of vectors dynamically based on the input embedding. The retrieved vectors combined together will form the output embedding, which provides an estimation of the result of matrix multiplication operation in a fully-connected layer. Compared to conducting matrix multiplication, retrieving data blocks from memory is a much cheaper operation which requires little computations. We train MemoryFormer from scratch and conduct extensive experiments on various benchmarks to demonstrate the effectiveness of the proposed model.
format Preprint
id arxiv_https___arxiv_org_abs_2411_12992
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle MemoryFormer: Minimize Transformer Computation by Removing Fully-Connected Layers
Ding, Ning
Tang, Yehui
Qin, Haochen
Zhou, Zhenli
Xu, Chao
Li, Lin
Han, Kai
Liao, Heng
Wang, Yunhe
Computation and Language
In order to reduce the computational complexity of large language models, great efforts have been made to to improve the efficiency of transformer models such as linear attention and flash-attention. However, the model size and corresponding computational complexity are constantly scaled up in pursuit of higher performance. In this work, we present MemoryFormer, a novel transformer architecture which significantly reduces the computational complexity (FLOPs) from a new perspective. We eliminate nearly all the computations of the transformer model except for the necessary computation required by the multi-head attention operation. This is made possible by utilizing an alternative method for feature transformation to replace the linear projection of fully-connected layers. Specifically, we first construct a group of in-memory lookup tables that store a large amount of discrete vectors to replace the weight matrix used in linear projection. We then use a hash algorithm to retrieve a correlated subset of vectors dynamically based on the input embedding. The retrieved vectors combined together will form the output embedding, which provides an estimation of the result of matrix multiplication operation in a fully-connected layer. Compared to conducting matrix multiplication, retrieving data blocks from memory is a much cheaper operation which requires little computations. We train MemoryFormer from scratch and conduct extensive experiments on various benchmarks to demonstrate the effectiveness of the proposed model.
title MemoryFormer: Minimize Transformer Computation by Removing Fully-Connected Layers
topic Computation and Language
url https://arxiv.org/abs/2411.12992