Cloudflare、Kimi と GLM の大規模推論を高速化・安全化
本文の状態
日本語全文を表示中
詳細モードで約9分の本文を読めます。
同じ出来事の情報源
この情報源を基点に整理
Cloudflare AI
Cloudflare は Kimi や GLM のような大規模モデルの効率的な推論を実現するため、KV キャッシュの量子化や重圧縮などの最適化技術を Workers AI に導入し、メモリ制約を克服してコストとスループットを改善した。
AI深層分析を開く2026年8月3日 22:21
AI深層分析
キーポイント
大規模モデルへの最適化技術の実装
Cloudflare は Kimi K-series や GLM のような大規模で長文脈の混合専門家モデルを、メモリ制約の中で効率的に運用するために KV キャッシュの量子化と重圧縮を導入した。
KV キャッシュの FP8 量子化による効果
KV キャッシュを 16 ビットから 8 ビット浮動小数点 (FP8) に量子化することで、Kimi K2.6 のコンテキスト容量が約 68 万トークンから 137 万トークンに倍増し、並行リクエスト数も大幅に増加した。
コスト削減とスループット向上の両立
FP8 の採用により、BF16 に比べて約 30% コストを削減しながら、ピーク時のトークン生成速度を約 41% 向上させ、モデル精度への影響は確認されなかった。
SGLang フレームワークとの連携
Cloudflare は SGLang というオープンソース推論サービングフレームワークを実験および本番トラフィックに採用し、パフォーマンス向上のために開発チームと密接に連携してパッチをアップストリームした。
INT4 重圧縮によるメモリ効率と推論速度の向上
GLM 5.2 の重みを INT4 に圧縮することで、チェックポイントサイズが約 40%減少し、GPU メモリに余裕が生まれる。デコードフェーズではデータ転送量が減るため遅延が改善される一方、プレフィルは計算集約型のため速度が低下する。
重要な引用
Quantizing the cache adds a small amount of work per token, since the FP8 attention kernel has to convert values as it reads them.
Because we run prefill and decode as separate pools, we can apply this where it helps most: prefill is compute-bound rather than memory-bound, so there we leave the cache in BF16 and keep its slightly higher throughput.
None of this would matter if it changed the model's answers
The effect is largest at low concurrency, where per-request latency matters most
編集コメントを表示
編集コメント
Cloudflare は大規模モデルの運用におけるメモリ制約という普遍的な課題に対し、KV キャッシュの量子化とアーキテクチャの工夫で明確な解決策を示した。この技術は、コスト増を伴わずに高性能 LLM の実用スケール展開を可能にする重要な指針となる。
Source Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
Workers AI は、Cloudflare のデータセンター内でユーザーに近い GPU 上で、世界中で最も優れたオープンソースモデルの推論を実行しています。その中でも特に能力が高く、かつリソースを多く消費するのが、Moonshot の Kimi K シリーズと Z.ai の GLM です。これらは大規模な長文脈対応の MoE(Mixture of Experts)モデルであり、非常に使い勝手が良い一方で、メモリ制約のため効率的に提供するのは難しいという課題もあります。
以前、Workers AI 上で大規模モデルをどのように提供するか、また推論のプリフェッチとデコードの各フェーズを分離して GPU の性能を最大化する方法について解説しました。今回の記事では、これらのモデルをメモリ内に収めつつ高速性を維持するために追加した 3 つの技術について紹介します。それは KV キャッシュの量子化、モデル重みの圧縮、そしてそれらの最適化により共有ハードウェア上でより多くのリクエストが処理されるようになるため、共有キャッシュを守るための保護機構です。これらの最適化により、モデルの精度を一切損なうことなく、より多くのお客様をより低コストでサポートできるようになりました。
すべての実験と本番トラフィックは、オープンソースの推論サービングフレームワークである SGLang を用いて実行・ベンチマークされています。私たちは市場において SGLang が最高のパフォーマンスを発揮することを確認しており、SGLang チームと緊密に連携してパッチや新機能をアップストリームへ還元し、その成果をオープンソースコミュニティ全体で利用できるようにしています。
KV キャッシュの量子化
モデルがテキストを生成する際、すでに処理したすべてのトークンに対するアテンションキー(K)とバリュー(V)は、KV キャッシュと呼ばれる構造体に格納されます。このキャッシュにより、モデルは新しいトークンを生成するたびに文脈全体を読み直すことなく、長い会話の続きを可能にします。長文コンテキスト対応モデルではこのキャッシュが急速に成長し、GPU メモリを最初に圧迫するのは通常、モデルの重みではなく KV キャッシュの方です。
デフォルトではキャッシュは 16 ビット精度(BF16)で保存されますが、ここでは 8 ビット浮動小数点形式(FP8, e4m3)で保存することでサイズを半分に抑えています。Kimi K2.6 ではこれにより、メモリに保持できるコンテキスト量が約 686,000 トークンから約 137 万トークンへと倍増します。
この恩恵がどこから来るのかを正確に理解しておく必要があります。それは純粋な速度向上ではありません。キャッシュの量子化は、FP8 アテンションカーネルが値を読み込む際に変換処理を行う必要があるため、トークンあたりの計算負荷をわずかに増加させます。実際に変えるのは、同時にメモリ上に保持できるリクエスト数です。以下の測定結果は、分離型 H200 デプロイメントにおける Kimi K2.6 のデコード処理で、アテンションカーネルを直接比較したものです:
単一の並行処理レベルにおいて、BF16 はトークンあたりの処理速度が数%速い傾向にあります。しかし、32 件の同時リクエストでキャッシュ容量がいっぱいになり、33 件目を処理できなくなるのに対し、FP8 は 64 件まで対応可能で、秒間 2,192 トークンのスループットを達成します。これは BF16 のピーク値より約 41% 高く、トークンあたりのコストは約 30% 削減できます。
プリフェッチとデコードを別々のプールで実行しているため、最適な場所でそれぞれに適用可能です。プリフェッチは計算リソースがボトルネックとなる領域であり、メモリ帯域がボトルネックではないため、ここではキャッシュを BF16 のまま維持し、わずかに高いスループットを活かします。
もしこれがモデルの回答内容を変えてしまうのであれば意味がありませんが、確認したところ、評価スイート全体を通じて FP8 と BF16 のキャッシュによる結果に差は見られませんでした。
モデル重みの圧縮
GPU メモリに対する負荷要因は主に 2 つあります。1 つは KV キャッシュ、もう 1 つがモデルの重みです。GLM 5.2 では、精度を一切損なうことなく、8 ビット浮動小数点数から 4 ビット整数(INT4)へ重みを圧縮しています。これによりチェックポイントサイズは 705 GB から 421 GB に約 40% 削減され、8 台の GPU でテンソル並列処理を行う際の 1 GPU あたりのメモリ使用量は約 88 GB から 52 GB に低下します。同じハードウェア上で、KV キャッシュとして約 118 万トークンを格納できる余地が生まれました。
評価スイート全体を通じて、INT4 と FP8 の重みによる結果にも差は見られませんでした。
重みサイズを小さくすると、デコード処理が高速化します。その理由は明確です。トークンを生成するたびに、モデルの重みを GPU メモリからストリーミングで読み出す必要があるため、デコード速度はメモリー帯域幅によって制限されます。転送するデータ量を減らせば、各トークンの到着も早まります。この効果は、1 リクエストあたりのレイテンシが最も重要になる低同時実行時において特に顕著です。
一方、プリフィル(初期処理)の挙動は異なります。これは計算集約型であり、INT4 形式の重みを使用する場合は、モデルが乗算を行う前に一度拡張して展開する必要があり、その追加ステップによりむしろ速度が低下します。具体的には、GLM モデルでは FP8 で秒間 10,160 トークン、INT4 では 8,660 トークンのプリフィル処理速度を記録しています。
KV キャッシュと同様に、この分散型アーキテクチャにより「どちらを選ぶか」という選択が可能になります。つまり、デコードでは INT4 を使い、その恩恵を受ける一方で、プリフィルでは FP8 を採用して同様のメリットを得るのです。あらゆるベンチマークにおいて、このモデルの精度は FP8 モデルと比較して 0.8 ポイント以内の誤差に収まり、品質面での差異は実質的に見分けがつかないレベルです。
共有 KV キャッシュの保護
上記の2 つの手法には共通する効果があります。つまり、1 つの GPU メモリを複数のリクエストで同時に効率的に共有できる点です。これが本技術の核心ですが、同時に数百のリクエストが同じ物理的な KV キャッシュページに対して読み書きを行うことを意味します。
この高速化を実現するメカニズム——ページアテンション、連続バッチ処理、キャッシュ再利用など——はすべて、厳密な管理ロジックに依存しています。私たちが扱うリクエスト量においては、10 億分の 1 のミスですら頻繁に発生しうるリスクとなります。
そこで、KV キャッシュの整合性を検証する仕組みを防御層として実装しました。このアイデアはシンプルです。物理的なキャッシュページには、再割り当てされるたびに値が変化するタグを付与し、サーバー側では各リクエストでどのページとタグを使用するかを記録します。サポート対象のデコード操作がキャッシュからデータを読み出す前に、これらのマッピングを検証します。不一致が発生した場合、影響を受けるリクエストは処理を中止し、誤ったページからのデータを返すことを防ぎます。
この安全チェックを実装するかどうかを決めるのはコストです。私たちは、2 つのプリフィルと 2 つのデコード構成を持つ中規模のプロダクションモデルで測定を行いました。入力トークンは 8,192、出力トークンは 1,000 です。
スループットとレイテンシの両方でコストは 1% を下回っており、95% の信頼区間の上限値もほぼ 1% に留まりました。計算コストを抑えるため、検証処理をアテンションカーネルに統合するのではなく、別のバッチチェックとして実行しました。これにより、GPU スレッドグループ間の競合が発生するのを防ぎました。この機能は各デプロイメント単位で有効化可能で、デフォルトのパスではオーバーヘッドが測定できないほど小さい NOP(何もしない)トラッカーを使用します。そのため、この機能が不要な環境でも追加コストは一切かかりません。
今後の展望
最先端モデルの効率的な提供は、常に移り変わる目標であり、その実現に向けた取り組みは現在も続いています。私たちは FP8 KV キャッシュをより多くの環境に展開し、Blackwell(NVIDIA の GPU アーキテクチャ)上での NVFP4 重みの検証を進め、コストをほぼ無視できるレベルで整合性チェックを常時有効化することを目指しています。これらの最適化により、精度を維持したまま、より多くのお客様を低コストでサポートすることが可能になります。
最高のオープンモデルを GPU に詰め込み、数百万人の開発者に提供するという課題に挑戦したい方は、ぜひ私たちと一緒に働いてください。
原文を表示
Workers AI runs inference for some of the best open models in the world on GPUs in Cloudflare data centers close to your users. Two of the most capable, and most demanding, are Moonshot's Kimi K-series and Z.ai's GLM. They are large, long-context, mixture-of-experts models, and they are wonderful to use. They are also very hard to serve efficiently because of memory constraints.
We've written before about how we serve large models on Workers AI and about separating the prefill and decode phases of inference to get more out of each GPU. This post looks at three techniques we layer on top of that to fit these models into memory and keep them fast: quantizing the KV cache, compressing the model weights, and, because both of those pack more requests onto shared hardware, protecting the cache those requests share. These optimizations enable us to support more customers at lower costs, with no change in model accuracy.
All our experiments and production traffic are running and benchmarked with SGLang, an open-source inference serving framework. We found that SGLang offers the best performance in the market, and we work closely with the SGLang team to upstream patches and new features to make our work available to the open-source community.
Quantizing the KV cache
As a model generates text, it stores the attention keys (K) and values (V) for every token it has already processed in a structure called the KV cache. The cache is what lets the model extend a long conversation without re-reading the entire context on every new token. For a long-context model, it grows quickly, and it is usually the KV cache, not the model's weights, that fills up GPU memory first.
By default, the cache is stored in 16-bit precision (BF16). We store it in 8-bit floating point instead (FP8, e4m3), which halves its size. On Kimi K2.6, that raises the amount of context we can hold in memory from roughly 686,000 tokens to about 1.37 million, twice as much.
It's worth being precise about where the benefit comes from, because it isn't raw speed. Quantizing the cache adds a small amount of work per token, since the FP8 attention kernel has to convert values as it reads them. What it changes is how many requests we can keep resident at once. The following measurements are for Kimi K2.6 decoding on a disaggregated H200 deployment, comparing the attention kernels directly:
At any single concurrency level, BF16 is a few percent faster per token. But BF16 runs out of cache at 32 concurrent requests and can't admit a 33rd, while FP8 keeps going to 64 and reaches 2,192 tokens per second, about 41% higher than BF16's peak, for roughly 30% less cost per token. Because we run prefill and decode as separate pools, we can apply this where it helps most: prefill is compute-bound rather than memory-bound, so there we leave the cache in BF16 and keep its slightly higher throughput.
None of this would matter if it changed the model's answers, so we checked. Across our evaluation suite, FP8 and BF16 caches are indistinguishable:
Compressing the model weights
The KV cache is one demand on GPU memory; the model's weights are the other. For GLM 5.2, we compress the weights from 8-bit floating point down to 4-bit integers (INT4) with no loss in accuracy. The checkpoint shrinks from 705 GB to 421 GB, about 40%, and per-GPU memory across an 8-way tensor-parallel deployment drops from roughly 88 GB to 52 GB, which leaves room for around 1.18 million tokens of KV cache on the same hardware.
Across our evaluation suite, INT4 and FP8 weights are indistinguishable:
Smaller weights make the decode phase faster, and for a clear reason: generating each token means streaming the model's weights out of GPU memory, so decode speed is limited by memory bandwidth. Move less data and every token arrives sooner. The effect is largest at low concurrency, where per-request latency matters most:
Prefill behaves differently. It is compute-bound, and INT4 weights have to be expanded back out before the model can multiply with them, so that extra step makes prefill slower rather than faster, GLM sustains about 10,160 tokens per second of prefill in FP8 versus 8,660 in INT4. As with the KV cache, the disaggregated design turns this into a choice rather than a compromise: we run INT4 for decode, where it wins, and FP8 for prefill, where it wins. Model accuracy stays within 0.8 points of the FP8 model across every benchmark we run, making its quality indistinguishable.
Protecting a shared KV cache
Both techniques above have the same effect: they let many more requests share one GPU's memory at the same time. That efficiency is the whole point, but it also means hundreds of requests are reading and writing pages of the same physical KV cache. The mechanisms that make this fast, paged attention, continuous batching, cache reuse, all rely on getting the bookkeeping exactly right, and at our request volumes, even a one-in-a-billion mistake would show up regularly.
So we built KV cache integrity checking as a layer of defense. The idea is straightforward: every physical cache page gets a tag that changes whenever the page is reallocated, and the server records which pages and tags each request expects to use. Before supported decode operations read from the cache, those mappings are checked. If anything doesn't match, the affected request is aborted rather than allowed to return data from the wrong page.
The question that decides whether a safety check ships is what it costs. We measured it on a mid-sized production model in a two-prefill, two-decode configuration, with 8,192-token inputs and 1,000-token outputs:
The cost is under 1% on both throughput and tail latency, and even the upper bound of the 95% confidence interval stays near 1%. We kept it computationally cheap by running the validation as a separate batch check rather than fusing it into the attention kernel, which would have introduced a race between GPU thread groups. It's enabled per deployment, and the default path uses a no-op tracker with no measurable overhead, so deployments that don't need it pay nothing.
What's next
Serving frontier models efficiently is a moving target, and this is the ongoing work behind it. We're expanding FP8 KV caches across more of the fleet, validating NVFP4 weights on Blackwell (NVIDIA’s GPU architecture), and working toward making integrity checks something we can leave on everywhere at negligible cost. These optimizations will allow us to continue to support more customers at a lower cost and at the same accuracy.
If squeezing the best open models onto GPUs and serving them to millions of developers sounds like your kind of problem, come work with us.
関連記事
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み