DenseFormer: Enhancing Information Flow in Transformers via Depth Weighted Averaging
Matteo Pagliardini, Amirkeivan Mohtashami, Francois Fleuret, Martin Jaggi
TL;DR
<3-5 sentence high-level summary> DenseFormer tackles the inefficiency of extreme Transformer depth by introducing a Depth Weighted Average (DWA) that aggregates current and all past block outputs after every transformer block, enabling strong inter-block information flow with only a small parameter overhead. The method uses learnable weights, initialization to act as an identity, and optional dilation and periodicity to control compute, yielding data-efficient improvements in perplexity and faster inference than deeper baselines. Empirically, DenseFormer beats same-depth Transformers, matches deeper models with fewer parameters and lower memory footprint, and shows robust gains on OpenWebText2 and PG-19, including longer sequences. Analyses of the learned DWA weights reveal stable, interpretable patterns that emphasize early representations and structured information reuse, supporting the proposed mechanism for improved information flow.
Abstract
The transformer architecture by Vaswani et al. (2017) is now ubiquitous across application domains, from natural language processing to speech processing and image understanding. We propose DenseFormer, a simple modification to the standard architecture that improves the perplexity of the model without increasing its size -- adding a few thousand parameters for large-scale models in the 100B parameters range. Our approach relies on an additional averaging step after each transformer block, which computes a weighted average of current and past representations -- we refer to this operation as Depth-Weighted-Average (DWA). The learned DWA weights exhibit coherent patterns of information flow, revealing the strong and structured reuse of activations from distant layers. Experiments demonstrate that DenseFormer is more data efficient, reaching the same perplexity of much deeper transformer models, and that for the same perplexity, these new models outperform transformer baselines in terms of memory efficiency and inference time.
