AIニュース最前線
最新ニュースAI日報Hacker日報週報動画AIツールトレンド企業

AIニュース最前線

世界中のAI最新情報を日本語で毎時更新

最新ニュース日報トレンド企業プレミアムRSS
© 2026 ainew.jp特定商取引法に基づく表記
ニュース一覧元記事を開く
TLDR AI·2026年6月16日 09:00·約21分で読める

AI推論エンジニアリングへのガイド(17分読了)

#LLM#推論最適化#vLLM#量子化#KV キャッシュ
TL;DR

TLDR AI は、大規模モデルの推論コスト削減とレイテンシ改善に向けたエンジニアリング戦略を体系的に解説し、実装レベルでの最適化手法を提示している。

AI深層分析2026年6月17日 03:06
4
重要/ 5段階
深度40%
5
関連度30%
5
実用性20%
4
革新性10%
3

キーポイント

1

推論コストとレイテンシのトレードオフ管理

モデルサイズ、バッチ処理、量子化などのパラメータ調整が、コストと速度に与える影響を定量化し、バランスを取る戦略を解説している。

2

高度な最適化技術の活用

KV キャッシュ管理、継続的バッチ処理(Continuous Batching)、および推論フレームワーク(vLLM など)の具体的な実装手法を紹介している。

3

アーキテクチャレベルでの設計指針

単一モデルの最適化だけでなく、ラージ言語モデルを構成するパイプライン全体や、マルチモデル連携におけるインフラ設計の重要性を強調している。

影響分析・編集コメントを表示

影響分析

本記事は、LLM の実装フェーズにおいて「モデル選び」だけでなく「どう動かすか」というエンジニアリングの重要性を再認識させる内容であり、開発者がコスト効率の高いシステム設計を行うための具体的なロードマップを提供する。特に、大規模な推論負荷に対応するための技術的ベストプラクティスは、業界全体のパフォーマンス向上に寄与する重要な指針となる。

編集コメント

モデルの性能だけでなく、運用コストと速度をどう両立させるかという実務的な課題に対し、技術的詳細まで踏み込んだ解説が非常に有益です。

制御のない速度は偽りの経済です。AI コード生成がソフトウェア納品を加速する中、FeatureOps Summit 2026 は、より多く出荷する際に壊れることがないようにするためにここにあります。この主要なバーチャルイベントでは、Wayfair、Visa、Mintlify、Lloyds など多くの企業のエンジニア、アーキテクト、製品リーダーが集まり、恐れなき納品のインフラストラクチャーを探求します。

主要テーマ:

AI セーフティネット: 自動生成コードの洪水に対するガードレール。エッジ耐性: スケールにおけるサブミリ秒評価。継続的フロー: 「固定リリース」マインドセットからの脱却。失敗しないリリース環境に必要なツールとパターンを習得するために、今日登録してください。

Register Today

LLM が応答を生成するたびに、同じ GPU 上で 2 つの操作が連続して実行されます。最初の操作は入力プロンプトを処理し、単一のトークンを出力します。2 つ目の操作は、その後のすべてのトークンを一度に一つずつ生成します。

外側から見ると、これらは一つのプロセスの段階のように見えます。しかし、ハードウェア内部では、これらには相反するボトルネックがあります。一方は純粋な計算能力によって制限され、他方はメモリを通過するデータの速度によって制限されます。生産環境の AI システムを高速化するエンジニアリング作業の多くはこの分裂に起因しており、それを処理するために使用される技術が推論工学(inference engineering)の基礎となっています。

推論エンジニアリングは、訓練済み AI モデルを生産環境で効率的に実行するための分野です。この仕事には、低レベルの GPU コード、モデルサービングフレームワーク、そしてそれらを結びつけるクラウドインフラストラクチャが含まれます。この分野のエンジニアたちは、レイテンシ(遅延)、スループット、コスト、品質のいずれかの組み合わせを最適化の対象としますが、具体的なバランスは支援する製品によって異なります。数年前までは、こうした仕事はほぼ完全に最先端 AI 研究所の中で行われていました。今日では、本格的な AI ワークロードを実行するあらゆる企業が投資する広範な専門分野となっています。

この記事では、推論がどのように機能し、なぜこの分野の最適化技術が存在するのかを順を追って解説します。

*免責事項:本投稿は、さまざまなソースから公開された詳細に基づいています。不正確な点にお気づきの方はコメントをお願いします。*

