Transformer-Evolution-Paper
  • README
  • 数学符号
  • Act
    • A survey on recently proposed activation functions for Deep Learning
  • Arch
    • Supplementary Material Implementation and Experiments for GAU-based Model
    • MetaFormer is Actually What You Need for Vision
    • Deeper vs Wider A Revisit of Transformer Configuration
    • Perceiver General Perception with Iterative Attention
    • General-purpose, long-context autoregressive modeling with Perceiver AR
    • Hierarchical Transformers Are More Efficient Language Models
    • Branchformer: Parallel MLP-Attention Architectures to Capture Local and Global Context for Speech Recognition and Understanding
    • Generalization through Memorization: Nearest Neighbor Language Models
  • FFN
    • Large Memory Layers with Product Keys
    • Transformer Feed-Forward Layers Are Key-Value Memories
    • GLU Variants Improve Transformer
    • Simple Recurrence Improves Masked Language Models
    • Pay Attention to MLPs
    • S2-MLP Spatial-Shift MLP Architecture for Vision
    • S2-MLPv2 Improved Spatial-Shift MLP Architecture for Vision
    • HyperMixer An MLP-based Green AI Alternative to Transformers
    • DeFINE: DEep Factorized INput Token Embeddings for Neural Sequence Modeling & DeLighT: Deep and Light-weight Transformer
    • When Shift Operation Meets Vision Transformer: An Extremely Simple Alternative to Attention Mechanism
    • Sparse MLP for Image Recognition: Is Self-Attention Really Necessary?
  • Head
    • Multi-Head Attention Collaborate Instead of Concatenate
    • Fast Transformer Decoding: One Write-Head is All You Need
  • Memory
    • Compressive Transformers for Long-Range Sequence Modelling
    • Memformer The Memory-Augmented Transformer
    • Memory Transformer
    • Do Transformers Need Deep Long-Range Memory
    • LaMemo Language Modeling with Look-Ahead Memory
    • GMAT Global Memory Augmentation for Transformers
    • Block-Recurrent Transformers
    • Augmenting Self-attention with Persistent Memory
    • Recurrent Memory Transformer
    • Memorizing Transformers
    • Scaling Transformer to 1M tokens and beyond with RMT
    • Adapting Language Models to Compress Contexts
  • MHA
    • FFT
      • Fourier Neural Operator for Parametric Partial Differential Equations
      • Global Filter Networks for Image Classification
      • Adaptive Fourier Neural Operators: Efficient Token Mixers for Transformers
      • FNet: Mixing Tokens with Fourier Transforms
    • LocalGlobal
      • CrossFormer: A Versatile Vision Transformer Hinging on Cross-scale Attention
      • Nested Hierarchical Transformer: Towards Accurate, Data-Efficient and Interpretable Visual Understanding
      • Neighborhood Attention Transformer
      • FMMformer: Efficient and Flexible Transformer via Decomposed Near-field and Far-field Attention
      • Adaptive Attention Span in Transformers
      • CoLT5: Faster Long-Range Transformers with Conditional Computation
    • MatrixMethod
      • Skyformer Remodel Self-Attention with Gaussian Kernel and Nyström Method
      • Is Attention Better Than Matrix Decomposition
    • RightProduct
      • Kronecker Attention Networks
      • An Attention Free Transformer
      • Transformer with Fourier Integral Attentions
      • Linear Complexity Randomized Self-attention Mechanism
      • UFO-ViT: High Performance Linear Vision Transformer without Softmax
      • XCiT: Cross-Covariance Image Transformers
      • SimpleTRON: Simple Transformer with O(N) Complexity
      • A Dot Product Attention Free Transformer
      • On Learning the Transformer Kernel
      • Momentum Transformer: Closing the Performance Gap Between Self-attention and Its Linearization
    • SparseOrLowRank
      • Explicit Sparse Transformer: Concentrated Attention Through Explicit Selection
      • Scatterbrain: Unifying Sparse and Low-rank Attention Approximation
      • Sparse Factorization of Large Square Matrices
      • Blockwise Self-Attention for Long Document Understanding
      • H-Transformer-1D: Fast One-Dimensional Hierarchical Attention for Sequences
      • ChunkFormer: Learning Long Time Series with Multi-stage Chunked Transformer
      • Enhancing the Locality and Breaking the Memory Bottleneck of Transformer on Time Series Forecasting
      • Fast Transformers with Clustered Attention
      • Long-Short Transformer: Efficient Transformers for Language and Vision
      • LongT5: Efficient Text-To-Text Transformer for Long Sequences
      • Luna: Linear Unified Nested Attention
      • Memory-efficient Transformers via Top-k Attention
      • Separable Self-attention for Mobile Vision Transformers
      • Simple Local Attentions Remain Competitive for Long-Context Tasks
      • You Only Sample (Almost) Once: Linear Cost Self-Attention Via Bernoulli Sampling
    • Others
      • Synthesizer: Rethinking Self-Attention in Transformer Models
      • Transformer Dissection: A Unified Understanding of Transformer's Attention via the Lens of Kern
      • Combiner Full Attention Transformer with Sparse Computation Cost
      • Ripple Attention for Visual Perception with Sub-quadratic Complexity
      • Sinkformers: Transformers with Doubly Stochastic Attention
      • SOFT: Softmax-free Transformer with Linear Complexity
      • Value-aware Approximate Attention
      • EL-Attention: Memory Efficient Lossless Attention for Generation
      • Flowformer: Linearizing Transformers with Conservation Flows
      • ETSformer: Exponential Smoothing Transformers for Time-series Forecasting
      • IGLOO: Slicing the Features Space to Represent Sequences
      • Swin Transformer V2: Scaling Up Capacity and Resolution
      • Skip-Attention: Improving Vision Transformers by Paying Less Attention
  • Normalize_And_Residual
    • ReZero is All You Need Fast Convergence at Large Depth
    • Batch Normalization Biases Residual Blocks Towards the Identity Function in Deep Networks
    • Improving Deep Transformer with Depth-Scaled Initialization and Merged Attention
    • RealFormer Transformer Likes Residual Attention
    • On Layer Normalizations and Residual Connections in Transformers
    • Transformers without Tears: Improving the Normalization of Self-Attention
    • Query-Key Normalization for Transformers
    • Understanding the difficulty of training transformers
  • Pe
    • A Simple and Effective Positional Encoding for Transformers
    • DeBERTa Decoding-enhanced BERT with Disentangled Attention
    • DecBERT Enhancing the Language Understanding of BERT with Causal Attention Masks
    • Encoding word order in complex embeddings
    • Improve Transformer Models with Better Relative Position Embeddings
    • KERPLE Kernelized Relative Positional Embedding for Length Extrapolation
    • PermuteFormer Efficient Relative Position Encoding for Long Sequences
    • Rethinking Positional Encoding in Language Pre-training
    • Transformer-XL Attentive Language Models Beyond a Fixed-Length Context
    • Translational Equivariance in Kernelizable Attention
    • Transformer Language Models without Positional Encodings Still Learn Positional Information
    • Stable, Fast and Accurate: Kernelized Attention with Relative Positional Encoding
    • Randomized Positional Encodings Boost Length Generalization of Transformers
  • Pretrain
    • XLNet Generalized Autoregressive Pretraining for Language Understanding
    • Transcormer Transformer for Sentence Scoring with Sliding Language Modeling
    • Optimus Organizing Sentences via Pre-trained Modeling of a Latent Space
    • ELECTRA Pre-training Text Encoders as Discriminators Rather Than Generators
    • Cramming: Training a Language Model on a Single GPU in One Day
  • Softmax
    • Transformer with a Mixture of Gaussian Keys
    • Normalized Attention Without Probability Cage
  • Others
    • Accelerating Neural Transformer via an Average Attention Network
    • Do Transformer Modifications Transfer Across Implementations and Applications?
    • Object-Centric Learning with Slot Attention
    • Do Transformer Modifications Transfer Across Implementations and Applications?
    • Why self-attention is Natural for Sequence-to-Sequence Problems? A Perspective from Symmetries
  • LongConv
    • Legendre Memory Units: Continuous-Time Representation in Recurrent Neural Networks
    • Parallelizing Legendre Memory Unit Training
    • Simplified State Space Layers for Sequence Modeling
    • Pretraining Without Attention
    • What Makes Convolutional Models Great on Long Sequence Modeling?
    • Hungry Hungry Hippos: Towards Language Modeling with State Space Models
    • Hyena Hierarchy: Towards Larger Convolutional Language Models
    • RWKV
    • Simple Hardware-Efficient Long Convolutions for Sequence Modeling
    • Time-aware large kernel convolutions
    • Resurrecting Recurrent Neural Networks for Long Sequences
    • CKConv: Continuous Kernel Convolution For Sequential Data
    • FlexConv: Continuous Kernel Convolutions with Differentiable Kernel Sizes
    • Towards a General Purpose CNN for Long Range Dependencies in ND
  • Rnn
    • When Attention Meets Fast Recurrence: Training Language Models with Reduced Compute
    • Linear Transformers Are Secretly Fast Weight Programmers
    • Going Beyond Linear Transformers with Recurrent Fast Weight Programmers
    • Parallelizing Linear Recurrent Neural Nets Over Sequence Length
    • Quasi-recurrent neural networks
  • CrossAttention
    • Neural Machine Translation in Linear Time
  • Inference
    • Extrapolation
      • Parallel Context Windows for Large Language Models
      • Structured Prompting: Scaling In-Context Learning to 1,000 Examples
      • Naive Bayes-based Context Extension
  • Peft
    • Parameter-Efficient Fine-Tuning without Introducing New Latency
    • Make Your Pre-trained Model Reversible: From Parameter to Memory Efficient Fine-Tuning
  • LLM
    • LLM Details Summary
    • What Language Model to Train if You Have One Million GPU Hours?
