我想要一天分享一點「LLM從底層堆疊的技術」,並且每篇文章長度控制在三分鐘以內,讓大家不會壓力太大,但是又能夠每天成長一點。
- Attention Layer的複雜度是O(n^2 * d)
- Recurrent Layer的複雜度是O(d^2 * n)
這些資料出自於ChatGPT的關鍵技術 - Transformer的原始Google論文:Attention is All You Need, Vaswani et al. (2017)
我們在AI說書 - 從0開始 - 9,已經完成Colab Python GPU環境配置。現在目標是想要用Python來做模擬,且使用GPU當作運算資源,我們已經在AI說書 - 從0開始 - 10得出以下結論:
- 使用Attention Layer耗費: 2.8872秒
- 使用Recurrent Layer耗費: 36.3216秒
接著我們可以來計算一下百分比:
total = attention_time + recurrent_time
percentage_attention_time = round((attention_time / total) * 100, 2)
print(f"The percentage of self-attention computation in the sum of self-attention and recurrent computation is {percentage_attention_time}%")
對此,執行結果為:
