Reducing the Transformer Architecture to a Minimum

Bernhard Bermeitinger, Tomas Hrycej, Massimo Pavone, Julianus Kath, Siegfried Handschuh · DOI

Abstract

Transformers have become the standard architecture for Natural Language Processing (NLP) and Computer Vision (CV), largely due to the success of the attention mechanism. However, these models are often heavily over-parameterized. This paper investigates whether the Multi-Layer Perceptron (MLP) components and complex attention matrices are strictly necessary. By systematically removing MLPs and simplifying the attention mechanism—including collapsing matrices and enforcing symmetry—we demonstrate that parameter counts can be reduced by up to 90% while maintaining comparable classification performance on MNIST and CIFAR-10 benchmarks.

Introduction: The Problem of Over-Parameterization

Since the introduction of the Transformer architecture, the trend has been toward increasingly massive models. A standard Transformer block pairs an attention mechanism with an MLP. The MLP is traditionally justified as providing the non-linearity required to model complex data. However, the attention mechanism itself is non-linear due to its internal similarity measures and softmax operations. This study tests the hypothesis that this inherent non-linearity is sufficient, allowing for the removal of parameter-heavy MLPs and the simplification of other components to create "Minimum Transformers."

Methodology: Deconstructing the Transformer

The researchers systematically simplified the Transformer architecture through four primary modifications:

  1. MLP Removal: The MLP blocks were omitted entirely, leaving only the attention layers to handle both context extraction and non-linear modeling.
  2. Matrix Collapsing: In single-head attention, the query ($W^Q$) and key ($W^K$) matrices can be mathematically collapsed into a single matrix ($W^{QK}$). Furthermore, the value ($W^V$) and projection ($W^O$) matrices can be omitted, treating the output as a simple convex combination of input embeddings.
  3. Symmetry Enforcement: By enforcing symmetry in the similarity measure, the number of parameters in the query/key relationship is halved.
  4. Overdetermination Ratio ($Q$): The authors introduced a metric $Q$ representing the ratio of data constraints to trainable parameters. Higher $Q$ values typically indicate better potential for generalization.

Key Results

The simplified architectures were evaluated on the MNIST and CIFAR-10 datasets. The results indicate that massive parameter savings do not necessarily lead to a significant loss in accuracy.

Performance on MNIST

On the MNIST dataset, the "minimum" variant—lacking an MLP and utilizing collapsed/omitted matrices—reduced the parameter count from approximately 279,000 to just 26,650. Despite this 90% reduction, validation accuracy remained high at 95.32%.

Table 1: Performance metrics for various Transformer configurations on the MNIST dataset. Note the significant parameter reduction in simplified models.

Performance on CIFAR-10

For the more complex CIFAR-10 dataset, the findings were even more striking. Variants without MLPs and with symmetric similarity measures often showed superior generalization compared to the standard architecture. This suggests that the extra parameters in full Transformers may lead to overfitting on medium-sized datasets.

Table 2: Performance metrics for various Transformer configurations on the CIFAR-10 dataset. Simplified models often maintain or improve generalization performance.

Discussion and Insights

The experiments support the "Obsolete Parameter" hypothesis: many parameters in standard Transformers are redundant. By forcing the model to represent tokens as weighted averages of their neighbors (by omitting $W^V$ and $W^O$), the architecture may learn more robust and meaningful representations. Furthermore, the inherent non-linearity of the attention mechanism appears sufficient for these classification tasks.

Limitations and Future Work

While successful on MNIST and CIFAR-10, scaling these "Minimum Transformers" to larger datasets like ImageNet proved challenging, with baseline convergence issues. Future research should explore these architectures in the NLP domain and investigate the use of more robust second-order optimization algorithms to stabilize training for smaller, more constrained models.

Summary updated

Abstract