3 年前、推論エンジニアリングはほぼ完全に最先端 AI 研究所内で実践される専門分野でした。この仕事は、業界の他の部分が API を通じて消費するクローズドモデルを構築する少数のエンジニアたちに関わるものでした。しかし、2024 年以降、この状況は劇的に変化しました。

オープンモデルがこの変化を牽引しました。AI モデルの公開レジストリである Hugging Face には、現在 200 万を超えるオープンモデルが登録されており、5 年前の数値のおよそ 25 倍に達しています。DeepSeek V3 などのオープンリリースにより、クローズドモデルとの能力格差は縮まり、企業にとってはクローズド API の利用料を支払うか、自前でオープンモデルを実行するかという現実的な選択肢が生まれました。

オープンモデルを自社でホストすることは、クローズド API に比べて以下の 3 つの運用上の利点をもたらします:

  • レイテンシプロファイルは、特定の製品のワークロードパターンに合わせてチューニング可能であり、パブリック API は多くの顧客にわたる一般的なスループットを最適化しています。
  • 専用デプロイメントではアップタイムが 4 つの 9(99.99%)以上を達成でき、パブリック API で典型的な 2 つの 9(99.9%)と比較して有利です。
  • スケール効果により、エンジニアリング投資に見合うボリュームに達すれば、コストは通常約 80% 低下します。

その結果、多くのカテゴリの企業が本格的な推論スタックを構築するようになり、AI ネイティブのスタートアップから既存ワークフローに AI を統合した確立された製品、さらに従来慎重だった医療分野に至るまで含まれています。

Cursor は代表的な例です。同チームはオープンモデルの上に Composer 2.0 を構築し、広範な推論エンジニアリングを適用することで、クローズド API が提供するものよりも低いオートコンプリートのレイテンシを実現しました。

なぜ推論エンジニアリングが現在の姿をしているのかを理解するには、プロンプトが LLM(大規模言語モデル)に到達した際に実際に何が起こるかを理解する必要があります。このプロセスは、GPU に対して非常に異なる物理的負荷を要求する 2 つのフェーズに分かれます。

トークンは、LLM が扱う原子単位です。おおよそ、単語または単語の一部を指します。「inference」という単語は 1 トークンですが、「engineering」は 2 つに分割される可能性があります。秒間あたりのトーク数(tokens per second)というレイテンシ指標もこの単位で計測されます。

最初のフェーズはプリフィル(prefill)と呼ばれます。

モデルは入力プロンプト全体を受け取り、すべての重み層を並列に処理します。このバーストから得られる2 つの出力とは、応答の最初のトークンと KV キャッシュです。KV キャッシュは、アテンション機構からの中間値を保存する構造体であり、より多くのトークンが生成される際に参照できるようになっています。

プリフィル(初期処理)は計算リソースに制約されます。GPU の数値演算ユニットがボトルネックとなります。なぜなら、すべての入力トークンがモデルの各層を通じて同時に処理されるためです。この段階には、より多くの純粋な計算能力を投入することで高速化が可能です。プリフィルのパフォーマンスを表す指標は「最初のトークンまでの時間(TTFT)」です。ChatGPT にプロンプトを送信してから最初のトークンが表示されるまでのわずかな遅延が、まさにプリフィルの動作を示しています。

2 つ目のフェーズはデコードフェーズです。モデルは各トークンを1 つずつ生成し、各トークンに対して重み層全体を順方向に完全に通します。新しいトークンはそれ以前のすべてのトークンに依存するため、このプロセスは本質的に逐次的になります。長い応答では、GPU はこれを数千回実行することになります。

デコードはメモリー帯域幅に制約されます。数値演算のスループットは主にアイドル状態となり、GPU のサイクルの多くは、各順方向パスのためにメモリからモデル重みを読み込むことに費やされます。ボトルネックは演算ではなくデータ転送にあります。デコードのパフォーマンスを表す指標は「1 秒あたりのトークン数(TPS)」です。長い応答におけるストリーミング速度が、まさにデコードフェーズの動作を示しています。

prefill と decode は逆のボトルネックを抱えているため、一方のフェーズを加速する技術は他方のフェーズにはほとんど影響を与えません。これがベンチマークで TTFT(Time To First Token)と TPS(Tokens Per Second)が別々の数値として報告され、各フェーズのパフォーマンスが独立して測定される理由です。

この分割はまた、推論エンジニアリングの残りの部分を組織化する構造的洞察でもあります。prefill と decode を2 つの異なる操作として理解すれば、分野内の技術は自然と3 つのグループに分類されます:prefill を加速するもの、decode を加速するもの、そして両者のバランスを再調整するものです。

