Transformer 的競爭者們
Mamba
每一種架構的存在都有一個理由
Fully Connected Layer
Receptive Field
Parameter Sharing
Convolutional Layer
Larger model bias
(for image)
Jack of all trades,
master of none
根據影像的特性,減少不必要的參數,避免 Overfitting
每一種架構的存在都有一個理由
https://youtu.be/OP5HcXJg2Aw?si=RPfmHhsrMtuN0QS6
每一種架構的存在都有一個理由
Testing Data
Overfitting?
Training Data
Optimization issue
Source of image: http://arxiv.org/abs/1512.03385
每一種架構的存在都有一個理由
Source of image: https://arxiv.org/abs/1712.09913
……
……
Self-attention Layer
Layer
Layer
Layer
Layer
Layer
Layer
Layer
Layer
Transformer 出現的理由是甚麼呢?
Transformer Layer (Block)
RNN (LSTM)
Mamba (and its friends)
要解的問題
……
RNN, Self-Attention, Mamba …
……
RNN-Style
……
Hidden
State
RNN-Style
……
……
……
Vector,
Matrix, …
RNN-Style
……
……
……
Vector,
Matrix, …
RNN-Style
xt
z
zi
zf
zo
yt
xt+1
z
zi
zf
zo
yt+1
ht
ht-1
ct-1
ct
ct+1
LSTM
RNN-Style vs. AI Agent’s Memory
RNN-Style vs. AI Agent’s Memory
……
……
……
Vector,
Matrix, …
Memory
Read
Write
Reflection
LLM
<BOS>
大
家
好
,
我
大
家
好
,
我
是
RNN-style
Self-Attention Style
Soft-max
……
+
x
x
x
x
Self-Attention Style
……
Attention 的概念很早就有了
Neural Turing Machine
https://arxiv.org/abs/1410.5401
Memory Networks
https://arxiv.org/pdf/1410.3916
Attention 的概念很早就有了
https://arxiv.org/abs/1611.08656
Attention-based Memory Selection Recurrent Network for Language Modeling
Da-Rong Liu
LLM
<BOS>
大
家
好
,
我
大
家
好
,
我
是
每一步運算量都一樣
輸入越長,運算量越來越大
RNN 沒辦法記大量資訊?
https://arxiv.org/abs/1706.03762
不是發明 Attention ,而是拿掉 Attention 以外的東西
語言模型的訓練 (找出參數)
Backpropagation
https://youtu.be/ibJpTrp5mcE
https://youtu.be/-yhm3WdGFok?si=2cZOANbtm0Mjd9lT
Computational Graph
語言模型的訓練 (找出參數)
語言模型
……
???
2. 計算差異
1. 得到目前的答案
3. 更新參數
語言模型的訓練 (找出參數)
假設我們想要教模型說「大 家 好 , 我 是 ……」
語言
模型
語言
模型
語言
模型
大
家
好
<BOS>
<BOS> 大
<BOS> 大 家
???
???
???
語言模型的訓練 (找出參數)
假設我們想要教模型說「大 家 好 , 我 是 ……」
是
???
語言
模型
<BOS>
大
家
好
,
我
???
???
???
???
???
大
家
好
,
我
LLM
<BOS>
大
家
好
,
我
大
家
好
,
我
是
給定完
整輸入
0
0
=
=
=
=
softmax
=
令 GPU 歡喜的計算過程
LLM
<BOS>
大
家
好
,
我
大
家
好
,
我
是
給定完
整輸入
GPU 討厭等待
Self-attention vs. RNN-style
| Self-attention | RNN |
Inference | 計算量、記憶體需求隨著序列長度增加 | 計算量、記憶體需求固定 |
Training | 容易平行化 | 難以平行化(?) |
Source of image: https://www.artfish.ai/p/long-context-llms
RAG、AI Agent 都需要語言模型處理很長的序列
影像、聲音是比文字更長的序列
RNN 有沒有訓練時平行的可能性
……
RNN 有沒有訓練時平行的可能性
……
RNN 有沒有訓練時平行的可能性
……
RNN 有沒有訓練時平行的可能性
……
RNN 有沒有訓練時平行的可能性
……
RNN 有沒有訓練時平行的可能性
這不就是 Self-attention!
(少了 softmax)
叫做 Linear Attention
RNN
Linear Attention
Linear Attention
Training 的時候像 Self-attention
Inference 的時候像 RNN
Training
Inference
…
…
Linear Attention
=
+
……
要寫入記憶的資訊
要寫到哪裡
1
0
0
Linear Attention
=
不同資訊存不同 Column
從哪一個 column 取多少資訊
0
1
0
……
這不是甚麼新想法 ……
https://youtu.be/yHoAq1IT_og?si=pSymySFnZqQj51Ik
Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention
https://arxiv.org/abs/2006.16236
RNN (Linear Attention) 贏不過 Transformer (Self-attention with Softmax)?
RNN (Linear Attention)
Transformer (Self-attention with softmax)
記憶太小
記憶有限
無限記憶?
……
……
RNN (Linear Attention) 贏不過 Transformer (Self-attention with Softmax)?
RNN (Linear Attention)
=
+
=
Transformer (Self-attention with softmax)
……
Transformer (Self-attention with softmax)
……
……
+
記憶開始錯亂
RNN (Linear Attention) 贏不過 Transformer (Self-attention with Softmax)?
0.6
1
0.4
0.5
1
0.5
2
1
很重要的事
很重要的事
更重要的事
0.30
0.45
0.25
0.10
0.17
0.10
0.46
0.17
相對沒那麼重要了
Soft-max
Soft-max
Linear Attention 記憶永不改變
加上 Reflection: 逐漸遺忘
https://arxiv.org/abs/2307.08621
Linear Attention
Retention Network (RetNet)
加上 Reflection: 逐漸遺忘
Training
Inference
……
……
加上 Reflection: 根據情況遺忘
https://arxiv.org/abs/2405.05254
Retention Network (RetNet)
Gated Retention
加上 Reflection: 逐漸遺忘
Training
Inference
……
……
更複雜的 Reflection
……
……
……
……
……
抹去
保留
減弱
https://arxiv.org/abs/2406.06484
https://arxiv.org/abs/2312.00752
125M to 1.3B
https://arxiv.org/abs/2312.00752
DeltaNet
https://arxiv.org/abs/2406.06484
Titans: Learning to Memorize at Test Time
https://arxiv.org/abs/2501.00663
Parameter
after update
before
update
learning rate
gradient
Gradient Descent
https://arxiv.org/abs/2408.01129
Minimax-01
https://arxiv.org/abs/2501.08313
https://arxiv.org/abs/2410.10629
MambaOut: Do We Really Need Mamba for Vision?
https://arxiv.org/abs/2405.07992
Do not train from scratch
Low-rank Linear Conversion via Attention Transfer (LoLCATs), https://arxiv.org/abs/2410.10254
The Mamba in the Llama, https://arxiv.org/abs/2408.15237
Transformers to SSMs, https://arxiv.org/abs/2408.10189
Linger, https://arxiv.org/abs/2503.01496
Self-attention Layer
Mamba or its friends
https://www.isattentionallyouneed.com/
https://www.isattentionallyouneed.com/