Gated Attention

Context: Gating Mechanisms

Gating mechanisms have a long history in neural network architecture as a way to regulate information flow and improve the propogation of gradients (∇) open paren nabla close paren.

Early architectures like LSTMs, Highway Networks, and GRUs pioneered gating to control flow across layers / time steps.

More recent works like State-Space Models (SSMs) and linear attention variants often also apply gating to modulate token-mixer outputs.

Gated Attention for Large Language Models: Non-linearity, Sparsity, and Attention-Sink-Free

The paper systematically investigates augmenting standard Softmax attention with gating at various positions (G1,G2,G3,G4,G5) open paren G sub 1 comma G sub 2 comma G sub 3 comma G sub 4 comma G sub 5 close paren.

Optimal Position (G1) open paren G sub 1 close paren: Applying a head-specific sigmoid gate after the Scaled Dot-Product (SDPA) open paren SDPA close paren yields the most significant improvements.

Mathematics: Formalizing Gated Attention

The gating mechanism is formalized as a dynamic filter applied to a target input Y Y using a gating input X X:

Y′=g⁡(Y,X,Wθ,σ)=Y⊙σ⁡(X⁢Wθ) Y prime equals g of open paren Y comma X comma W sub theta comma sigma close paren equals Y circled dot sigma of open paren X W sub theta close paren

where Y Y is the input to be modulated (e.g., SDPA) SDPA close paren, X X is the hidden states after pre-normalization used to compute gating scores, and σ sigma is the activation function, typically sigmoid sigmoid. The effectiveness is attributed to two factors:

  1. Non-linearity: This increases the expressiveness of the low-rank linear transformation formed by the value (WV) open paren W sub V close paren and the dense (WO) open paren W sub O close paren projections.

  2. Input-Dependent Sparsity: Gating scores concentrated near zero introduce sparsity, filtering irrelevant context.

Impact: Performance and Scaling

They see a reduction of over 0.2 0.2 PPL in 15 15 billion parameter MoE models using SDPA SDPA Elementwise G1 G sub 1.

Training Stability: The gated architecture nearly eliminates loss spikes, allowing for larger learning rates and better scaling. Gating allows dense models to converge at higher learning rates (e.g., doubled to 8.0×10-3 8.0 times 10 to the negative 3 power) where standard baselines would otherwise diverge.

Attention-Sink-Free: Sparse gating scores effectively eliminate the "attention sink" phenomenon, where models over-allocate attention to the first token. In baseline models, the first token receives ~46.7% tilde 46.7 percent of attention; gating reduces this to ~4.8% tilde 4.8 percent of attention.

Context Extension: SDPA output gating facilitates adaptation to sequence length increases by replacing fixed attention-sink patterns with input-dependent filtering. Gated models demonstrate superior length generalization, outperforming baselines significantly at 64 64k and 128 128k context lengths on the RULER benchmark.

Questions

  • N/A