上記の図は少し単純化されています。実際の推論エンジンでは、バッチ処理やスケジューリングなど、他の複雑な要素が層状に重ねられて実行されており、そのすべての下で prefill-decode の分割という構造が維持されています。これが、本記事の残りの部分の基礎として機能する理由です。

prefill-decode の分割を意識すれば、推論エンジニアリングにおける主要な技術ははるかに整理しやすくなります。各技術は特定のフェーズを加速するか、異なる理由で両方に作用するか、あるいはシステム構造そのものをこの分割を中心に再構築します。

それでは、6 つの技術をそれぞれ詳しく解説しましょう。

バッチ処理(Batching)は、単一の GPU の出力をスケーリングする最も基本的な方法です。推論エンジンは複数のリクエストをトークン単位で織り交ぜて実行するため、1 つの GPU で同時に多くのユーザーに対応できます。GPU の計算容量がリクエスト間のアイドル状態ではなく最大限に活用されるため、スループットは大幅に向上します。

その代償として、ユーザーごとのレイテンシが増加します。

バッチ処理を行わないシステム上の単一ユーザーは、可能な限り最短の応答時間を得ますが、同じユーザーが重度にバッチ処理されたシステムでは、GPU が他のリクエストも処理しているため、より長い待ち時間が発生します。このトレードオフこそが、あらゆる他の技術が回避しようとする主要な緊張関係であり、異なる製品はこのスペクトラム上の異なる地点で位置づけられています。消費者向けのチャットツールは低レイテンシを重視し、バッチ処理パイプラインは高いスループットを優先する傾向があります。

プレフィックスキャッシング(先頭部分キャッシュ)は、リクエスト間で KV キャッシュ(キー・バリューキャッシュ)の値を再利用することで、プリフィル(事前計算)フェーズを加速します。2 つのプロンプトが共通の冒頭セグメント(例えば、数千件のリクエストで同一となる長いシステムプロンプトなど)を共有する場合、エンジンはそのプレフィックスを一度だけ計算し、その後はキャッシュから読み出します。これが API プロバイダーがキャッシュされた入力トークンに対して料金を安く設定する理由です。

ただし、このキャッシュの恩恵は、シーケンスの先頭から最初の不一致トークンに至るまでしか得られません。2 つのプロンプト間で最初のトークンが異なる場合、残りのシーケンスが完全に一致していても、プレフィックスキャッシングによる節約効果はゼロとなります。したがって、プロンプトの構造には直接的なコストとレイテンシへの影響があり、共有コンテンツを先頭に配置し、可変的なユーザー入力を後方に配置することで、キャッシュが活用できる余地を作ることができます。

量子化(Quantization)は、異なる理由ではあるものの、推論の両フェーズにおいて有益です。

基本となる手法は、モデルの重みをより低い精度の数値形式で保存することです。現代のほとんどのモデルは 16 ビット浮動小数点(floating-point)で学習されますが、量子化(quantization)によってこれらの値を 8 ビットまたは 4 ビットの表現に圧縮します。これにより、重みのサイズが小さくなりメモリ使用量が削減され、データ転送の必要も減ります。

プリフィル(prefill)が高速化する理由は、現代の GPU 内部にある専用数学演算ユニット上で低精度の計算がより速く実行されるためです。デコード(decode)が高速化する理由は、メモリ帯域幅への負荷が軽減され、各フォワードパスで重みをメモリからより迅速に読み込めるようになるためです。精度を一段階下げることで、モデルや適用された技術によって異なりますが、概ね 30% から 50% の性能向上が得られます。

その代償として、品質の低下というリスクがあります。また、モデル内の異なる部分は量子化に対して異なる耐性を持っています。

線形層(linear layers)の重みはこれに良く耐えますが、活性化値(activations)はやや敏感であり、KV キャッシュ(KV cache)はさらに敏感です。そして何よりも、アテンション層(attention layers)が最も敏感です。その理由は、アテンション層における小さな精度誤差がトークンのシーケンス全体にわたって累積し、各トークンの計算が前の計算に基づいて行われるためです。そのため、わずかな誤差でも長い応答期間中に雪だるま式に膨らみ、意味のある品質低下へとつながります。

この理由から、多くの本番環境(production)のセットアップでは、アテンション層は完全な精度で維持されます。量子化におけるエンジニアリング作業の大部分は、どの部分を圧縮し、どれほど積極的に圧縮するかを決定することに帰着します。

