NVIDIA、高速対話型長文脈推論向けAIモデル注意機構の共同設計を発表
本文の状態
日本語全文を表示中
詳細モードで約21分の本文を読めます。
同じ出来事の情報源
この情報源を基点に整理
NVIDIA Developer Blog
NVIDIA は、アジェンシーワークロードの増加に伴う推論時間の増大に対し、グループサイズやシーケンス長といった設計要素がパフォーマンスに与える影響を分析し、高密度アテンションの実用化に向けた具体的なガイドラインを提示した。
AI深層分析を開く2026年8月1日 08:03
AI深層分析
キーポイント
アテンションコストの支配的変化
コンテキスト長が4Kトークンから128Kトークンに拡大する際、アテンションの前処理時間が推論時間の18%から85%へと急増し、アーキテクチャ設計が性能を決定づける要因となっている。
高密度アテンションの最適化要素
クエリヘッドあたりのKVヘッド数(グループサイズ)、ヘッド次元、シーケンス長といったパラメータが、GPU上での実行効率に直接的な影響を与えることが分析された。
NVIDIA GPU向け設計ガイドライン
スループットと対話性を両立させるため、モデル開発者が参照すべき共設計チェックリストが4つの実践的な指針として提示された。
コンテキスト長によるアテンション計算時間の増大
コンテキストが4Kトークンから128Kトークンに拡大すると、プリフィル段階におけるアテンション計算の割合は18%から85%へと劇的に増加する。
長文推論におけるボトルネックの特定
この傾向により、長いコンテキストを扱う際のアテンション計算がシステム全体の主要なボトルネックとなっていることが示される。
重要な引用
Because attention now dominates that cost, how it is designed—not just how it is implemented—increasingly determines a model's inference performance.
Shaping model architecture around how GPUs execute it is the premise of AI model co-design.
Pie charts showing the attention prefill share increasing from 18% to 85% as context grows from 4K to 128K tokens.
Every analysis is grounded in two sources: analytical formulas from GEMM-shape arithmetic, and measured data from prefill and decode kernels with FP8 for both attention compute and the KV cache.
編集コメントを表示
編集コメント
コンテキスト長が拡大する現代のLLM運用において、単なる実装最適化ではなくアーキテクチャ設計そのものの見直しが求められている現状を浮き彫りにしている。NVIDIA が提供する具体的な設計指針は、大規模コンテキスト処理におけるパフォーマンスボトルネック解消への道筋を示す重要な資料である。
Source Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
エージェント型タスクや長文コンテキストを扱うワークロードが一般的になるにつれ、コンテキスト長は拡大し、アテンションにかかる時間が推論全体の占める割合を増大させています(図 1)。現在、このコストの大部分をアテンションが支配しているため、その実装方法だけでなく設計自体が、モデルの推論性能を決定づける重要な要素となっています。GPU の実行特性に合わせてモデルアーキテクチャを設計することが、AI モデルのコデザイン(共設計)の前提条件です。
モデルの設計選択が、精度を損なうことなくスループットと対話性(インタラクティビティ)にどう影響するかについては、前回の投稿 AI Model Co-Design: Hardware-Friendly LLM Design をご参照ください。
本稿では、クエリヘッドあたりの KV ヘッド数(グループサイズ)、ヘッド次元、シーケンス長が、すべてのクエリがシーケンス上のすべてのキーと値にアテンションを向ける「デンス・アテンション」のパフォーマンスにどう影響するかを検証します。GPU 間でのアテンションの並列化方法についても言及し、これらの分析を要約して 4 つの実践的なガイドラインを提示します。これは、NVIDIA GPU 上で推論スループットと対話性を向上させるためのモデル開発者向けチェックリストです。
スパース・アテンションに関する記事も近日公開予定です。
image*図 1. DeepSeek-R1 のプリフィル時間内訳(コンテキスト長 4K、32K、128K)。アテンションの割合は 18% から 85% に上昇します*
すべての分析は、GEMM形状演算に基づく解析式と、アテンション計算および KV キャッシュに FP8 を用いたプリフィル・デコードカーネルの実測データという 2 つの根拠に基づいています。
略語 定義
PB プリフィルバッチサイズ
DB デコードバッチサイズ
QH クエリヘッド数
KH KV ヘッド数 (MHA では KH = QH、GQA では KH = QH/G、MQA では KH = 1)
G グループサイズ = QH/KH (1 つの KV ヘッドを共有するクエリヘッドの数)
Hsz ヘッド次元 (通常は 64, 128, または 256)
ISL 入力シーケンス長 (プリフィル時のクエリトークン数)
KVSL デコード反復における KV キャッシュの平均シーケンス長
*表 1. この記事の数式で使用されている記号*
プリフィルとデコードはなぜ異なる問題なのか?
プリフィルではプロンプト全体を並列処理するため、計算量に依存する大規模な GEMM-M (= ISL × ) 行列積が発生します。一方、推測的デコーディング を用いない場合、デコードはトークンを 1 つずつ生成するため、小規模な GEMM-M (= ) 行列積となり、高帯域幅メモリ (HBM) からの KV キャッシュ読み出しによってメモリアクセスがボトルネックとなります。
推測的デコーディングを用いると GEMM-M が大きくなり、デコード側も計算量依存の処理へとシフトします。ただし、クエリ長や KV アクセス、ボトルネックとなる部分がプリフィルとデコードで異なるため (表 2)、各パラメータはそれぞれのフェーズごとに個別に分析されます。
プリフィル デコード
クエリ長、フル入力(ISL トークン)、KV コンテキスト(プロンプトの ISL トークン)、フル KV キャッシュ(KVSL トークン)、アテンション GEMM-M の計算量、および主要なボトルネックの違いを比較した表です。プリフィルは計算集約型で、デコードはメモリー帯域制約型となります。
*Table 2. プリフィルとデコードは、クエリ長、KV コンテキスト、アテンション GEMM-M の規模、および主要なボトルネックにおいて異なります*
注記:エージェントや多対話アプリケーションで一般的なプレフィックスキャッシングを使用する場合、新しいターンでは ISL が短くても、大規模なプレフィックスキャッシュを参照することがあります。ISL が短くプレフィックスキャッシュが長い場合、プリフィルの動作はデコードに近づきます。
演算量が計算集約型かメモリー制約型かをどう決定するか
Roofline モデルは、GPU の性能を計算能力と帯域幅の上限によって制限します。演算強度(Arithmetic Intensity)がどちらの制約を受けるかを決定します。
演算強度 = 総 FLOPs / 総アクセスバイト数
「リッジポイント」は、メモリー制約型から計算集約型への転換点を示します。プリフィルはこのポイントを大きく上回るため計算集約型であり、デコードは下回るためメモリー制約型となります(図 2)。推測的デコーディングはデコードの演算強度を高め、リッジポイントに近づける効果があります。
image*図 2. メモリバウンド型の勾配部分でデコードが、計算バウンド型の平坦な部分でプリフィルが実行される様子を示す Roofline モデル*
GPU 上で FlashAttention カーネルはアテンションをどのように計算するか?
FlashAttention は、フルサイズの注意行列(attention matrix)を一時的にメモリ上に展開することなくアテンションを計算します。HBM からオンチップ SRAM へ Q、K、V のタイルをストリーミングし、3 つの処理ステップを 1 パスで統合して実行します。
- まず、バッチ化された行列積(BMM1)により、クエリとキーのスコアリングを行います。
- 次に、オンラインソフトマックスがランニング最大値と合計値を用いてスコアを正規化します。
- 最後に、2 回目のバッチ化された行列積(BMM2)で値に重み付けを行います。
これらの行列積は Tensor Core で実行され、ソフトマックスの指数計算は特殊機能ユニットで行われます。この BMM の形状が、後述する演算強度分析の基礎となります。
GEMM 形状
アテンションの性能は、2 つの行列積(matmul)の形状によって決まります。表 3 は、BMM1 と BMM2 の各フェーズにおける(バッチ数、M、N、K)の次元を示しています。
BMM フェーズ バッチ M N K 意味
BMM1 プリフィル PB × KH ISL × G ISL Hsz Q · Kᵀ: クエリとキーのスコア計算
Decode DB × KH 1 × G KVSL Hsz
BMM2 のプリフィルでは、PB × KH が ISL × G に比例し、Hsz ISL の重みと V(集約値)が計算されます。
デコードでは、DB × KH が 1 × G に比例し、Hsz KVSL の KV シーケンス長が計算されます。
*表 3. BMM1 および BMM2 における GEMM (バッチサイズ, M, N, K) の形状*
デコード処理において、GEMM の M は通常 8〜16 と小さく、GPU タイルの M(64 または 128)を大きく下回っています。このため、タイルあたりの並列処理量が制限されてしまいます。より大きなグループサイズを採用すると、トークンあたりに読み込む KV が減り、各読み込みを複数のクエリヘッドで共有できるため、利用効率が向上します。次のセクションでは、この効果を実数値で定量化します。
グループサイズ
グループサイズ () は、1 つの KV ヘッドを共有するクエリヘッドの数を指します。MHA(Multi-Head Attention)では = 1、GQA(Grouped Query Attention)では = 4, 8, 16…、MQA(Multi-Query Attention)では = QH です。
計算密度はグループサイズ () の関数として表されます。以下の式において「Bytes」とは HBM で移動されるバイト数を意味します。簡略化のため、要素あたり 1 バイト(すなわち FP8 KV キャッシュ)であると仮定します。
プリフィル
() が大きくなると、1/ の項は無視できるようになり、計算密度は 2 × ISL に近づきます。ISL = 32K の場合、() を 8 から 16 に上げても計算密度が 6% 未満しか向上しません。つまり、プリフィル処理は () ではなく ISL によって支配されています。図 4 がこれを裏付けており、() を 1(MHA)から 64(MQA)まで変化させても、プリフィルの実行時間は 1% 未満しか変動しません。
式 2, 3, および 4:
**FLOPs = 4 × PB × QH × ISL² × Hsz (は一定)
Bytes = 2 × PB × KH × Hsz × ISL × ( + 1)
計算密度 = 2 × × ISL / ( + 1) = 2 × ISL / (1 + 1/) → () が無限大に近づくにつれ 2 × ISL**
デコード (GEMM-M = )
デコード時の演算集約度を2倍にすると、処理速度が向上します。これを1から8に上げると、メモリトラフィックを削減しGPUの計算リソース利用率を高めることで、8倍の性能向上を実現できます。ただし、これはKVSL(キー・バリューストアメントの長さ)には依存しません。演算集約度はほぼ 2 × のまま維持されるため、 が非常に大きい場合を除き、デコードは依然としてメモリボトルネックに縛られます。
NVIDIA Nemotron 3のようなモデルでは、GQA(グループ化クエリアテンション)を採用しKVヘッドを2つにすることで、デコード効率を高めています。式5、6、7は以下の通りです。
FLOPs = 4 × DB × QH × KVSL × Hsz ( は一定)
Bytes = 2 × DB × KH × Hsz × ( + KVSL)
演算集約度 = 2 × × KVSL / ( + KVSL) ≈ 2 × (KVSL ≫ の場合)
図4に示す通り、の値を2倍にするごとにデコード実行時間は約半分になります。これはKVヘッド数を半分にすることで、トークンあたりの読み込みデータ量が半分になるためです。 が16を超えると、KVSL=32Kの曲線は平坦化します。これは、ステップごとのカーネルが小さすぎるため、固定されたセットアップと後処理のオーバーヘッド、そして少数のKVヘッドで並列性を保つためにKVをSM(ストリーミングマルチプロセッサ)間で分割するフラッシュデコードによる削減効果という2つのコストが支配的になるからです。一方、より長いKVSL=128Kのカーネルはこれらのコストをよりよく分散できるため、2倍の傾向を維持し続けます。
注:スペキュレーティブ・ディコーディングでは、有効なGEMM-M が (1+) × になります( はドラフトトークンの数)。これが計算タイルを埋めるのに十分な大きさに達すると、デコードはメモリ束縛から計算束縛へと移行します。
image*図 4:正規化された実行時間と G の関係(QH=64、Hsz=128、PB=1、DB=8;プリフィル ISL とデコード KVSL はそれぞれ 32K と 128K)。プリフィルは計算リソース制約下で G に依存せず平坦ですが、デコードはメモリー制約下で G が 2 倍になるごとに実行時間が約半分になります(MHA の G=1 から MQA の G=64 まで)*
ガイドライン 1:デコード効率のために G を高く設定する
プリフィルの実行時間は G に依存せず平坦ですが、デコードの演算集約度はおよそ 2×G です。つまり、G を大きくすればデコード速度と GPU の利用率が向上します。また、特定の G でパフォーマンスをさらに引き上げるには、推測的デコーディング(speculative decoding)も有効な手段です。
ヘッド次元
グループサイズとは異なり、ヘッド次元(Hsz)は演算集約度には影響しません。Hsz を 2 倍にすると、FLOPs(式 2 および 5)と必要なバイト数(式 3 および 6)がともに 2 倍になるため、その比率は変わりません。しかし図 5 に示されるように、アテンションカーネルは Hsz の変化に対して異なるスケーリング特性を持つ 3 つの処理を行うため、Hsz が大きくなるほど実行時間は増加します。
- 行列積(Matmul):Hsz に比例して増大しますが、その増加は一定のステップで起こります。前回の投稿では、GPU のタイルサイズやキャッシュライン幅に合わせるため、モデル次元を 128 の倍数にするよう推奨されています。部分的に埋められたタイルも完全なタイルと同じコストがかかるため、Hsz=64 では 128 を支払うことになります。一方、Hsz≥512 はテンソルメモリー(TMEM)の容量限界に近づきます。この観点から、128 と 256 が効率的な選択肢となります。
- メモリー(KV ステート):これも Hsz に比例して増大します。GPU はデータを 128 バイト単位で転送するため、行列積と同様に、Hsz が 128 の倍数のときにメモリアクセスが最も効率的になります。
ソフトマックス演算の特徴は、計算コストが Hsz(ヘッドサイズ)に依存しない点です。これは、アテンションスコア行列(クエリトークン×キー)上で動作するため、ヘッド次元を持たないからです。式 8 と 9 に示される通り、プリフィルとデコードフェーズでの演算量は以下のようになります。
Softmax ops (prefill) ≈ PB × QH × ISL²
Softmax ops (decode) ≈ DB × QH × KVSL
これらのバランスが、各フェーズにおける Hsz のコストを決定します(図 5 参照)。

