atlas

Research map / Architectures and efficiency / Attention and transformers

On the Role of Attention Masks and LayerNorm in Transformers

NeurIPS 2024 · Architectures and efficiency › Attention and transformers · approach: Attention head and block redesign · 2 citations (OpenAlex)

Read the paperCheck your idea against 108,967 papers

AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.

Analyzes rank collapse in transformer self-attention under general attention masks and LayerNorm, showing masks slow collapse while LayerNorm with orthogonal or proper value matrices can prevent collapse to rank one.

Problem

Rank collapse (token uniformity/oversmoothing) of token representations in multi-layer self-attention, which prior theory analyzed only for fully bidirectional attention and without LayerNorm (or with LayerNorm only under identity value matrices).

Approach

Treats self-attention as a discrete-time dynamical system with general masks described by directed graphs (quasi-strongly connected graphs and radius), proves exponential collapse for masked attention, and uses infinite products of nonnegative matrices and constructed counterexamples to show LayerNorm with suitable value matrices yields equilibria of any rank and prevents rank-one collapse.

Key results

Measured effects reported in the paper

What was changedWhereMeasuredEffect
Use local or sliding-window attention instead of full attentionSelf-attention networks · Wikipedia 128-token excerptstoken similarity μ(X)Helped
Add LayerNormRandomly initialized self-attention networks · Wikipedia 128-token excerptstoken similarity μ(X)Helped
Add LayerNorm alongside other components, including skip connectionsPretrained transformer models · Wikipedia 128-token excerptstoken representation stabilityHelped
Add skip connections without the full transformer's other componentsSelf-attention networks · Deeper layerstoken similarity μ(X)Hurt
Add LayerNorm to counteract the instability from pure skip connectionsTransformer components · Deeper layerstoken representation stabilityHelped
Use a smaller attention temperature d_QKPretrained self-attention networks · Different attention masksinitial rate of rank collapseHelped
Use a smaller attention temperature d_QKPretrained self-attention networks · Global attention versus sparse masked attentioninitial rate of rank collapseMixed
Use causal attention instead of full attentionLayerNorm self-attention with orthogonal value matrices · Rank collapse under attention masksrate of rank collapseHelped
Use LayerNorm with orthogonal value matricesSelf-attention dynamics · Strongly connected attention maskstoken similarity μ(X)Hurt
Use LayerNorm with properly chosen value matricesSelf-attention dynamics · A general class of input sequencestoken rankHelped
Add LayerNorm to pure self-attentionSelf-attention networks · All attention masks in the numerical experimentstoken similarity μ(X)Mixed
Use self-attention with LayerNorm rather than without LayerNormTransformer token representations · Pretrained BERT, GPT2, T5, and ALBERTtoken rankHelped

Surprising findings

Limitations

Experimental setup

Datasets: Wikipedia excerpts (3000 samples of 128 tokens)

Metrics: mu(X) token collapse measure (Frobenius deviation from mean) minimal singular value average absolute pairwise cosine similarity

Baselines: pure self-attention without LayerNorm full bidirectional attention causal attention

Builds on: Dong et al. 2021 rank collapse of pure self-attention Geshkovski et al. continuous-time self-attention dynamics Wang et al. LayerNorm in MLPs isometry

Closest papers by meaning

Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.

Open scime draft

Get the next scime Dispatch and a monthly field update

Free. We send a confirmation link first; every email has a one-click unsubscribe. Privacy