Speculative decoding は、非対称性を活用することでデコードプロセスを加速します。ゼロからトークンを生成するのは高コストですが、候補となるトークンがメインモデルが生成するものと同じかを確認することははるかに安価です。この点で、数独のパズル解決には労力が必要である一方、完成したパズルの確認は迅速であるというアナロジーが成り立ちます。

Speculative decoding では、小さなドラフトモデルが次のいくつかのトークンを予測し、メインモデルがそれらすべてを単一のフォワードパスで検証します。メインモデル自身の予測と一致するトークンは受け入れられ、残りは拒否されます。その結果、通常は 1 つしか現れないはずのトークンが、メインモデルを通る単一のフォワードパスあたり複数個出現することになります。

Speculative decoding は、プリフェッチ(prefill)が通常通り実行されるため、TPS(Tokens Per Second)を向上させつつ、TTFT(Time To First Token)は変化させません。この手法は、GPU に余剰な計算リソースがあり検証に費やせる場合、つまりバッチサイズが小さい場合に最も効果的です。一方、バッチサイズが大きくなり一度に多くのリクエストを処理している場合は GPU がすでに飽和状態であり、すべてのサイクルがメインのワークロードに必要なため、推測(speculation)は動的に無効化されます。

並列化技術により、単一の GPU では不足する場合、つまりモデルが大きすぎてメモリに収まらない場合や、単一 GPU のレイテンシが高すぎる場合に、大規模モデルを複数の GPU にわたって実行することが可能になります。オープンなモデルの現状において支配的な 2 つの主なアプローチは、テンソル並列化(tensor parallelism)とエキスパート並列化(expert parallelism)です。

テンソル並列化は、モデルの各層を複数の GPU に分割します。各 GPU は各層の一部を持ち、順伝播ごとに作業を共有します。これには NVIDIA の NVLink などの高帯域幅インターコネクトが必要であり、結果は各層の後に結合される必要があるためです。テンソル並列化は、非常に大規模な密モデル(dense models)のサービスにおいてデフォルトの選択肢となります。ここでは、帯域幅を多く消費する通信が、層ごとの作業を共有することによる速度向上によって相殺されます。

エキスパート並列化は、混合エキスパートモデル(mixture-of-experts models)に特化した手法です。このモデルでは、各トークンに対してモデルパラメータの一部のみが活性化します。異なるエキスパートは異なる GPU に分散され、トークンは必要なエキスパートへルーティングされます。エキスパートは独立して動作するため、通信オーバーヘッドはテンソル並列化よりも低く、帯域幅がより限られているマルチノード展開に適しています。実際の生産環境でのデプロイでは、両方を組み合わせて使用することが多く、ノード内ではテンソル並列化を、ノード間ではエキスパート並列化を採用します。

非集約(disaggregation)は、プリフィルとデコードの分割を文字通り適用するアプローチです。アイデアとしては、プリフィルをある GPU セットで実行し、デコードを別の GPU セットで実行し、KV キャッシュ(Key-Value cache)をネットワーク経由で両者の間で転送することです。各セットは特定のボトルネックに最適化されたハードウェアを使用し、それぞれのトラフィックパターンに基づいて独立してスケーリングします。

このフローは 3 つのステップのプロセスになります:

  • Prefill エンジンは入力シーケンスを受け取り、最初のトークンと KV キャッシュを生成します。
  • このキャッシュは高速な相互接続を介してデコードエンジンに送信され、デコードエンジンがその後のすべてのトークンを処理します。
  • 条件付きの分離では、短いかすでにキャッシュされたリクエストはハンドオフを完全にスキップし、デコードエンジンだけで実行されます。これは、長いプロンプトと短いプロンプトの混合を含む実際のトラフィックに対してより優れたパフォーマンスを発揮します。

分離(disaggregation)は、ここで取り上げられた技術の中で最もアーキテクチャ的なアプローチです。これは、prefill と decode を別々のサービスとして扱い、それぞれに異なる運用上の課題があるものとして扱います。これにより、オペレーターは各サービスを独立してスケールするためのレバーを手にすることができます。大規模な推論を実行している企業では、ワークロードのミックスが十分に理解された段階で、この手法をほぼ必須のステップと考えることが一般的です。

これらの技術を本番環境に導入することは真剣に取り組むべき課題であり、複数の技術を組み合わせることでさらに複雑さが増します。すべてのエンジニアリングチームが答えなければならない問いは、この作業を引き受けるか、それとも市販の API のままが適切な選択かどうかです。その答えは製品の段階によって異なります。

