7
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Multi-Head Attention と Multi-Query Attention と Grouped-Query Attention

Posted at

Multi-Head Attention は性能がいいけど、遅い。

一時期流行った Bert から、現在流行っている ChatGPT のような大規模言語モデルまで、最近のモデルには Transformer という機構が利用されています。
この Transformer には Multi-Head Attention という要素技術が使われています。
ただ、Multi-Head Attention は Key と Value のロードに伴うメモリ帯域幅のオーバーヘッドが大きいという問題がありました。

Multi-Query Attention は早いけど、品質劣化の可能性がある

そのメモリへのオーバーヘッドを解消するために提案されたのが Multi-Query Attention です。

Multi-Query Attention は単一のキー・バリューヘッドのみを使用することで、デコーダの推論を大幅に高速化します。
しかし、Multi-Query Attention は品質の劣化を招く可能性がありました。
(「Head が複数だと時間かかるけど性能いい。一方、1 個だと早い代わりに性能的には不十分だよね」という話)

Multi-Head と Multi-Query の中間択:Grouped-Query Attention

Grouped-Query Attention は下図のように、Head のサブグループごとに共有します。
Grouped-Query Attention は、マルチヘッドアテンションに近い品質を実現しつつ、マルチクエリアテンションとほぼ同じ速度で動作するらしいです。
(Multi-Query よりは遅い気もしますが、論文曰く同等らしいです。)

7
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?