Powered by GitBook
On this page
  • 整体思路以及计算方式
  • 训练以及loss
  • 代码
  • 实验以及适用场景
  • 细节
  • 简评
  1. Normalize_And_Residual

Improving Deep Transformer with Depth-Scaled Initialization and Merged Attention

PreviousBatch Normalization Biases Residual Blocks Towards the Identity Function in Deep NetworksNextRealFormer Transformer Likes Residual Attention

Last updated 2 years ago

论文地址:

整体思路以及计算方式

论文工作量两点:

  1. 解释了深层Transformer为什么难以训练,针对这点,提出了一种新的初始化方式;

  2. 结合作者之前的AAN,提出加速解码的方案;

第一点:

作者的观点是,深层Transformer难以训练是因为反传的原因,而主要的方面是因为残差和Layer Norm。

回顾Transformer的计算公式:

r=RC⁡(z,f(z))o=LN⁡(r)\begin{aligned} \mathrm{r}&=\operatorname{RC}(\mathrm{z}, f(\mathrm{z})) \\ \mathrm{o}&=\operatorname{LN}(\mathrm{r}) \end{aligned}ro​=RC(z,f(z))=LN(r)​

其中fff表示MHA\mathrm{MHA}MHA或FFN\mathrm{FFN}FFN,RC\mathrm{RC}RC表示残差连接,LN\mathrm{LN}LN表示layer norm。