AI プロダクトの構築初期段階では、確立されたプロバイダーからの市販 API を利用することがほぼ常に最適な選択です。意味のある最適化には、実際に機能する現実的な制約が必要であり、初期段階のプロダクトはトラフィックパターン、レイテンシ要件、単体経済性について不確かな仮定を抱いている傾向があります。この段階でのエンジニアリングの努力は、プロダクトをリリースすることに注ぐべきです。なぜなら、カスタム推論スタックの運用に伴う複雑さが、実際には重要となるイテレーション速度を低下させてしまうからです。

方程式が変化したことを示すシグナルとして、通常以下の 3 つが挙げられます:

  • API コストが意味のある支出項目に成長した。
  • レイテンシ要件がクローズド API が提供できる範囲を超えた。
  • 信頼性要件がベンダーの SLA で保証されるレベルを上回り始めた。

Cursor はこの移行をうまく処理しました。サブ秒単位の自動補完レイテンシこそがプロダクトそのものであり、クローズド API は多数の顧客にわたる一般的なスループットを目指しますが、コード補完モデルは特定の速度形状を要求します。オープンモデルをセルフホストし、スタック全体に推論エンジニアリングを適用することで、レイテンシ目標を達成可能にし、投資対効果も得られました。なぜなら、制約が現実的なものであり、ワークロードが十分に理解されていたからです。

LLM 推論は、物理的制約が正反対である 2 つの操作から成り立っています。

Prefill は計算リソースに制約され、1 リクエストごとに 1 回実行されます。Decode はメモリー帯域幅に制約され、トークン生成ごとに 1 回実行されます。推論エンジニアリングにおける技術のほとんどは、この 2 つのフェーズの分離によって存在しており、これを理解することが分野全体をより容易にナビゲートする鍵となります。

上記で取り上げた各技術は、prefill-decode フレームワークの中に位置づけられます:

  • Batching(バッチ処理)は、ユーザーごとのレイテンシと引き換えに総スループットを向上させます。
  • Prefix caching(プレフィックスキャッシュ)は、プロンプトの冒頭部分が共通している場合に prefill 作業を削減します。
  • Quantization(量子化)はモデル重みを圧縮し、両フェーズを支援します。
  • Speculative decoding(推測デコーディング)は、アイドル状態の計算リソースを活用して、decode フェーズからより多くのトークンを引き出します。
  • Parallelism(並列処理)は、複数の GPU にわたってモデルをスケーリングします。
  • Disaggregation(非集約化)は、prefill と decode を完全に異なるハードウェア上で実行します。

これらの上に重ねられるのが、ビルドか購入かの選択です。初期段階の製品では、市販の API が依然として最適な選択肢ですが、API コストが実質的な経費項目となる場合や、レイテンシ要件がクローズドな API の提供能力を超えた場合、あるいは信頼性要件がベンダーの SLA を上回る場合に、セルフホスティングが意味を持ち始めます。

References:

  • Hugging Face Hub Documentation
  • DeepSeek-V3 Technical Report

-Cursor — Composer: 強化学習を用いた高速な最前線モデルの構築

-Cursor — Composer 2 の紹介

-DistServe: 処理効率を最適化した大規模言語モデル推論におけるプリフィルとデコーディングの非同期化

-PagedAttention を用いた大規模言語モデル推論のための効率的なメモリ管理

-Anthropic — プロンプトキャッシングドキュメンテーション

-NVIDIA TensorRT Documentation

-Fast Inference from Transformers via Speculative Decoding

-Megatron-LM: モデル並列性を用いた数十億パラメータの言語モデルのトレーニング

-NVIDIA Megatron-Core Developer Guide — Tensor Parallel

-Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer

-NVIDIA NVLink and NVLink Switch

-Anthropic Claude API Documentation

原文を表示

Speed without control is a false economy. As AI code-generation accelerates software delivery, the FeatureOps Summit 2026 is here to ensure that when we ship more, we break less.This premier virtual event brings together engineers, architects, and product leaders from companies like Wayfair, Visa, Mintlify, Lloyds, and many others, to explore the infrastructure of fearless delivery.

Key Themes:

AI Safety Nets: Guardrails for the flood of automated code.Edge Resilience: Sub-millisecond evaluation at scale.Continuous Flow: Moving past the “fixed-release” mindset. Register today to master the tools and patterns required for a fail-safe release environment.

