Research paperICML 2024 · PMLR 235

Outlier-Efficient Hopfield Layers for Large Transformer-Based Models

An associative-memory account of outlier-efficient attention.

Authors

Jerry Yao-Chieh Hu1,*Pei-Hsuan Chang2,*Haozheng Luo1,*Hong-Yu Chen2Weijian Li1Wei-Po Wang2Han Liu1

Equal contribution.

Affiliations

  • 1Northwestern University
  • 2National Taiwan University

Softmax cannot assign zero probability. Large models learn to park attention on tokens that carry little information, and the cost shows up as activation outliers.

When a token's representation already has enough information, the best attention update is close to zero. Prior work observed that attention heads approximate this no-update behavior by concentrating on low-information tokens such as delimiters, punctuation, or background patches in ViT. The paper calls these no-op outliers.

To make that concentration possible, the logits \(\mathbf{Q}\mathbf{K}^{\top}\) must span a wide range. Because softmax never reaches exact zero, gradients keep reinforcing the pattern during training. The resulting outliers make 8-bit quantization harder.

Give no-op patterns a place to go

OutEffHop reads attention as memory retrieval in a modern Hopfield model. Stored patterns that are unrelated to the query are mapped to a single no-op memory \(\Omega\) at zero energy.

A relevant query descends to its nearest stored pattern. A query that matches nothing settles at the zero-energy point, which contributes nothing to the retrieved output.

Figure 1 · conceptual energy landscape
Op memories \(\boldsymbol{\xi}_\mu\) and the no-op memory \(\Omega\)

Figure 1: energy of a physical system over configuration space. Op memories xi 1 through xi M sit at local minima of a colored energy surface. An op query descends into a local minimum; a no-op query descends to the zero-energy no-op memory Omega at either side.
Visualization of the Outlier-Efficient Hopfield Model, Figure 1 of the paper. Source ↗

Add one dimension that classifies memories as no-op, then derive the retrieval rule from the new energy.

Modern Hopfield models retrieve a memory as an expectation of stored patterns under \(\operatorname{Softmax}(\beta\,\Xi^{\top}\mathbf{x})\). A single retrieval step of that model is ordinary attention. OutEffHop changes the energy function so that one retrieval step becomes \(\operatorname{Softmax}_1\) attention, which can place probability mass on nothing.

  1. 01 /

    No-op classification

    Queries and memories gain an extra coordinate. Memories marked as no-op are mapped to one class vector \(\Omega\), whose inner product with every query is zero.

    \[ \Omega = (\underbrace{0,\ldots,0}_{d},\,C), \qquad \langle \Omega, \bar{\mathbf{x}} \rangle = 0 . \]
  2. 02 /

    Outlier-efficient energy

    The energy uses a refined log-sum-exp. The extra term \(+1\) is the contribution of \(\Omega\), which creates a zero-energy point.

    \[ \begin{aligned} \mathcal{H}(\mathbf{x}) = &-\frac{1}{\beta}\log\Bigl(\sum_{\mu=1}^{M} e^{\beta\langle \boldsymbol{\xi}_\mu,\mathbf{x}\rangle} + 1\Bigr) \\ &+ \tfrac12\langle\mathbf{x},\mathbf{x}\rangle + \mathrm{const}. \end{aligned} \]
  3. 03 /

    Retrieval dynamics

    A standard concave-convex derivation gives an update that monotonically decreases \(\mathcal{H}\) (Lemma 2.1). One step of this update is \(\operatorname{Softmax}_1\) attention.

    \[ \begin{aligned} \mathbf{x}_{t+1} &= \Xi\,\operatorname{Softmax}_1\!\bigl(\beta\,\Xi^{\top}\mathbf{x}_t\bigr), \\ \operatorname{Softmax}_1(\mathbf{z})_\mu &= \frac{e^{z_\mu}}{1+\sum_{\nu} e^{z_\nu}} . \end{aligned} \]
  4. 04 /

    The OutEffHop layer

    Mapping queries and memories through learned projections yields a layer that replaces attention in transformers and Hopfield layers in Hopfield networks.

    \[ \mathbf{Z} = \operatorname{Softmax}_1\!\bigl(\beta\,\mathbf{R}\mathbf{W}_Q\mathbf{W}_K^{\top}\mathbf{Y}^{\top}\bigr)\,\mathbf{Y}\mathbf{W}_K\mathbf{W}_V . \]
Notation

\(\mathbf{x}\in\mathbb{R}^d\) is a query pattern and \(\Xi=[\boldsymbol{\xi}_1,\ldots,\boldsymbol{\xi}_M]\) holds the stored memory patterns; \(\bar{\mathbf{x}}\) is the query with the extra coordinate set to zero. \(\beta\) is the inverse temperature and \(C\) is a constant. In the layer, \(\mathbf{R}\) is the raw query input, \(\mathbf{Y}\) the raw memory input, and \(\mathbf{W}_Q,\mathbf{W}_K,\mathbf{W}_V\) are learned projections; setting \(\mathbf{R}=\mathbf{Y}\) recovers self-attention. See Sections 2.2–2.4 of the paper.

