NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Improving Transformers with Dynamically Composable Multi-Head Attention

Da Xiao, Qingye Meng, Shengping Li, xingyuan yuan

TL;DR

Dynamically Composable Multi-Head Attention (DCMHA) breaks the "silo" approach of standard Transformers by allowing attention heads to collaborate dynamically based on the input sequence. This simple architectural shift allows a 7B parameter model to outperform a 12B parameter baseline, effectively matching the performance of models trained with nearly double the compute.

The Problem with Standard Multi-Head Attention

In a standard Transformer, Multi-Head Attention (MHA) consists of several "heads" that operate in parallel and complete independence. While this design is simple and scales well, it suffers from two major flaws:

  1. Low-rank Bottleneck: Individual attention matrices often lack the expressive power to represent complex relationships between tokens.
  2. Head Redundancy: Many heads end up learning similar patterns, wasting precious parameters and computational resources.

Previous attempts to fix this either combined head outputs (which is too "surface-level") or composed the linear projections themselves (which is computationally expensive and often static). The authors sought a middle ground that is dynamic, expressive, and efficient enough for large-scale training.

Dynamically Composable Multi-Head Attention (DCMHA)

To address these flaws, the authors introduce DCMHA, a drop-in replacement for standard MHA. The core innovation is a Compose function that transforms attention matrices (both the scores before softmax and the weights after) in an input-dependent way.

Dynamic Composition Patterns

Key technical highlights include:

  • Dynamic Composition: Unlike previous "static" methods, the way heads interact in DCMHA changes based on the specific queries and keys in the input sequence.
  • Five-Branch Architecture: The Compose function uses five parallel branches—including a base projection, query-wise gating/projections, and key-wise gating/projections—to allow heads to "share" information.
  • Efficient Decomposition: To avoid the massive computational cost of materializing 4D transformation tensors, the authors use a "row plus column" tensor decomposition. This keeps the parameter and FLOP overhead minimal.
  • DCFormer: By swapping MHA for DCMHA, any standard Transformer architecture (like GPT or LLaMA) becomes a "DCFormer."

Key Insights: Collaboration Over Independence

The primary breakthrough is the realization that heads don't need to be larger; they just need to communicate. By allowing a head to "borrow" the search pattern (QK circuit) of another head while keeping its own transformation logic (OV circuit), the model becomes significantly more capable.

Mechanistic analysis revealed that DCMHA significantly increases the diversity of attention circuits. In standard Transformers, heads often become redundant; in DCFormers, they maintain unique, specialized roles. Furthermore, the paper shows that making this composition input-dependent is what unlocks scaling-law-level improvements, far surpassing static composition methods like Talking-Heads Attention.

Evaluation and Results

The models were rigorously tested across multiple domains, including language modeling (pretrained on The Pile up to 300B tokens), a suite of standard NLP benchmarks (LAMBADA, PIQA, WinoGrande, ARC, etc.), and vision tasks (ImageNet-1K).

  • Compute Efficiency: DCFormer consistently matches the performance of standard Transformers that use 1.7x to 2.0x more compute.
  • Outperforming Larger Models: The authors' DCPythia-6.9B model outperformed the open-source Pythia-12B on both pretraining perplexity and a wide range of downstream NLP tasks.
  • Vision Gains: In the vision domain, a DCViT-S/16 (22M parameters) performed on par with a ViT-M/16 (39M parameters), which is nearly double its size.
  • Scaling Laws: The relative improvement of DCMHA over standard baselines holds steady or improves as models scale, suggesting it is a fundamental architectural upgrade rather than a "small model trick."

Limitations and Future Work

While DCMHA is compute-efficient in terms of total FLOPs required to reach a specific performance level, it introduces a real-world training overhead (roughly 10-25% slower throughput) and inference overhead (5-12%). This is primarily due to I/O bottlenecks in current deep learning frameworks. The authors note that writing custom CUDA kernels—similar to FlashAttention—could significantly mitigate this speed penalty.

Additionally, it is difficult to "convert" a standard pretrained Transformer into a DCFormer via finetuning; to realize the full benefits, the model generally needs to be trained with DCMHA from scratch.

Summary updated

BibTeX
@inproceedings{xiao2024improving,
  author = {Da Xiao and Qingye Meng and Shengping Li and xingyuan yuan},
  title = {{Improving Transformers with Dynamically Composable Multi-Head Attention}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=RbiBKPtuHp},
}
Figure