Register Today

Every time an LLM generates a response, two operations run in sequence on the same GPU. The first processes the input prompt and emits a single token. The second produces every token after that, one at a time.

From the outside, they look like stages of one process. However, inside the hardware, they have opposite bottlenecks. One is limited by raw compute. The other is limited by how fast data moves through memory. Most of the engineering work that makes production AI systems fast exists because of this split, and the techniques used to handle it are what inference engineering is built around.

Inference engineering is the discipline of running trained AI models in production efficiently. The work spans low-level GPU code, model serving frameworks, and the cloud infrastructure that ties them together. Engineers in this field optimize for some combination of latency, throughput, cost, and quality, with the specific mix depending on the product they support. A few years ago, this work happened almost entirely inside frontier AI labs. Today, it has become a broad specialty that any company running serious AI workloads invests in.

In this article, we will walk through how inference works and why the field’s optimization techniques exist.

*Disclaimer: This post is based on publicly shared *details* from various sources. Please comment if you notice any inaccuracies.*

Three years ago, inference engineering was a specialty practiced almost entirely inside frontier AI labs. The work concerned a small group of engineers building closed models that the rest of the industry consumed through APIs. That picture has shifted dramatically since 2024.

Open models drove the change. Hugging Face, the public registry for AI models, now hosts well over two million open models, roughly 25 times what existed five years ago. Open releases like DeepSeek V3 have closed the capability gap with closed models, giving companies a real choice between paying for a closed API and running an open model themselves.

Self-hosting open models brings three operational advantages over closed APIs:

  • Latency profiles can be tuned for the workload pattern of a specific product, where public APIs optimize for general throughput across many customers.
  • Uptime can reach four nines or better with dedicated deployments, comparing favorably to the two nines typical of public APIs.
  • Costs typically drop by around 80 percent at scale once volume justifies the engineering investment.

The result is that companies across many categories now build serious inference stacks, including AI-native startups, established products integrating AI into existing workflows, and even traditionally cautious sectors like healthcare.

Cursor offers a representative example. The team built Composer 2.0 on top of an open model, applying extensive inference engineering to deliver autocomplete latency below what closed APIs offer.

Understanding why inference engineering looks the way it does starts with understanding what actually happens when a prompt arrives at an LLM. The process splits into two phases with very different physical demands on the GPU.

A token is the atomic unit that an LLM works with. Roughly, it is a word or word fragment. The word “inference” might be one token, while “engineering” might break into two. Latency metrics that mention tokens per second are counted in this unit.

The first phase is called prefill.

The model takes the entire input prompt and runs it through every layer of weights in parallel. Two outputs come out of this burst, namely the first token of the response and the KV cache, which is a structure that stores intermediate values from the attention mechanism so they can be referenced as more tokens get generated.

Prefill is compute-bound. The GPU’s math units are the limiting factor because every input token gets processed simultaneously through every layer of the model, and throwing more raw computational power at this phase makes it faster. The metric that captures prefill performance is time to first token, or TTFT. That brief pause between sending a prompt to ChatGPT and seeing the first tokens appear is prefill in action.

The second phase is the decode phase. The model generates each subsequent token one at a time, running a full forward pass through every layer of weights for every token. Each new token depends on every token before it, which makes the process fundamentally sequential, and the GPU does this thousands of times for a long response.

Decode is memory-bandwidth-bound. Math throughput sits mostly idle while the GPU spends its cycles reading model weights from memory for each forward pass, with the bottleneck living in data movement rather than arithmetic. The metric that captures decode performance is tokens per second, or TPS. The streaming pace of a long response is the decode phase at work.

Since prefill and decode have opposite bottlenecks, a technique that accelerates one phase often has minimal impact on the other. This is why benchmarks report TTFT and TPS as separate numbers, with performance on each phase measured independently.

This split is also the structural insight that organizes the rest of inference engineering. Once prefill and decode are understood as two distinct operations, the field’s techniques sort themselves into three groups: those that accelerate prefill, those that accelerate decode, and those that rebalance the two against each other.

The picture above is somewhat simplified. Real inference engines run batching, scheduling, and other complexity layered on top, and the prefill-decode split holds underneath all of it, which is why it serves as the foundation for the rest of this article.

With the prefill-decode split in mind, the major techniques in inference engineering become much easier to organize. Each one accelerates a specific phase, attacks both for different reasons, or restructures the system around the split itself.

Let us cover each of the six techniques in detail.

