Improving Transformers with Dynamically Composable Multi-Head Attention

Da Xiao, Qingye Meng, Shengping Li, Xingyuan Yuan
5/14/2024
cs.LGcs.CL

Official code: Caiyun-AI/DCFormer (224 stars, MIT, last commit 2025-02-14).

Abstract

Multi-Head Attention (MHA) is a key component of Transformer. In MHA, attention heads work independently, causing problems such as low-rank bottleneck of attention score matrices and head redundancy. We propose Dynamically Composable Multi-Head Attention (DCMHA), a parameter and computation efficient attention architecture that tackles the shortcomings of MHA and increases the expressive power of the model by dynamically composing attention heads. At the core of DCMHA is a $\it{Compose}$ function that transforms the attention score and weight matrices in an input-dependent way. DCMHA can be used as a drop-in replacement of MHA in any transformer architecture to obtain the corresponding DCFormer. DCFormer significantly outperforms Transformer on different architectures and model scales in language modeling, matching the performance of models with ~1.7x-2.0x compute. For example, DCPythia-6.9B outperforms open source Pythia-12B on both pretraining perplexity and downstream task evaluation. The code and models are available at https://github.com/Caiyun-AI/DCFormer.

View on arXivView PDF

Code Implementations(1)

Caiyun-AI/DCFormerOfficial100%
MIT
22417Shell, PythonMay 11, 20241 years agoMIT

Similar Papers

Cite this paper

@article{xiao2024improving,
  title  = {Improving Transformers with Dynamically Composable Multi-Head Attention},
  author = {Da Xiao and Qingye Meng and Shengping Li and Xingyuan Yuan},
  year   = {2024},
  eprint = {2405.08553},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2405.08553v2},
  journal = {ICML 2024 2024}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2405.08553.svg)](https://codeofpaper.com/paper/2405.08553)

Discussion