mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2077] [CLOSED] serve: --prompt-cache-file <path>, the long prompt prefix saved to disk and restored across restarts (opt-in) #3846
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3846
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2077
Author: @imanu86
Created: 10/12/2026
Status: ❌ Closed
Base:
main← Head:pr/prefix-disk📝 Commits (1)
25e12d7serve: --prompt-cache-file : the long prompt prefix saved to disk and restored across restarts (opt-in)📊 Changes
7 files changed (+1536 additions, -15 deletions)
View changed files
📝
CMakeLists.txt(+16 -1)📝
include/strata/core/mtp.hpp(+7 -1)➕
include/strata/core/prefix_cache_file.hpp(+64 -0)📝
src/core/mtp.cpp(+3 -2)➕
src/core/prefix_cache_file.cpp(+599 -0)➕
src/core/prefix_cache_file_test.cpp(+587 -0)📝
src/program/generate.cpp(+260 -11)📄 Description
Title
Issue: none (an opt-in feature: the prompt prefix survives a restart).
Summary
--prompt-cache-file <path>(opt-in) writes the root checkpoint of the shared prompt prefix to a file and reads itback at the next start, so the first turn after a restart resumes from the saved prefix instead of reading it again.
Format v2 holds one image per
--layer-splitblock (so it works with two cards) and the MTP drafter's root cells.Without the option nothing changes.
Why
The in-RAM prompt cache (
--prompt-cache-tail/--prompt-cache-every) dies with the engine. An agent session(Claude Code through a local gateway here) starts with a 40-130K prefix that is the same across restarts; every
restart of the server re-read it. Measured on this box the first 40K prompt after a restart went from ~42 s to
16-20 s with the file.
What changed
src/core/prefix_cache_file.cpp,include/strata/core/prefix_cache_file.hpp(new, librarystrata_prefix_cache):the file format (header with the engine's identity, one image per block, the drafter's root), write and read,
BCrypt SHA-256 on Windows / the C++ fallback elsewhere.
src/program/generate.cpp: the option; the save after the root checkpoint is taken, the restore at start-upbefore the first request; host memory checked with
available_host_bytes()before the restore; the file'sidentity covers the executable, the arguments and the
STRATA_*/CUDA_*environment, so a file written byanother configuration is replaced, never misread.
src/core/mtp.cpp,include/strata/core/mtp.hpp: the drafter usesfirst_needed()so every cell of the saved rootis computed, not only the ones the current window asks for.
src/core/prefix_cache_file_test.cpp: the format, round trip and identity checks.CMakeLists.txt: the library and the test.Relation to open work
#1937 (parked conversations on the disk,
--conversation-disk-dir) and #1810 (conversation checkpoints with diskrestore) persist conversations of the conversation cache; this persists the shared prompt prefix root (the
--prompt-cachecheckpoint every conversation of a session starts from, including the drafter's state) and isindependent of the conversation cache. They can coexist; none of them is merged at the time of writing.
Measurements
RTX 2080 Ti 22 GB + RTX 3060 12 GB, Windows 11,
--layer-split 16 --pipeline-windows 2, Qwen3.8-Flash-Next IQ3_XXS.Reading a 40K-token first prompt takes ~42 s on this box; with the file the first turn after a restart resumes from
the saved root instead (one image per block read from an NVMe). Decode and later turns are unchanged; the output tokens
are the same with and without the file (the same checkpoint, read from RAM or from the file). The save/restore path has
run in this fork's daily build since 0.1.40 with 40-130K prefixes. On v0.1.43 the branch was built and started twice
with the option (
prefix disk cache: enabled, identity computed in 17-23 ms), same answers.Risks / limits
Opt-in. The file is rewritten when the identity changes (a new engine build, a changed option): one re-read, as
without the option. A file of a different format version is ignored and replaced.
Part of a series from a public patch registry (
stack/in the fork imanu86/Strata-2080Ti).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.