Batching is the most basic way to scale a single GPU’s output. The inference engine weaves multiple requests together, token by token, so one GPU can serve many users at once. Throughput rises significantly because the GPU’s compute capacity gets fully utilized instead of sitting idle between requests.

The cost is paid in per-user latency.

A single user on an unbatched system gets the lowest possible response time, while the same user on a heavily batched system waits longer because the GPU is also serving other requests. This trade-off is the primary tension that every other technique navigates around, and different products land at different points on the spectrum, with consumer chat tools favoring lower latency and batch processing pipelines favoring higher throughput.

Prefix caching accelerates prefill by reusing KV cache values across requests. When two prompts share an opening segment, like a long system prompt that is identical across thousands of requests, the engine computes that prefix once and reads from cache thereafter. This is why API providers charge less for cached input tokens.

The catch is that the cache helps from the start of the sequence up to the first non-matching token. If the very first token differs between two prompts, prefix caching delivers zero savings even when the rest of the sequence is identical. Therefore, prompt structure has direct cost and latency implications, and putting variable user input late in the prompt while keeping shared content early gives the cache something to work with.

Quantization helps both phases of inference, though for different reasons.

The basic move is storing model weights in a lower-precision number format. Most modern models train in 16-bit floating-point, and quantization compresses those values down to 8-bit or 4-bit representations, which means smaller weights occupying less memory and requiring less data movement.

Prefill speeds up because lower-precision math operations run faster on the specialized math units inside modern GPUs. Decode speeds up because reduced memory bandwidth pressure means weights are loaded from memory more quickly per forward pass. A typical step down in precision yields roughly 30 to 50 percent better performance, with the exact gain depending on the model and the technique applied.

The cost is potential quality degradation, and different parts of a model tolerate quantization differently.

Linear weights handle it well, activations are somewhat more sensitive, the KV cache is more sensitive still, and attention layers are the most sensitive of all. The reason is that small precision errors in attention layers compound across the sequence of tokens, with each token’s calculation building on the previous ones, so even small errors snowball into meaningful quality loss over a long response.

Most production setups leave attention at full precision for this reason. The bulk of the engineering work in quantization comes down to figuring out which parts to compress and how aggressively.

Speculative decoding accelerates the decode process by exploiting an asymmetry. Generating a token from scratch is expensive, while verifying whether a candidate token matches what the main model would produce is much cheaper. The Sudoku analogy works here, where solving the puzzle takes effort, while checking a finished puzzle is fast.

In speculative decoding, a smaller draft model predicts the next several tokens, and the main model verifies all of them in a single forward pass, accepting the ones that match its own predictions and rejecting the rest. The result is multiple tokens emerging per forward pass through the main model, where one would normally appear.

Speculative decoding improves TPS while leaving TTFT unchanged, because prefill still runs normally. The technique also works best at smaller batch sizes, when the GPU has spare compute capacity to spend on verification. At larger batch sizes, when many requests are being served at once, the GPU is already saturated, and speculation gets dynamically disabled because every cycle is needed for the main workload.

Parallelism techniques let large models run across multiple GPUs when a single one falls short, either because the model is too big to fit in memory or because single-GPU latency is too high. Two main approaches dominate the open model landscape: tensor parallelism and expert parallelism.

Tensor parallelism splits each layer of the model across multiple GPUs. Every GPU holds a fragment of every layer, and the GPUs share the work for each forward pass. This requires high-bandwidth interconnects between the GPUs, like NVIDIA’s NVLink, because results need to be combined after every layer. Tensor parallelism is the default choice for serving very large dense models, where the bandwidth-hungry communication is offset by the speedup from sharing per-layer work.

Expert parallelism applies specifically to mixture-of-experts models, where only a subset of the model’s parameters activate for each token. Different experts get distributed across different GPUs, and tokens get routed to whichever experts they need. The communication overhead is lower than tensor parallelism because experts operate independently, which makes expert parallelism well-suited for multi-node deployments where bandwidth is more limited. Most production deployments combine both, using tensor parallelism within a node and expert parallelism across nodes.

Disaggregation takes the prefill-decode split literally. The idea is to run prefill on one set of GPUs and decode on another, with the KV cache shipped between them over the network. Each set uses hardware tuned to its specific bottleneck, and each set scales independently based on its own traffic pattern.

