
ローカルAIのllama.cppで、モデル切替後の最初の返答が重くなる話題がHacker Newsに上がりました。KV-cache recycling(キャッシュを使い回す仕組み)をうたうTokiRecurが3ポイント、コメント0件で投稿されました[1]。スリープで2秒以内という高速切替が、1ポイント、コメント0件で話題になりました[3]。
原因は、会話の途中まで計算したKVキャッシュが消えることです。KVキャッシュは、推論のprefill(プロンプト全体を一括処理する段階)で計算したattentionのkey/value(計算の途中結果)をメモリに保持し、次のdecode(トークンを1つずつ生成する段階)で再利用する仕組みです[2]。サーバーが起動していれば、同じ会話の先頭を再利用できます[4]。

llama.cppのメモリ管理は、モデルの構造に応じて複数の実装を使い分けます。再帰型や混合型のメモリ、ISWA(一部の窓だけを見るattention)、DeepSeek V4向けの圧縮キャッシュなども扱われます[2]。メモリの種類はモデルのハイパーパラメータと設定から選ばれ、推論ステップに必要な状態を維持し、保存・復元も想定されています[2]。
再起動やクラッシュ、モデルの入れ替えでスロット(サーバー内の会話枠)が消えると、サーバーは会話の先頭からprefillし直します。システムプロンプト、過去のメッセージ、貼り付けたファイル、新しい質問まで、すべてを先頭から処理し直します[4]。ファンが回り、最初のトークンが出るまで長い待ち時間が発生し、長いチャットやコーディングエージェントほど影響が大きいと指摘されています[4]。
llama-serverには、スロットをディスクに保存し、同じモデルで復元する手順があります[4]。スロット保存用のフォルダを指定し、保存と復元をAPIで行うことで、同じ会話の先頭を再利用でき、次のリクエストでprefillを短くできます[4]。モデル切替を速くする試みも出ており、TokiRecurはKV-cache recyclingを掲げ[1]、llmsnapはsleep/wake(スリープと起床)対応で高速なモデル入れ替えをうたっています。
GitHubの議論やチュートリアルでも、KVキャッシュの入れ替え挙動やllama-serverでの再利用が話題になっています[5][6]。ただし、キャッシュの再利用は万能ではありません。RAMに保持するプロンプトキャッシュの設定では、メモリ不足やeviction errors(キャッシュを追い出すエラー)が起きる場合があると解説されており、プロンプトキャッシュの挙動やeviction errorsへの対処が論点になっています[7]。スロット保存・復元も同じモデルを前提としており、切替後の復元がそのまま効くとは限りません[4]。
そこで必要になるのが、切替前後の速度を測る仕組みです。llama-benchは推論性能をベンチマークするツールで、READMEや解説記事があります[8]。モデル切替やキャッシュ設定を変えたときに推論性能の差を確認しやすくなり、切替前後の速度を数値で比較できます[8]。
今回の話題は、モデルを載せ替える速さだけでなく、セッションの「続き」を守ることに中心が移ったようです。ローカルAIの実用では、スリープや保存・復元、キャッシュ設定を組み合わせ、自分のマシンで実測することが近道になりそうです。
引用ソース
- Hacker News Hacker News: TokiRecur – llama.cpp LLM launcher with KV-cache recycling — https://github.com/lhadzic377-netizen/TokiRecur
TokiRecur – llama.cpp LLM launcher with KV-cache recycling
- Web記事 記事全文: Memory Management and KV Cache | ggml-org/llama.cpp | DeepWiki — https://deepwiki.com/ggml-org/llama.cpp/3.6-memory-management-and-kv-cache
This page explains the memory management system in llama.cpp, focusing on key-value (KV) cache mechanisms, recurrent and hybrid memory models, Independent Sliding Window Attention (ISWA), DeepSeek V4 (DSV4) compressed ca
- Hacker News Hacker News: Swapping LLMs in Under Two Seconds: A Sleep Mode for Llama.cpp — https://zaage.it/writing/llama-sleep/
Swapping LLMs in Under Two Seconds: A Sleep Mode for Llama.cpp
- Web記事 記事全文: Why your long llama.cpp chats get slow after a restart, and how to fix … — https://dev.to/ramenai/why-your-long-llamacpp-chats-get-slow-after-a-restart-and-how-to-fix-it-2fc2
If you run models locally with llama.cpp, you have probably seen this. A long chat feels fine while the server is up. Then you restart the server, the machine reboots, the process crashes, or you swap models and come bac
- Web記事 記事全文: KV cache swapping behaviour? · ggml-org llama.cpp – GitHub — https://github.com/ggml-org/llama.cpp/discussions/17283
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your sess
- Web記事 記事全文: Tutorial: KV cache reuse with llama-server · ggml-org llama.cpp … — https://github.com/ggml-org/llama.cpp/discussions/13606
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your sess
- Web記事 Web検索: Understanding –cache-ram in llama.cpp: Prompt Caching, Eviction Errors … — https://jessequinn.info/blog/llama-cpp-cache-ram-prompt-caching
Understanding –cache-ram in llama.cpp: Prompt Caching, Eviction Errors …
- Web記事 Web検索: How to Benchmark Inference Performance Using llama-bench in llama.cpp … — https://instagit.com/ggml-org/llama.cpp/how-to-benchmark-inference-performance-using-llama-bench/
How to Benchmark Inference Performance Using llama-bench in llama.cpp …
※ 本記事はAIにより、Reddit・Hacker News・5ch・Xトレンドの公開投稿・トレンドを軸に、その話題をWeb検索で深掘りして集めた一次情報(記事全文・HNコメント)を併せて自動生成されました。本文中の[n]は末尾の引用ソース番号です。内容の正確性は保証されません。引用先を必ずご確認ください。









RECENT COMMENTS