v0.34.2-rc2:mlxrunner、投機的デコード中に解放済みKVバッファーを回収v0.34.2-rc2: mlxrunner: Release freed KV buffers during speculative decode
匿名の公開いいねです。記事の保存・お気に入りではなく、Featured、Top 3、重要度、掲載順位には影響しません。仕組みとプライバシーAnonymous public likes are reactions, not saved articles or bookmarks. They do not affect Featured, Top 3, importance, or listing order.How it works and privacy
- Ollama v0.34.2-rc2のmlxrunnerは、投機的デコードで生成数が256トークンの境界を越えるたび、MLXの解放済みバッファーを回収します。
- 長いコンテキストで数GBのメモリーが残る問題を抑え、長時間生成時のメモリー不足を防ぎます。
Ollama v0.34.2-rc2 makes mlxrunner clear MLX's freed buffers when speculative decoding crosses a 256-token boundary, preventing multi-GB buildup and OOM during long generations.
本ページの本文と要約は AI による自動生成です。日本語版と英語版は言語ごとに独立して生成されるため、表現や詳しさが異なる場合があります。正確性は元記事 (github.com) をご確認ください。The body and summaries are AI-generated independently for each language, so wording and detail may differ. Verify accuracy at the original source (github.com).
要約と収集メタデータに基づく AI 解説。元記事全文の転載・翻訳ではありません。AI explainer based on the summaries and collected metadata, not a copy or translation of the full source article.
mlxrunner
Ollama v0.34.2-rc2では、mlxrunnerが投機的デコード中にMLXの解放済みバッファーを回収する条件が変更された。長いコンテキストで数GBのメモリーが残り続け、長時間の生成でメモリー不足に至る問題を抑えるための対応となる。
256トークン境界
デコードループは、生成トークン数が256の倍数になった時点で、MLXが管理する解放済みバッファーのプールを解放していた。これは、KVキャッシュが拡張され、それまで使われていた小さいバッファーを手放す間隔とも一致する。
ただし、従来の判定が動作するのは、トークン数が256の倍数に正確に一致した場合だけだった。投機的デコードでは1回の処理で複数のトークンを出力するため、多くの処理がこの境界を飛び越え、プールが解放されない状態になっていた。
解放済みバッファー
長いコンテキストでKVキャッシュが拡張されるたびに、数GB規模のバッファーが残る場合があった。これらは後続の割り当てでは再利用できず、長時間の生成を続けるとrunnerのメモリー使用量が増え続け、最終的にシステムのメモリーが不足すると説明されている。
投機的デコード
変更後は、1回の処理で生成トークン数が256の倍数をまたいだ場合にも、解放済みバッファーのプールを回収する。1トークンずつ生成する処理では従来から境界上で回収できており、今回の変更によって、複数トークンを出力する投機的デコードでも同様のタイミングを扱えるようになった。
Decode loop
Ollama v0.34.2-rc2 changes how mlxrunner recovers MLX’s freed buffers during speculative decoding. The change matters for long generations because unreleased buffers could accumulate by several gigabytes and eventually cause the system to run out of memory.
The decode loop was designed to release MLX’s pool of freed buffers every 256 generated tokens. This interval matches how often the KV cache grows and drops its previous, smaller buffers. However, the release check previously fired only when the generated token count landed exactly on a multiple of 256.
Speculative decoding
That exact-match check works for rounds that generate one token at a time, because such rounds land on each 256-token boundary. Speculative decoding behaves differently: it emits several tokens in a single round.
As a result, most speculative rounds can step over a multiple of 256 without landing exactly on it. When that happens, the release check does not fire, and MLX’s pool of freed buffers is not cleared at the intended boundary.
The updated behavior releases the pool whenever a speculative decoding round crosses a multiple of 256 generated tokens. This makes the boundary handling equivalent to what already occurred with a single-token round, while accounting for rounds that advance the count by several tokens.
Long context
The missed releases were especially significant during generation with a long context. Each time the KV cache grew and discarded its previous, smaller buffers, several gigabytes of buffers could remain in the pool. According to the release description, no later allocation could reuse those buffers.
Consequently, mlxrunner’s memory footprint could continue climbing throughout a long generation until the system exhausted its available memory. Clearing freed buffers whenever a round crosses the 256-token boundary prevents that multi-gigabyte buildup and addresses the out-of-memory condition during extended speculative generation.
ポコとTECHガイドPoko & TECH Guide
ポコと当サイトのTECHガイドが、記事の要約と収集した情報から読みどころを語るAI生成の対話です。Poko and TECH Dashboard's own TECH Guide discuss the article's highlights in an AI-generated conversation based on its summary and collected source details.
- ポコPokoなんで、256トークンぴったりじゃなく、境界を越えた時に回収するの?Why clear the buffers when crossing a 256-token boundary instead of only at exactly 256?
- TECHガイドTECH Guide投機的デコードは1回で複数トークンを出すため、ぴったりの値を飛び越えがちなんだ。そこで境界を越えた時にも解放済みバッファーを回収するよ。Speculative decoding can emit several tokens per round, so it often skips the exact multiple. The change clears freed buffers whenever a round crosses that boundary.
- ポコPokoじゃあ、長いコンテキストで長く生成する人の、メモリー不足を防ぎやすくする変更なんだね?So this helps people running long generations with long contexts avoid running out of memory?
- TECHガイドTECH Guideそう。再利用されない数GBのバッファーが残って使用量が増え続ける問題を抑え、長時間生成でのメモリー不足を防ぐ狙いだよ。Yes. It targets multi-GB freed buffers that could not be reused and kept increasing memory use, helping prevent out-of-memory failures during long generations.
- ポコPoko境界を飛び越えても回収できるようにして、メモリーの積み上がりを抑えたんだね。Got it—the runner now clears buffers even when a round jumps past the boundary, limiting memory buildup.
- TECHガイドTECH Guideうん。ただし、この変更の対象はOllama v0.34.2-rc2のmlxrunnerで、投機的デコード中に256トークンの倍数をまたぐ場面だよ。Right. The stated scope is mlxrunner in Ollama v0.34.2-rc2, specifically when speculative decoding crosses a multiple of 256 generated tokens.