The flow becomes a three-step process:

  • The prefill engine takes the input sequence and produces both the first token and the KV cache.
  • The cache gets sent over a fast interconnect to the decode engine, and the decode engine handles every subsequent token.
  • In conditional disaggregation, short or already-cached requests skip the handoff entirely and run on the decode engine alone, which performs better against real-world traffic that includes a mix of long and short prompts.

Disaggregation is the most architectural of the techniques covered here. It treats prefill and decode as separate services with separate operational concerns, giving operators independent levers to scale each one. Companies running large-scale inference often consider this a near-mandatory step once their workload mix is well understood.

Putting these techniques into production is a serious task, and combining them adds further complexity. The question every engineering team has to answer is whether to take on this work or whether off-the-shelf APIs are still the right choice. The answer depends on the stage of the product.

Early in building an AI product, off-the-shelf APIs from established providers are almost always the right choice. Meaningful optimization requires real constraints to work against, and early-stage products tend to have fuzzy assumptions about traffic patterns, latency requirements, and unit economics. Engineering effort at this stage is better spent shipping product, since the complexity of running a custom inference stack slows down iteration when iteration speed is what actually matters.

Three signals usually indicate the equation has shifted:

  • API costs have grown into a meaningful expense line.
  • Latency requirements have moved past what closed APIs can deliver.
  • Reliability needs have started to exceed what vendor SLAs offer.

Cursor handled this transition well. Sub-second autocomplete latency was the product itself, and closed APIs aim for general throughput across many customers, while a code completion model demands a specific shape of speed. Self-hosting an open model and applying inference engineering across the stack made the latency target reachable, and the investment paid back because the constraints were real and the workload was well understood.

LLM inference is two operations with opposite physical constraints.

Prefill is compute-bound and runs once per request. Decode is memory-bandwidth-bound and runs once per token. Most of the techniques in inference engineering exist because of this split, and grasping it makes the rest of the field much easier to navigate.

Each technique covered above fits into the prefill-decode framework:

  • Batching trades per-user latency for total throughput.
  • Prefix caching cuts prefill work when prompts share opening segments.
  • Quantization compresses model weights to help both phases.
  • Speculative decoding squeezes more tokens out of decode by exploiting idle compute.
  • Parallelism scales models across multiple GPUs.
  • Disaggregation runs prefill and decode on separate hardware altogether.

Layered on top of all this is the build-versus-buy question. Off-the-shelf APIs remain the right choice for most products in their early stages, while self-hosting starts to make sense when API costs grow into a real expense line, when latency requirements outgrow what closed APIs can deliver, or when reliability needs exceed vendor SLAs.

References:

  • Hugging Face Hub Documentation
  • DeepSeek-V3 Technical Report
  • Cursor — Composer: Building a fast frontier model with RL
  • Cursor — Introducing Composer 2
  • DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large Language Model Serving
  • Efficient Memory Management for Large Language Model Serving with PagedAttention
  • Anthropic — Prompt Caching Documentation
  • NVIDIA TensorRT Documentation
  • Fast Inference from Transformers via Speculative Decoding
  • Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism
  • NVIDIA Megatron-Core Developer Guide — Tensor Parallel
  • Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer
  • NVIDIA NVLink and NVLink Switch
  • Anthropic Claude API Documentation
この記事をシェア

関連記事

Latent Space2026年6月20日 17:06

[AINews] 今日特に大きな出来事はありませんでした

Latent Space は、GLM 5.2 が依然として注目されていると指摘しつつ、AIE WF 2026 の通常チケットが月曜日に完売すると発表しました。同サイト購読者向けに限定割引を提供し、参加者には Warp や Datadog などからのスポンサークレジットも付与されます。

TechCrunch AI★42026年6月20日 01:01

米国がアンソロピックの「Fable 5」発売を禁止、しかし市場は動じず

米国政府は国家安全保障上の懸念から、アマゾンの研究者らがガードレール回避手法を発見したとして、アンソロピックに対し最新モデル「Fable 5」と「Mythos 5」の販売差し止めを命じた。サイバーセキュリティ研究者らはこの措置が危険だとする公開書簡に署名し、同社も他モデルでも同様の抜け道が存在すると指摘している。

GitHub Blog★42026年6月20日 01:00

社内データ分析エージェントの構築方法について

GitHub は、大規模なデータ組織が直面する自己完結型のデータアクセスと洞察提供の課題に対し、AI を活用した信頼性の高い解決策として、社内でデータ分析エージェントを構築したことを発表した。

今日のまとめ

AI日報で今日の重要ニュースをまとめ読み

ニュース一覧に戻る元記事を読む