计算反传可得:

δr=∂o∂rδo=diag⁡(gσr)(I−1−r‾r‾⊤d)δoδz=∂r∂zδr=(1+∂f∂z)δr,\begin{aligned} &\delta_{r}=\frac{\partial \mathrm{o}}{\partial \mathrm{r}} \delta_{o}=\operatorname{diag}\left(\frac{\mathrm{g}}{\sigma_{r}}\right)\left(\mathrm{I}-\frac{1-\overline{\mathrm{r}} \overline{\mathrm{r}}^{\top}}{d}\right) \delta_{o} \\ &\delta_{z}=\frac{\partial \mathrm{r}}{\partial \mathrm{z}} \delta_{r}=\left(1+\frac{\partial f}{\partial \mathrm{z}}\right) \delta_{r}, \end{aligned}​δr​=∂r∂o​δo​=diag(σr​g​)(I−d1−rr⊤​)δo​δz​=∂z∂r​δr​=(1+∂z∂f​)δr​,​

其中r‾\overline {\mathrm r}r表示归一化的输入,所以r‾r‾⊤\overline{\mathrm{r}} \overline{\mathrm{r}}^{\top}rr⊤表示方差,注意到δr\delta_rδr​和方差正相关。

接着作者考虑了如下量:

β=βLN⋅βRC=∥δz∥2∥δr∥2⋅∥δr∥2∥δo∥2\beta=\beta_{\mathrm{LN}} \cdot \beta_{\mathrm{RC}}=\frac{\left\|\delta_{z}\right\|_{2}}{\left\|\delta_{r}\right\|_{2}} \cdot \frac{\left\|\delta_{r}\right\|_{2}}{\left\|\delta_{o}\right\|_{2}}β=βLN​⋅βRC​=∥δr​∥2​∥δz​∥2​​⋅∥δo​∥2​∥δr​∥2​​