*図 5. Hsz と正規化実行時間の関係 (QH=64, =32, PB=1, DB=8; プリフィル ISL およびデコード KVSL はそれぞれ 32K、128K)。Hsz が大きくなるほど実行時間は増加します*
プリフィルフェーズは計算集約型(行列乗算とソフトマックスの組み合わせ)です。Hsz を増やすと行列乗算の FLOPs は増加しますが、ソフトマックスの計算量は一定のままです。もしプリフィルが純粋な行列乗算だけで構成されていれば、Hsz を 2 倍にしたときに実行時間も 2 倍になるはずです。しかし、ソフトマックス部分はスケーリングしないため、実行時間の増加は Hsz の増加よりも緩やかになります。図 5 が示す通り、プリフィルの実行時間は Hsz に比例して上昇しますが、その傾きは Hsz そのものの増加率より緩やかです。Hsz を広く取ることでソフトマックスの計算コストを分散(アモタイズ)し、カーネル時間の多くを行列乗算にシフトさせることで、プリフィルがソフトマックスに縛られる状態から解放されます。
一方、デコードフェーズはメモリー集約型です。KV キャッシュをストリーミングする際に、トークンあたりの KV バイト量が Hsz の増加に伴って増えるため(式 6)、実行時間は Hsz に比例して増加するはずです。図 5 はこれを裏付けていますが、わずかに非線形的な挙動を示しています。これは、セットアップやポストプロセッシング、フラッシュデコーディングによるオーバーヘッドが Hsz に依存せず、特に KVSL=32K のような短いカーネルにおいてこれらの固定コストの割合が大きくなるためです。
ガイドライン 2: Hsz は 128 または 256 を使用してください。Hszの値自体が演算集約度を変えるわけではありませんが、ハードウェアに合わせる必要があります。一般的に、Hsz = 64 の場合でも 128 幅のタイル分のコストがかかる一方、Hsz ≥ 512 とすると TMEM(Tensor Memory)容量の限界に近い値になります。このため、128 と 256 が最も適した選択肢となります。
シーケンス長について
シーケンス長(ISL / KVSL)は、それぞれ異なる変数を通じて各フェーズに流入するため、プリフィルとデコードに対して異なる影響を与えます。具体的には、プリフィルではすべての ISL 入力トークンをまとめて処理するのに対し、デコードの各ステップでは長さ KVSL の KV キャッシュを読み込みます。このため両者は異なる速度でスケーリングします(図 6 参照)。
プリフィルは二次関数的にスケーリングする
プリフィルでは ISL² に相当する処理量が発生します(すべてのトークンが他のすべてのトークンとアテンションを行う一方、KV の通信量は ISL に比例して増加します。式 2, 3)。演算集約度は ISL に応じて線形に上昇するため、プリフィルは常に「リッジポイント」よりも上側に位置し、計算ボトルネックとなります。ISL を 2 倍にすると、実行時間は概ね 4 倍になります(図 6 参照)。ただし、ISL が短い場合は固定されたセットアップや後処理のオーバーヘッドが支配的となるため、スケーリングは 4 倍未満にとどまります。十分な大きさの ISL に達し、これらのオーバーヘッドを分散できるようになって初めて、二次関数的なスケーリングが現れます。
デコードは線形にスケーリングする
各ステップでトークン生成時にフルの KV キャッシュを読み込むため、KVSL(キー・バリューシーケンス長)が伸びるにつれてデータ量は増え、1 ステップあたりの計算負荷は小さくなります(式 5 と 6)。演算強度は約 2×程度に留まり、リッジ点を下回る状態が続くため、どの長さでもデコード処理はメモリーバウンドのままです。KVSL を倍にしても実行時間は理論上 2 倍になるはずですが、図 6 はその通りを示しています。
ただし KVSL が短い場合、スケーリング効率は 2 倍に達しません。これはセットアップやポストプロセッシング、フラッシュデコードの削減オーバーヘッドが KVSL に比例して増えないためです。KVSL が大きくなるほど、これらの固定コストの割合は相対的に小さくなります。
image*図 6. シーケンス長に対する正規化実行時間(QH=64, =32, Hsz=256, PB=1, DB=8)。プリフィルは ISL に伴い O(n²) で、デコードは KVSL に伴い O(n) で増加しますが、短い長さでは理想値より低いスケーリングを示します*
ガイドライン 3: 可能な限り有効な KV 状態を減らす。ユースケースによってシーケンス長が決まりますが、コストの増え方は非対称です。プリフィルは ISL の二乗に比例して増加する一方、デコードは KVSL に比例して線形増加します。KV キャッシュ圧縮やスパース・スライディングウィンドウアテンション、あるいは一部の層だけが成長するグローバルな KV 状態を保持するハイブリッドモデルアーキテクチャ(Nemotron 3 など)を用いて、有効な KV 状態を削減しましょう。
テンソル並列化はアテンションヘッドを GPU 間で分割します
テンソル並列処理(TP)は、アテンションヘッドを複数の GPU に分散させます。これにより、各 GPU は QH/TP 個のクエリヘッドと KH/TP 個の KV ヘッドを担当します。重要なのは、この手法がトークンではなく「ヘッド」を分割する点です。
Table 3 のデータを見ると、KH/TP を含むバッチ次元のみが縮小しますが、各 GPU での GEMM(行列積演算)の形状や計算密度は変化しません。
TP には実用上の限界があります。KV ヘッド数は GPU 数で割り切れる必要があります。もし TP が KH より大きくなると、あるグループのクエリヘッドが複数のランクにまたがることになります。その場合、共有される KV ヘッドのコピーを各ランクが必要とするため、KV 状態が重複してしまいます。これはメモリと帯域幅の無駄遣いとなり、何のメリットも生みません(Figure 7 を参照)。したがって、TP は KH 以下に保つべきです。これにより、各 GPU が少なくとも 1 つの完全なグループ(1 つの KV ヘッドとそのクエリヘッド)を専有できるようになります。
KV ヘッド数が少ないモデル(例:Nemotron 3 では 2 つのみ)では、TP をすぐに使い切ってしまいます。なぜなら、GPU あたり 1 つの KV ヘッド未満に分割すると重複が発生するからです。このような場合、アテンションのスケーリング方法は変える必要があります。リクエストを分割する「Attention Data Parallelism(ADP)」と、長文シーケンスの KV キャッシュを GPU に分散させる「KV Parallelism(KVP)」を組み合わせて使用します。一方、FFN(フィードフォワードネットワーク)は、「Expert Parallelism(EP)」を用いて独立してスケーリングされます。
TensorRT-LLM では、これらを組み合わせて Wide EP(注意機構には ADP、FFN には EP)や Helix Parallelism(注意機構には KVP、FFN には EP)を実現しています。いずれのケースでも、効率的なスケーリングを決定するのは KH です。
image*図 7. 注意機構のシャード戦略:TP > KH の場合、KV キャッシュが複製され、メモリと帯域幅にオーバーヘッドが生じます*
ガイドライン 4: KH を用いて並列化戦略を決定してください。TP ≤ KH に保ち、各 GPU が完全な KV ヘッドを持つようにします。KV ヘッドが少ないモデル(MQA の場合 1 つ、GQA の場合 2 つ)では TP がすぐに枯渇するため、注意機構には ADP または KVP を、MoE FFN には EP を用いる方が適しています。これは TensorRT-LLM では Wide EP や Helix Parallelism として実装されています。
AI モデルの注意機構を共設計して始めよう
AI モデルの注意力機構を共設計する際のモデル設計チェックリストとして、以下の 4 つのガイドラインを活用してください。これらの選択により、同じハードウェア上で GPU の利用率、推論速度、スループット、そして対話性を向上させることが可能です。
- ガイドライン 1: デコード時のグループサイズ(Group Size)を選択し、可能な限り高く設定します。プリフィルはグループサイズの感度が低いためです。
- ガイドライン 2: GPU タイルや 128 バイト転送に合わせつつ TMEM バジェット内に収めるため、ヘッド次元(Hsz)を 128 または 256 に設定します。より大きなヘッドサイズを採用すると、プリフィル時のソフトマックス計算も隠蔽できます。
- ガイドライン 3: KV キャッシュの圧縮、スパースまたはスライディングウィンドウアテンション、あるいはハイブリッドモデルの採用などを通じて、実効的な KV 状態量を削減します。
- ガイドライン 4: パラレリズム設定を KV ヘッド数(KH)に合わせます。TP は KH を超えないようにし、Wide EP と Helix Parallelism を活用して複数の KH モデルをスケールさせます。
謝辞
本記事は NVIDIA のクロスチームによる共同作業です。Timmy Liu, Jatin Mitra, Tiyasa Mitra, Bhargava Gopireddy, Brian Pharris, Julien Demouth, Eduardo Alvarez の皆様のご協力に感謝いたします。
原文を表示
As agentic and long-context workloads become common, the context lengths increase and attention consumes a larger share of inference time (Figure 1). Because attention now dominates that cost, how it is designed—not just how it is implemented—increasingly determines a model’s inference performance. Shaping model architecture around how GPUs execute it is the premise of AI model co-design. For a discussion of how model design choices impact both throughput and interactivity without sacrificing accuracy, see the previous post, AI Model Co-Design: Hardware-Friendly LLM Design.
This post examines how group size (query heads per KV head), head dimension, and sequence length shape the performance of dense attention, where every query attends to all keys and values along the sequence length. We distill that analysis, together with how attention is parallelized across GPUs, into four practical guidelines: a co-design checklist that helps model developers raise inference throughput and interactivity on NVIDIA GPUs. Stay tuned for a post covering sparse attention.