Layer variants in the paper

Like earlier Hopfield layers, OutEffHop has several configurations. In memory retrieval mode the projections are identities and nothing is learned. OutEffHop learns all three projections and serves as a drop-in attention replacement. OutEffHopPooling uses a learnable query to search static prototype patterns. OutEffHopLayer stores patterns in the learned key and value matrices, so keys and values do not depend on the input.

Giving each no-op pattern its own class vector instead of a shared \(\Omega\) generalizes the denominator from \(1\) to \(K\), which yields \(\operatorname{Softmax}_K\). Read Section 2.4.

Language, vision & time series

BERT-base Average kurtosis · pretraining from scratch

418.72426.564

93.66% lower average kurtosis

Vanilla attention → OutEffHop

OPT-125m W8A8 perplexity

42.01216.429

60.89% lower perplexity after quantization

Vanilla attention → OutEffHop

Maximum infinity norm during pretraining

Each row tracks the largest activation in one layer as training proceeds. The left column compares OutEffHop with vanilla attention. The other two columns apply \(\operatorname{Softmax}_1\) on top of Clipped Softmax and Gated Attention. The vertical scales differ between panels.

Figure 2: twelve line plots of maximum infinity norm against training step for BERT, OPT, ViT and STanHop-Net. In each panel a grey baseline curve is compared with a red OutEffHop curve. For BERT and OPT with vanilla attention the red curve stays far below the grey curve; the gaps in the other panels are smaller.
Figure 2. Layer 10 of BERT, OPT, and ViT, and layer 9 of STanHop-Net. Grey: baseline; red: with OutEffHop. Source ↗

Outliers and quantization across four models

Each model is trained from scratch with the attention (or Hopfield) layer replaced. OutEffHop reduces both outlier metrics relative to vanilla attention in all four models, and combining it with Clipped Softmax or Gated Attention usually reduces them further. Clipped OutEffHop on OPT is the exception, in line with earlier reports that Clipped Softmax performs poorly on OPT.

Outlier efficiency and quantization · Table 1
ModelMethodAvg. kurtosis ↓Max inf. norm ↓FP16*W8A8*
BERTVanilla418.724 ± 0.814255.859 ± 0.0046.237 ± 0.0017.154 ± 0.009
OutEffHop26.564 ± 0.02233.618 ± 0.0006.209 ± 0.0016.295 ± 0.001
Clipped Softmax14.210 ± 0.00333.619 ± 0.0016.118 ± 0.0026.189 ± 0.001
Clipped OutEffHop11.839 ± 0.00130.107 ± 0.0016.133 ± 0.0006.199 ± 0.001
Gated Attention17.779 ± 0.01434.082 ± 0.0006.230 ± 0.0016.299 ± 0.003
Gated OutEffHop15.625 ± 0.01232.777 ± 0.0006.214 ± 0.0016.279 ± 0.003
OPTVanilla23341.513 ± 27.36392.786 ± 0.00215.974 ± 0.00142.012 ± 19.514
OutEffHop21.542 ± 0.00013.302 ± 0.00115.916 ± 0.00216.429 ± 0.013
Clipped Softmax9731.110 ± 0.00043.803 ± 0.00016.042 ± 0.00030.825 ± 0.330
Clipped OutEffHop24127.332 ± 0.00067.602 ± 0.00016.118 ± 0.00029.269 ± 0.184
Gated Attention90.321 ± 0.00013.704 ± 0.00015.677 ± 0.00016.236 ± 0.074
Gated OutEffHop11.449 ± 0.0007.568 ± 0.00015.751 ± 0.00016.148 ± 0.005
ViTVanilla37.104 ± 0.000272.198 ± 0.00076.810 ± 0.00074.935 ± 0.046
OutEffHop31.601 ± 0.001249.163 ± 0.00076.788 ± 0.00076.313 ± 0.012
Clipped Softmax33.868 ± 0.00257.613 ± 0.0076.612 ± 0.00075.179 ± 0.013
Clipped OutEffHop24.642 ± 0.000196.199 ± 0.00176.871 ± 0.00176.083 ± 0.007
Gated Attention45.145 ± 0.864269.279 ± 1.42669.922 ± 2.43667.479 ± 1.447
Gated OutEffHop21.979 ± 0.25460.169 ± 1.15374.089 ± 2.58573.958 ± 3.126
STanHop-NetVanilla2.954 ± 0.0635.048 ± 0.2320.360 ± 0.0080.362 ± 0.000
OutEffHop2.897 ± 0.0114.565 ± 0.2090.360 ± 0.0040.355 ± 0.000
Clipped Softmax2.995 ± 0.054.890 ± 0.170.553 ± 0.030.591 ± 0.000
Clipped OutEffHop2.864 ± 0.064.145 ± 0.230.506 ± 0.050.517 ± 0.000
Gated Attention2.487 ± 0.0174.277 ± 0.1630.380 ± 0.0060.375 ± 0.000
Gated OutEffHop2.459 ± 0.0414.240 ± 0.1550.376 ± 0.0070.367 ± 0.000