从直觉上看,我们希望β≈1\beta\approx 1β≈1,因为太大会造成梯度消失,太小会造成梯度爆炸。那么β,βLN,βRC\beta,\beta_{\mathrm{LN}} , \beta_{\mathrm{RC}}β,βLN​,βRC​的值大概是多少?作者经过分析,给出如下结论:

  • FFN\mathrm{FFN}FFN的β<1\beta<1β<1,MHA\mathrm{MHA}MHA的β>1\beta>1β>1,包含Self和Cross Attention;

  • 无论是FFN\mathrm{FFN}FFN还是MHA\mathrm{MHA}MHA,都有βLN<1\beta_{\mathrm{LN}}<1βLN​<1 , βRC>1\beta_{\mathrm{RC}}>1βRC​>1;

    • 在Transformer中,βLN∈[0.82,0.86],βRC∈[1.10,1.22]\beta_{\mathrm{LN}}\in [0.82, 0.86], \beta_{\mathrm{RC}}\in [1.10,1.22]βLN​∈[0.82,0.86],βRC​∈[1.10,1.22]

由于βRC\beta_{\mathrm{RC}}βRC​和方差正相关,所以减少方差可以使得βRC\beta_{\mathrm{RC}}βRC​更接近1,作者给出的方案是修改初始化方案:

W∈Rdi×do∼U(−γαl,γαl)\mathrm{W} \in \mathbb{R}^{d_{i} \times d_{o}} \sim \mathcal{U}\left(-\gamma \frac{\alpha}{\sqrt{l}}, \gamma \frac{\alpha}{\sqrt{l}}\right)W∈Rdi​×do​∼U(−γl​α​,γl​α​)

其中lll表示层数。

第二点:

把NMT中Decoder的Self Attention换成AAN,从而提高解码效率:

MATT⁡(Sl−1)=SAAN⁡(Sl−1)+ATT⁡(Sl−1,HL)S‾l=LN(RC⁡(Sl−1,MATT⁡(Sl−1)))\begin{aligned} &\operatorname{MATT}\left(\mathrm{S}^{l-1}\right)=\operatorname{SAAN}\left(\mathrm{S}^{l-1}\right)+\operatorname{ATT}\left(\mathrm{S}^{l-1}, \mathrm{H}^{L}\right) \\ &\overline{\mathrm{S}}^{l}=\mathrm{L N}\left(\operatorname{RC}\left(\mathrm{S}^{l-1}, \operatorname{MATT}\left(\mathrm{S}^{l-1}\right)\right)\right) \end{aligned}​MATT(Sl−1)=SAAN(Sl−1)+ATT(Sl−1,HL)Sl=LN(RC(Sl−1,MATT(Sl−1)))​

训练以及loss

没有变化。

代码

实验以及适用场景

初始化部分适用于所有场景,解码部分适用于Decoder;实验测试了NMT,带来了一定的效果。

细节

暂无。

简评

第一点提供了一种分析的思路,值得复现。

https://arxiv.org/abs/1908.11365
https://github.com/bzhangGo/zero/tree/master/docs/depth_scale_init_and_merged_attention