Every analysis is grounded in two sources: analytical formulas from GEMM-shape arithmetic, and measured data from prefill and decode kernels with FP8 for both attention compute and the KV cache.
How are prefill and decode two different problems?
Prefill processes the full prompt in parallel, producing large GEMM-M (= ISL × ) matmuls that are compute-bound. Without speculative decoding, decode generates one token at a time, producing small GEMM-M (= ) matmuls and becoming memory-bound by KV cache reads from high-bandwidth memory (HBM).
Speculative decoding increases GEMM-M and can shift decode toward compute-bound. Because the query lengths, KV access, and bottleneck differ for prefill and decode (Table 2), each parameter is analyzed separately for each phase.
Note: With prefix caching, common in agentic and multiturn apps, a new turn may have a short ISL while attending to a large prefix cache. With a short ISL but long prefix cache, prefill behaves like decode.
How does arithmetic determine whether an operation is compute- or memory-bound?
The roofline bounds GPU performance by compute and bandwidth ceilings, as previously explained. Arithmetic intensity determines which binds (Equation 1):
Arithmetic Intensity = Total FLOPs / Total bytes accessed
The *ridge point* marks the transition from memory-bound to compute-bound. Prefill lies well above it and is compute-bound, while decode lies below it and is memory-bound (Figure 2). Speculative decoding raises decode arithmetic intensity and can move it toward the ridge.

