A Survey of Transformers
[[PTM]] pre-train-model
17 年 Google 发表论文 「Attention is all you need」提出 Transformers 框架,之后一大批人在此基础上进行研究和应用。原始 Transformer 改进的变体被称为 「X-formers」。
X-formers 改进方向有三个:
-
Model Efficiency
-
self-attetion 带来的计算量和参数量(内存)
-
sparse attention 轻量级注意力机制方案
-
divide-and-conquer methods 分治方法
-
-
-
Model Generalization
-
框架灵活,对数据没有太多的结构偏置
-
训练需要数据量大
-
structural bias or regularization, pre-training on large-scale unlabeled data
-
-
Model Adaptation
- 将 Transformer 应用到具体的下游任务中。
背景知识
模型使用形式
-
Encoder-Decoder
-
Encoder only
- classification or sequence labeling
-
Decoder only
-
sequence generation
- language modeling
-
根据对原始 Transformer 的改进分类:architecture modification, pre-training, and applications
-
architecture modification
-
Module Level
-
-
挑战
-
计算复杂度,受序列长度影响
-
Structural prior 没有结构先验,在小数据集上容易过拟合
-
-
Sparse Attention
-
token i 和 j 有关系的情况下计算 attention,以稀疏矩阵形式保存
-
如何定义关系
-
position-based
-
计算指定位置之间的 attention
-
atomic sparse attention
-
Global
-
Band
-
Dilated
-
-
组合 atomic attention 得到更加复杂的attention计算规则
-
-
content-based
-
Routing Transformer
-
Efficient Content-Based Sparse Attention with RoutingTransformers
-
聚类
-
-
[[Reformer]]
-
使用 LSH,同一个分桶内的 token 计算 attention
-
-
-
-
-
[[Linearized Attention]]
-
QKV 计算 Attention 的复杂度是 $$O(T^2D)$$,通过引入核函数降低到 $$O(TD)$$
-
key components
-
kernel feature map
-
Performer 用其他函数去拟合 attention 函数
-
FAVOR+ Fast Attention Via positive Orthogonal Random features approach
-
-
-
aggregation rule
-
-
-
Query Prototyping and Memory Compression
-
减少 queries or key-value pairs
-
Query Prototyping 计算关键 query 的 attention 值,剩余部分填充或者采用均匀分布填充
-
Memory Compression 减少 kv 数量
-
-
Low-rank Self-Attention
-
attention 矩阵线性相关的行数 A 远小于输入 T
-
Low-rank Parameterization
-
Low-rank Approximation
-
-
Attention with Prior
-
分成 generated attention 和 prior attention 两部分,下面的方法都是生成 prior attention 尝试
-
Prior that Models locality
-
文本之类的数据对位置敏感,使用 i 和 j 的位置,结合[[Normal Distribution]]计算先验信息
-
-
Prior from Lower Modules
-
使用之前层的注意力分布结果
-
Realformer 将 [[ResNet]] 结构放到 Attention 矩阵中
-
Lazyformer 每两层计算一次 Attention 矩阵
-
-
Prior as Multi-task Adapters
-
多任务适配器,看起来是在共享参数
-
-
Attention with Only Prior
- 只使用先验
-
-
Improved Multi-Head Mechanism
-
Head Behavior Modeling
-
Multi-head with Restricted Spans
-
观察到原始中部分 head 关注局部,部分关注全局
-
限制 attention 的范围(通过距离实现)
-
decoder 中 mask-multi-head 就是这个思路
-
-
Multi-head with Refined Aggregation
-
多头的结果如何合并
-
routing methods
-
-
Other Modifications
-
Shazeer
multi-query attention
所有头之间共享 kv -
Bhojanapalli 灵活设置 head size
-
-
-
-
OTHER MODULE-LEVEL MODIFICATIONS
-
Position Representations
-
Transformer 具有排列不变性,需要而外位置信息
-
Absolute Position Representations
-
正余弦编码
-
位置向量
-
-
Relative Position Representations.
-
token 之间的关系更加重要
-
将 embedding 加到 key 的attention中
-
Transformer-XL
-
-
Other Representations
-
TUPE
- 混合相对和绝对位置
-
Roformer
-
旋转位置编码
-
线性 attention 中实现相对位置编码
-
-
Position Representations without Explicit Encoding 不要编码
-
R-Transformer 先过 RNN 再将输出结果输入到多头
-
CPE 使用卷积
-
-
Position Representation on Transformer Decoders
- 移除 pe
-
-
-
LayerNorm
-
Placement of Layer Normalization
-
post-LN
-
pre-LN 保证 skip 链接路上没有其他操作
-
-
Substitutes of Layer Normalization
-
可学习参数效果不好,
-
AdaNorm
-
scaled l2 normalization
-
PowerNorm
-
-
Normalization-free Transformer
- ReZero 可学习残差模块替代 LN
-
-
FFN
-
Activation Function in FFN
-
[[Swish]]
-
[[GPT]] [[GELU]]
-
-
Adapting FFN for Larger Capacity
-
product-key memory layers
-
MoE
-
取 top k 专家
-
取最大专家
-
分组取各自 top1
-
-
-
Dropping FFN Layers
-
简化网络
-
-
-
-
-
Arch. Level
-
Adapting Transformer to Be Lightweight
-
Lite Transformer
-
Funnel Transformer
- hidden sequence pooling and up-sampling
-
DeLighT
- DeLighT block
-
-
Strengthening Cross-Block Connectivity
-
针对 decoder 解决问题
-
Transparent Attention
-
Feedback Transformer
- 使用前一步所有层的信息
-
-
[[Adaptive Computation Time]]
-
解决之前模型中层数固定
-
三种方法
-
[[Universal Transformers]]dynamic halting
- 达到停止条件的 token 不再改变
-
CCT
- 跳层
-
-
-
Transformers with Divide-and-Conquer Strategies
-
将 LM 任务中长文本拆分成多个片段
-
Recurrent Transformers 上一个 T 输出信息输入到下一个输入
-
Transformer-XL 上一个输出和下一个输入 concat 在一起
-
-
Hierarchical Transformers 多个结果聚合
-
Hierarchical for long sequence inputs
- sentence Transformer and document Transformer
-
Hierarchical for richer representations 更丰富的表示
- 字母级别表示和词级别表示
-
-
-
Exploring Alternative Architecture
- NAS
-
-
PRE-TRAINED TRANSFORMERS
-
Encoder only
-
Decoder only
-
-
APPLICATIONS OF TRANSFORMER
-
CV
- [[ViT]]
-
-
CONCLUSION AND FUTURE DIRECTIONS
-
理论分析
-
更好全局交互机制
-
处理多种类数据的框架
-
-
[[Layer Normalization]]
A Survey of Transformers
https://blog.xiang578.com/post/logseq/A Survey of Transformers.html