Transformers are a widespread and successful model architecture, particularly in Natural Language Processing (NLP) and Computer Vision (CV). The essential innovation of this architecture is the Attention Mechanism, which solves the problem of extracting relevant context information from long sequences in NLP and realistic scenes in CV. A classical neural network component, a Multi-Layer Perceptron (MLP), complements the attention mechanism. Its necessity is frequently justified by its capability of modeling nonlinear relationships. However, the attention mechanism itself is nonlinear through its internal use of similarity measures. A possible hypothesis is that this nonlinearity is sufficient for modeling typical application problems. As the MLPs usually contain the most trainable parameters of the whole model, their omission would substantially reduce the parameter set size. Further components can also be reorganized to reduce the number of parameters. Under some conditions, query and key matrices can be collapsed into a single matrix of the same size. The same is true about value and projection matrices, which can also be omitted without eliminating the substance of the attention mechanism. Initially, the similarity measure was defined asymmetrically, with peculiar properties such as that a token is possibly dissimilar to itself. A possible symmetric definition requires only half of the parameters. We have laid the groundwork by testing widespread CV benchmarks: MNIST and CIFAR-10. The tests have shown that simplified transformer architectures (a) without MLP, (b) with collapsed matrices, and (c) symmetric similarity matrices exhibit similar performance as the original architecture, saving up to 90% of parameters without hurting the classification performance.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
CIFAR-10Symmetric-similarity transformer encoder without MLPVal. loss1.2885-0.07 vs baselinesplit: val · mlp=no · epochs=500 · similarity=symmetric · encoder-layers=6 · attention-heads=1
Source quote
L355: \num{1} │ no │ symmetry │ \num{78490} │ \num{6.37} │ \num{0.9686} │ \num{1.2885} │ \num{64.80} │ \num{55.85}
CIFAR-10Minimum transformer variant (Wqk+noWv,Vo) without MLPVal. loss1.6565split: val · mlp=no · epochs=500 · variant=Wqk+noWv,Vo · encoder-layers=6 · attention-heads=1
Source quote
L358: \num{1} │ no │ Wqk+noWv,Vo │ \num{35230} │ \num{14.19} │ \num{1.5961} │ \num{1.6565} │ \num{40.52} │ \num{39.17}
MNISTMinimum transformer variant (Wqk+noWv,Vo) without MLP# Parameters26650-252456 vs baselinemlp=no · variant=Wqk+noWv,Vo · encoder-layers=6 · attention-heads=1 · parameter-count-includes=image-patch embedding matrix
Source quote
L295: 1 │ no │ Wqk+noWv,Vo │ \num{26650} │ \num{22.51} │ \num{0.1697} │ \num{0.1536} │ \num{94.82} │ \num{95.32}
Reported baseline / comparator measurements (3)
BenchmarkMethodMetricScoreProtocol / Evidence
CIFAR-10Unchanged transformer encoder with MLP baselineVal. loss2.2418split: val · mlp=yes · epochs=500 · encoder-layers=6 · attention-heads=1
Source quote
L350: \num{1} │ yes │ unchanged │ \num{287686} │ \num{1.74} │ \num{0.1533} │ \num{2.2418} │ \num{94.63} │ \num{60.24}
CIFAR-10Unchanged transformer encoder without MLP baselineVal. loss1.3590split: val · mlp=no · epochs=500 · encoder-layers=6 · attention-heads=1
Source quote
L353: \num{1} │ no │ unchanged │ \num{101470} │ \num{4.93} │ \num{0.9341} │ \num{1.3590} │ \num{66.16} │ \num{55.30}
MNISTUnchanged transformer encoder with MLP baseline# Parameters279106mlp=yes · encoder-layers=6 · attention-heads=1 · parameter-count-includes=image-patch embedding matrix
Source quote
L286: 1 │ yes │ unchanged │ \num{279106} │ \num{2.15} │ \num{0.0067} │ \num{0.0747} │ \num{99.78} │ \num{98.38}
BibTeX
@misc{bermeitinger2024reducing,
  author = {Bernhard Bermeitinger and Tomas Hrycej and Massimo Pavone and Julianus Kath and Siegfried Handschuh},
  title = {{Reducing the Transformer Architecture to a Minimum}},
  year = {2024},
  eprint = {2410.13732},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.13732},
}
Figure