Repository navigation
[Engine] size the conversation cache for one snapshot of the configured context - #4338
Closed
xvcezrqpbxtpzblrt wants to merge 1 commit into
Closed
xvcezrqpbxtpzblrt wants to merge 1 commit into
xvcezrqpbxtpzblrt wants to merge 1 commit into
Conversation
xvcezrqpbxtpzblrt
marked this pull request as draft
October 27, 2026 16:57
xvcezrqpbxtpzblrt
marked this pull request as ready for review
October 27, 2026 17:12
xvcezrqpbxtpzblrt
marked this pull request as draft
October 27, 2026 18:46
…ed context (#3998) With --serve and no --conversation-cache-mib the budget was 40% of the free RAM, capped at 8192 MiB. At long contexts one parked snapshot is larger than that, so every park was skipped and the next request read its whole prompt again (measured: 359,283 tokens, 1,105.8 s; the compaction requests in #3998 are the same path). The auto budget now never drops below one snapshot of --max-context (18 KiB per token; the largest measured snapshot was 17.6 KiB) while the RAM above the floor allows it. Shorter contexts keep the 40% rule, and the physical-RAM admission still refuses a snapshot the machine cannot hold. Measured on the same machine (RTX 3080 Ti Laptop 16 GB, 64 GB RAM, IQ3_XXS 512K int8) with an explicit 16 GiB budget and 1 GiB floor: a 359,207-token conversation parked 5.88 GiB in 2.76 s, restored in 0.94 s, and its follow-up after a side request reused 359,254 of 359,272 tokens in 2.3 s. conversation_memory_test: 40 checks (33 before, 7 new).
xvcezrqpbxtpzblrt
force-pushed
the
fix/3998-parking-budget
branch
from
October 28, 2026 09:08
14c455b to
05e9641
Compare
xvcezrqpbxtpzblrt
marked this pull request as ready for review
October 28, 2026 09:13
Contributor
Author
|
Superseded by #4606, which carries this change with the rest of the 0.2.7 branch. Closing so the review has one place. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and result
With
--serveand no--conversation-cache-mib, the conversation-cache budget is 40% of the free RAM, capped at 8192 MiB. At long contexts one parked snapshot is larger than that, so every park is skipped and the next request reads its whole prompt again. The 0.1.50 Harness replays a compaction as a prefix of the conversation (282,474 tokens = 282,077 reused + 397 read in the run below); when the conversation cannot stay parked, that prefix is lost and the whole prompt is read again (the 331K-342K reads of the 0.1.48 log in #3998; that older log also re-rendered the top of the compaction prompt, 6,127 reused of 337,603, which needs #3584 and is not what this PR fixes).Approach
auto_conversation_cache_mib()now takesmax_contextand never returns less than one snapshot of it (18 KiB per context token: the measured snapshots were 5,138,736,824 B / 282,108 tokens = 17.79 KiB and 6,318,446,860 B / 359,207 = 17.18 KiB with int8; q4_0 measured 11.3 KiB) while the RAM above the parking floor allows it. The 40% rule stays for shorter contexts;max_context0 keeps the old rule alone. The physical-RAM admission is unchanged, so a snapshot the machine cannot hold is still refused, and a 4 GiB-free machine still turns the cache off.Validation
Passed:
cmake -S . -B build-local -G Ninja -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=86 -DSTRATA_BUILD_TESTS=ON -DSTRATA_BUILD_CONVERSATION_TESTS=ONandcmake --build build-local --target strata conversation_memory_test -j 8at14c455b5on Windows 11, MSVC 14.44, CUDA 13.4, sm_86.conversation_memory_test: 40 checks passed (33 before, 7 new). New cases: 512K at 9 GiB free -> 6656 MiB, at 20 GiB -> 9216 MiB, at 40 GiB -> 9216 MiB; the reported machine's 12,160 MiB free -> 9216 MiB (the old rule gave 3,840 MiB, the value in [Engine] Compaction re-reads 331K-342K tokens five times (19.5-20.1 min each) because checkpoints match only from token 0 #3998's log); 32K context -> the 40% rule unchanged; 4 GiB free -> cache off as before. Output line:conversation_memory_test: 40 checks passed.14c455b5), RTX 3080 Ti Laptop 16 GB / 64 GB RAM, IQ3_XXS 512K int8,--kv-grow --vram-reserve-mib 1024 --conversation-cache-min-free-mib 1024, no--conversation-cache-mib. Log%TEMP%\kv512-bench-auto-int8-grow.log:conversation cache sized from the free RAM: 9216 MiB for up to 4 parked conversationsparked 359254 tokens in 1971.0 ms(6,318,446,860 B = 5.88 GiB);restored 359254 tokens (live) in 906.4 ms;prompt 359272 tokens = 359254 reused + 18 read in 1776 ms(1.9 s wall).prompt 359283 tokens = 0 reused + 359283 read in 1,105.8 s(%TEMP%\kv512-bench-int8-grow.log)./compactthrough the app's Harness, engine 0.1.50 with the explicit 16,384 MiB budget and 1,024 MiB floor (logC:\Users\123\AppData\Local\Strata\install\strata-swift-iq3_xxs.log, line 29,736): compaction request 282,474 tokens, reused 282,077 (99.86%), read 397, prefill 3,823 ms, summary 5,227 tokens in 137,393 ms. The post-summary turn: 11,810 tokens, 6,127 reused + 5,683 read, 8,485 ms. This shows the prefix reuse; the parked/restore path itself is shown by the 359K run above (park, side request, restore, follow-up).Failed: none.
Note: the commit message quotes the earlier 0.1.50 run with the explicit 16 GiB budget (park 2.76 s, restore 0.94 s, follow-up 2.3 s); the validation above is the built 0.1.51 run at
14c455b5.Not run:
conversation_memory.hppand one call ingenerate.cpp).Metal buildCI job on this head (metal-link), not executed on a Mac.Limits
--kv fp16is about twice int8's K/V and is not covered by the constant; at 512K that snapshot is about 16 GiB, so a 64 GB machine would still refuse it at the RAM gate. A follow-up can pass the KV mode's per-token size (q4_0 12 / int8 18 / fp16 36 KiB) from the caller.--kv int8on this 64 GB machine the snapshot is about 8 GiB and the free RAM beside the default 2560 MiB floor is about 8.2 GiB, so such a conversation still cannot park; that is a RAM limit, not a budget limit.--conversation-cache-min-free-mibmoves that boundary (the runs above used 1024).