How does the FlashAttention kernel compute attention on GPU?
FlashAttention computes attention without materializing the full attention matrix. It streams tiles of , , and from HBM to on-chip SRAM and fuses three steps into one pass:
- First, batched matmul (BMM1) scores queries against keys
- Second, online softmax normalizes the scores using a running max and sum
- Third, second batched matmul (BMM2) weights the values
The BMMs run on Tensor Cores while the softmax exponentials run on special-function units. The BMM shapes drive the arithmetic intensity analysis that follows.
GEMM shapes
Attention performance follows from the shapes of its two matmuls. Table 3 lists the per-phase (Batch, M, N, K) dimensions of BMM1 and BMM2.
For decode, GEMM-M = , usually 8-16, far below a GPU tile-M of 64 or 128, limiting parallel work per tile. Larger loads less KV per token and amortizes each load across more query heads, improving utilization. The next section quantifies this effect.
Group size
Group size () is the number of query heads that share one KV head. MHA has = 1, GQA has = 4, 8, 16, …, and MQA has = QH.
Arithmetic intensity as a function of . In the following formulas, “Bytes” refers to HBM bytes moved. For simplicity, assume 1 byte per element (that is, FP8 KV cache).
Prefill
As grows, the 1/ vanishes and arithmetic intensity approaches 2 × ISL. At ISL = 32K, raising from 8 to 16 improves arithmetic intensity by under 6%. In other words, prefill is dominated by ISL, not . Figure 4 confirms this, varying from 1 (MHA) to 64 (MQA) changes prefill runtime by under 1%. Equations 2, 3, and 4:
**FLOPs = 4 × PB × QH × ISL² × Hsz (constant in )
Bytes = 2 × PB × KH × Hsz × ISL × ( + 1)
Arithmetic Intensity = 2 × × ISL / ( + 1) = 2 × ISL / (1 + 1/) → 2 × ISL as → ∞
Decode (GEMM-M = )
Doubling doubles decode arithmetic intensity. Raising from 1 to 8 gives an 8x gain by reducing memory traffic and improving GPU compute utilization. It is independent of KVSL: arithmetic intensity stays near 2 × , so decode remains memory-bound unless is very large. Models such as NVIDIA Nemotron 3 adopted GQA with two KV heads, which makes decode more efficient. Equations 5, 6, and 7:
FLOPs = 4 × DB × QH × KVSL × Hsz (constant in )
Bytes = 2 × DB × KH × Hsz × ( + KVSL)
Arithmetic Intensity = 2 × × KVSL / ( + KVSL) ≈ 2 × (when KVSL ≫ )
Figure 4 shows decode runtime falls about 2x per doubling of because halving the KV heads halves the data loaded per token. Beyond = 16, the KVSL = 32K curve flattens. Its per-step kernel is small enough that two costs dominate: fixed setup and post-processing overhead, and the flash-decoding reduction from splitting KV across SMs to stay parallel with few KV heads. The longer KVSL = 128K kernel better amortizes these costs and continues tracking the 2x trend.
Note: Speculative decoding raises effective GEMM-M to (1+) × , where is the number of draft tokens. Once large enough to fill compute tiles, decode moves toward compute-bound.

Guideline 1: **Choose for decode efficiency and push it high. Prefill runtime is flat in , while decode arithmetic intensity ≈ 2 × , so higher improves decode speed and GPU utilization. Speculative decoding is another lever to boost performance at a given .
Head dimension
Unlike group size, head dimension (Hsz) does not affect arithmetic intensity. Doubling Hsz doubles both FLOPs (Equations 2 and 5) and bytes (Equations 3 and 6), leaving their ratio unchanged. Yet Figure 5 shows runtime increasing with Hsz because attention kernels perform three types of work that scale differently with Hsz.
- Matmul: Grows with Hsz, but in aligned steps. The previous post recommends model dimensions that are multiples of 128 to align with GPU tile sizes and cache-line widths. A partially filled tile costs as much as a full tile, so Hsz = 64 pays for 128. Hsz ≥ 512 pushes close to the tensor memory (TMEM) capacity limit. That makes 128 and 256 the efficient choices.
- Memory (the KV state): Also grows with Hsz. Since the GPU moves data in 128-byte units, memory access, like matmul, is most efficient when Hsz is multiple of 128.
- Softmax is different: Its cost is independent of Hsz because it operates on attention-score matrix (query tokens × keys), which has no head dimension. Equations 8 and 9:
Softmax ops (prefill) ≈ PB × QH × ISL²**Softmax ops (decode) ≈ DB × QH × KVSL
The balance between these determines Hsz cost in each phase (Figure 5).

Prefill is compute-bound **(matmul plus softmax). As Hsz grows, matmul FLOPs grow while softmax stays fixed. If prefill were pure matmul, doubling Hsz would double runtime; but the fixed softmax does not scale, so runtime rises less than Hsz does. Figure 5 confirms this: prefill climbs with Hsz but slower than Hsz grows. A wider Hsz amortizes softmax, shifting more kernel time to matmul and making prefill less softmax-bound.
Decode is memory-bound (streaming the KV cache). Larger Hsz increases KV bytes per token (Equation 6), so runtime should scale with Hsz. Figure 5 confirms this, though slightly sublinearly because setup, post-processing, and flash-decoding reduction overheads don’t scale with Hsz and weigh more on the shorter KVSL = 32K kernel.
Guideline 2: Use Hsz of 128 or 256. Hsz doesn’t change arithmetic intensity but must align with the hardware. Typically, Hsz = 64 still pays for a 128-wide tile, while Hsz ≥ 512 pushes close to the TMEM capacity limit. That makes 128 and 256 the sweet spot.
Sequence length
Sequence length (ISL / KVSL) affects prefill and decode differently, because it enters each phase through a different variable: prefill processes all ISL input tokens together, while each decode step reads a KV cache of length KVSL. The two therefore scale at different rates (Figure 6).
Prefill scales quadratically
Prefill performs ISL² work (every token attends to every token), while KV traffic grows only proportional to ISL (Eq. 2, 3). Arithmetic intensity therefore rises linearly with ISL, keeping prefill well above the ridge point and compute-bound. Doubling ISL should roughly quadruple runtime (Figure 6). At short ISL, scaling is below 4x because fixed setup and post-processing overheads dominate; quadratic scaling appears once ISL is large enough to amortize them.
Decode scales linearly
Each step reads the full KV cache to generate one token, so bytes grow with KVSL while per-step work remains small (Equations 5 and 6). Arithmetic intensity stays near 2 × , well below the ridge point, so decode remains memory-bound at all lengths. Doubling KVSL should double runtime, which Figure 6 confirms. At short KVSL, scaling is below 2x because setup, post-processing, and flash-decoding reduction overheads don’t scale with KVSL. Their share shrinks as KVSL grows.

Guideline 3: Reduce effective KV state where possible. The use case sets sequence length, but the cost is asymmetric: prefill grows as ISL², while decode grows linearly with KVSL. Reduce effective KV state through KV-cache compression, sparse or sliding-window attention, or hybrid model architectures (like Nemotron 3) where only some layers carry the growing global KV state.
Tensor parallelism splits attention heads across GPUs
Tensor parallelism (TP) splits the attention heads across GPUs, giving each GPU QH/TP query heads and KH/TP KV heads. It shards heads, not tokens. In Table 3, only the batch dimension, containing KH/TP, shrinks; the per-GPU GEMM shape and arithmetic intensity remain unchanged.
TP has a practical limit: KV heads must divide evenly across GPUs. Once TP > KH, a group’s query heads span multiple ranks, each requiring a copy of the shared KV head. This duplicates KV state, adding memory and bandwidth overhead without benefit (Figure 7). Thus, keep TP ≤ KH so each GPU owns at least one complete group: one KV head and its query heads.
Models with few KV heads (Nemotron 3 with two, for example), quickly exhaust TP because the cache cannot be sharded below one KV head per GPU without duplication. Attention must then scale differently: Attention Data Parallelism (ADP) shards requests, while KV Parallelism (KVP) shards long-sequence KV caches across GPUs. The FFN scales separately with Expert Parallelism (EP).
TensorRT-LLM combines these as Wide EP (ADP for attention plus EP for the FFN), and Helix Parallelism (KVP for attention plus EP for the FFN). In both cases, KH determines efficient scaling.

Guideline 4: Let KH determine the parallelism strategy. Keep TP ≤ KH so each GPU has a full KV head. Models with few KV heads (MQA with 1, or GQA with 2) exhaust TP quickly and are better served by ADP or KVP for attention plus EP for the MoE FFN (implemented as Wide EP and Helix Parallelism in TensorRT-LLM).
Get started co-designing AI model attention
Use the four guidelines summarized below as a model design checklist to get started co-designing AI model attention. These choices can improve GPU utilization, inference speed, throughput, and interactivity on the same hardware.
- Guideline 1: Choose the group size () for decode and push it high. Prefill is not sensitive to group size.
- Guideline 2: Use a head dimension (Hsz) = 128 or 256 to align with the GPU tiles and 128-byte transfers while staying within TMEM budget. A larger head also hides softmax in prefill.
- Guideline 3: Reduce effective KV state through KV-cache compression, sparse or sliding-window attention, or hybrid models.
- Guideline 4: Match parallelism to KV head count (KH). Keep TP ≤ KH and scale a few KH models with Wide EP and Helix Parallelism.
Acknowledgments
*This post is an NVIDIA cross-team effort. We are grateful to Timmy Liu, Jatin Mitra, Tiyasa Mitra, Bhargava Gopireddy, Brian Pharris, Julien Demouth, and Eduardo Alvarez for their help.*
AI算出
技術分析ainew評価高い
NVIDIA が GPU 実行特性に合わせた AI モデルのアテンション機構の共同設計手法を発表しており、プリフィルとデコードフェーズの違いに基づく詳細な技術分析が含まれているため、AI 関連度と新規性は高い。ただし、日本企業固有の情報や日本語一次情報ではなく、一般的な技術指針であるため日本の関連性は中程度となる。
6つの評価軸を見る
- AI関連度
- 100
- 情報源の信頼性
- 100
- 新規性
- 75
- 調べる価値
- 75
- 重複の少なさ
- 100
- 日本での有用性
- 25
関連記事
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み