* FP16 and W8A8 report perplexity for BERT and OPT (lower is better), top-1 accuracy for ViT (higher is better; ViT uses FP32 before quantization), and MSE for STanHop-Net (lower is better). Mean ± standard deviation over three seeds. BERT kurtosis averages FFN and LayerNorm outputs; the other models average every output component. The OPT vanilla W8A8 perplexity has a large standard deviation (±19.514). Parameter counts are 108.9M–109M for BERT, 124.06M–124.07M for OPT, 22.03M–22.04M for ViT, and 35.13M–35.15M for STanHop-Net.

Table 1 & protocol

Where the reduction happens inside BERT

The left four panels track FFN outputs in layers 3, 6, 9, and 10. The reduction is small in early layers and grows in later ones. The right four panels break layer 10 into components. OutEffHop suppresses the outliers in both FFN layers but not in the first residual LayerNorm, which the paper lists as a limitation.

Figures 3 and 4: eight line plots of maximum infinity norm against training step for BERT. Left: FFN outputs of layers 3, 6, 9 and 10. Right: attention layer, first residual LayerNorm, FFN-1 and FFN-2 in layer 10. The red OutEffHop curve is far below the grey vanilla curve in layers 9 and 10 and in both FFN components, but above it for the first residual LayerNorm.
Figures 3 and 4. Grey: vanilla softmax; red: OutEffHop. Source ↗

Inside a Hopfield network

STanHop-Net is a Hopfield-based model for multivariate time series. The paper swaps its Hopfield layer for dense, sparse, generalized sparse (GSH), and OutEffHop variants. Across ETTh1, ETTm1, and WTH at five horizons each, OutEffHop ranks first or second in outlier efficiency in 25 of 30 settings. The ETTh1 rows are shown below.

Hopfield layer variants on ETTh1 · Table 2
HorizonHopfieldSparseHopfieldSTanHop-Net (GSH)OutEffHop
Kurt. ↓Max ↓Kurt. ↓Max ↓Kurt. ↓Max ↓Kurt. ↓Max ↓
242.9545.0483.3114.9543.2694.9472.8974.565
482.9684.9693.2954.7493.2714.6442.9654.570
1682.5453.9233.1494.3483.0934.1602.5263.865
3362.4363.5363.0714.1563.0434.2482.4333.416
7202.4433.2663.0304.1793.0624.2382.4503.218

Average kurtosis and maximum infinity norm over 12 decoder layers, averaged over 10 runs; standard deviations and MSE/MAE are in the paper. The lowest value in each metric is in bold. Outlier efficiency comes with some loss in prediction error: across the three datasets, OutEffHop's MSE is higher than the best baseline in 14 of 15 settings. See Table 2 for ETTm1 and WTH ↗

The paper shows that the new energy keeps the standard properties of modern Hopfield models. Each result is stated under the assumptions in Section 3.

Convergence
Limit points of the retrieval dynamics are stationary points of \(\mathcal{H}\) (Theorem 3.1).
Retrieval error
A lower upper bound on retrieval error than the original modern Hopfield model (Theorem 3.2).
Memory capacity
Exponential in pattern dimension, with a lower bound at least that of the original model (Theorem 3.3).
Generalization
The bound scales as \(N^{-1/2}\) up to log factors in sample size and logarithmically in \(d\) and \(M\); it does not depend on sequence length (Theorem 3.4).

The experiments train BERT-base (109M) and OPT-125m on BookCorpus and Wiki40B/en, ViT-S/16 on ImageNet-1k, and STanHop-Net on ETTh1, with ETTm1 and WTH added for the Hopfield-layer comparison, following the protocol of Bondarenko et al. (2023). OutEffHop does not address outliers that originate in LayerNorm, which appear to arise from a different mechanism than the attention outliers studied here.

Theory, experiments & limitations ↗
BibTeX
Download
@InProceedings{pmlr-v235-hu24a,
  title     = {Outlier-Efficient Hopfield Layers for Large Transformer-Based Models},
  author    = {Hu, Jerry Yao-Chieh and Chang, Pei-Hsuan and Luo, Haozheng and
               Chen, Hong-Yu and Li, Weijian and Wang, Wei-Po and Liu, Han},
  booktitle = {Proceedings of the 41st International Conference on Machine Learning},
  pages     = {19123--19152},
  year      = {2024},
  volume    = {235},
  series    = {Proceedings of Machine Learning Research},
  publisher = {PMLR},
  url       = {https://proceedings.mlr.press/v235/hu24a.html}
}