Skip to content

kv-cache : keep all SWA cells with --swa-full for slot save/restore(フォーク内の確認用) - #1

Draft
butameron wants to merge 1 commit into
masterfrom
swa-full-keep-all
Draft

butameron wants to merge 1 commit into
masterfrom
swa-full-keep-all

Conversation

@butameron

Copy link
Copy Markdown
Owner

Overview

フォーク内の確認用 PR(base=このフォークの master)。上流 ggml-org/llama.cpp へ出す本文はオーナーが自分の言葉で書く(AGENTS.md)。ここは差分と CI の様子を見るためだけ。

--swa-full のとき SWA キャッシュは全量サイズになるが、find_slot は窓の外のセルを再利用候補にし、state_write は窓の外のセルを書かない。そのため、スロットを保存→復元して窓より深く分岐すると全文が再処理される。swa_keep_all を足し、llama_kv_cache_iswa が swa_full のとき SWA 側に立てて両方を止める。アテンションマスクは触らない。

Additional information

  • 回帰テスト test_slot_restore_swa_full_reuses_prefix_beyond_window(tools/server/tests/unit/test_slot_save.py):tinygemma3 の窓を --override-kv gemma3.attention.sliding_window=int:64 で縮め、--swa-full で save → 上書き → restore → 窓より深く分岐した続きで cache_n が live と同じになることを見る。修正前は落ちる(cache_n 0)、修正後は通る。test_slot_save.py 全 18 本通過。
  • tools/server/tests/utils.py に override_kv を追加(--override-kv)。
  • 関連:butameron/saibo#1200・server : preserve context checkpoints across slot save/restore ggml-org/llama.cpp#26004(チェックポイント持ち越し・--swa-full では無効)。

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - コードとテストは Claude Code の補助で作成(コミットの Assisted-by: を参照)。上流への PR 本文・コミットメッセージはオーナーが書き直す。

🤖 Generated with Claude Code

https://claude.ai/code/session_01AytyTnFz3SY5KAonPoXbLU


Generated by Claude Code

With --swa-full the SWA cache is full-size, but find_slot still recycles cells outside the window and state_write skips them, so a restored slot that diverges deeper than the window is fully re-processed. Add swa_keep_all, set by llama_kv_cache_iswa when swa_full is on, to stop both. The attention mask is unchanged.

Add a server test with the SWA window shrunk via --override-kv.

Assisted-by: Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants