2024-06-11|閱讀時間 ‧ 約 23 分鐘

AI說書 - 從0開始 - 11

我想要一天分享一點「LLM從底層堆疊的技術」,並且每篇文章長度控制在三分鐘以內,讓大家不會壓力太大,但是又能夠每天成長一點。


回顧我們在AI說書 - 從0開始 - 6中說當Context長度是n,且每個字用d維度的向量表示時有以下結論:

  • 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}%")

對此,執行結果為:



分享至
成為作者繼續創作的動力吧!
這頻道將提供三分鐘以內長度的AI知識,讓你一天學一點AI知識,每天進步一點
© 2024 vocus All rights reserved.