Repository navigation
feat(core): a paged prompt cache, a radix tree over the backend's own KV pages - #625
Conversation
… KV pages prompt_radix.zig keeps prompt reuse for a backend whose attention cache is paged: a request takes its longest match in a radix tree over token pages, shares the pages below its resume point instead of copying them, and resumes the deepest recurrent-state snapshot on that path. Marks follow prompt_cache.zig's rules (the history, shared system blocks, the last whole page); reclaim frees the least valuable leaf no stream holds. prompt_cache.zig gains only the types it shares: `Pages` (the backend's page holders), `Rules.page` and `Rules.tail`, and `Kept`. Their defaults leave every existing store as it was. No backend uses the paged store yet; the Qwen3.5 HIP engine will. Six host-memory tests cover resume, marks, shared cuts, eviction order, refusals and reclaim.
… lengths A backend that keeps prompt states itself (the paged store) needs the lengths prompt_cache.zig plans marks from: the rendered history and the shared system blocks. LaneHost now passes `history_len` and `shared_prefixes` from the request into the lane stream; nothing reads them in a backend that does not keep its own states.
5550b13 to
d6ffe84
Compare
|
Thank you, @BlivionIaG. The paged prompt cache is merged into main (1d8c625) with both your commits as they were, and it ships in 1.0.6. It and #623 both added tests at the end of When the HIP engine first uses it, please gate it as #571 did for the other stores: chat with the cache equals chat without it, through delete, edit and regenerate rewinds. |
|
Your rebase landed a few seconds after we fetched, so we merged the rebased head too (30ed6cf). It changes no files, since it matches what's already in main, and GitHub now shows this as merged. Thanks again. |
… and model checks The HIP branch's engine (ashhart#490) on ashhart#463's runtime and the kernel launches of ashhart#617 and ashhart#621: the lane rounds with MTP drafts, the paged attention cache and the radix prompt cache (ashhart#625), chunked prompts (ashhart#623), CUDA-graph rounds, the memory plan, and tensor parallelism over RCCL (comm/: the library, the rank link, the group). The native server takes it with `zig build native-hip -Dhip-arch=...` and the serve flags it lists (ashhart#624); `tf-qwen35-test` runs the model checks on a GPU. `zig build test` compiles both against stub kernels. The engine reads the policy (`--policy`, TF_POLICY) once and hands the kernels `Launcher.Choices`; a GPU other than the one the kernels were built for is refused with both names. round_shape.zig stays in the family: its only reader is the plan.
…r the backend's own KV pages Thanks @BlivionIaG. # Conflicts: # zig/src/core/lane_host_test.zig
… and model checks The HIP branch's engine (#490) on #463's runtime and the kernel launches of #617 and #621: the lane rounds with MTP drafts, the paged attention cache and the radix prompt cache (#625), chunked prompts (#623), CUDA-graph rounds, the memory plan, and tensor parallelism over RCCL (comm/: the library, the rank link, the group). The native server takes it with `zig build native-hip -Dhip-arch=...` and the serve flags it lists (#624); `tf-qwen35-test` runs the model checks on a GPU. `zig build test` compiles both against stub kernels. The engine reads the policy (`--policy`, TF_POLICY) once and hands the kernels `Launcher.Choices`; a GPU other than the one the kernels were built for is refused with both names. round_shape.zig stays in the family: its only reader is the plan.
… and model checks The HIP branch's engine (#490) on #463's runtime and the kernel launches of #617 and #621: the lane rounds with MTP drafts, the paged attention cache and the radix prompt cache (#625), chunked prompts (#623), CUDA-graph rounds, the memory plan, and tensor parallelism over RCCL (comm/: the library, the rank link, the group). The native server takes it with `zig build native-hip -Dhip-arch=...` and the serve flags it lists (#624); `tf-qwen35-test` runs the model checks on a GPU. `zig build test` compiles both against stub kernels. The engine reads the policy (`--policy`, TF_POLICY) once and hands the kernels `Launcher.Choices`; a GPU other than the one the kernels were built for is refused with both names. round_shape.zig stays in the family: its only reader is the plan.
…r the backend's own KV pages Thanks @BlivionIaG. # Conflicts: # zig/src/core/lane_host_test.zig
… and model checks The HIP branch's engine (ashhart#490) on ashhart#463's runtime and the kernel launches of ashhart#617 and ashhart#621: the lane rounds with MTP drafts, the paged attention cache and the radix prompt cache (ashhart#625), chunked prompts (ashhart#623), CUDA-graph rounds, the memory plan, and tensor parallelism over RCCL (comm/: the library, the rank link, the group). The native server takes it with `zig build native-hip -Dhip-arch=...` and the serve flags it lists (ashhart#624); `tf-qwen35-test` runs the model checks on a GPU. `zig build test` compiles both against stub kernels. The engine reads the policy (`--policy`, TF_POLICY) once and hands the kernels `Launcher.Choices`; a GPU other than the one the kernels were built for is refused with both names. round_shape.zig stays in the family: its only reader is the plan.
… and model checks The HIP branch's engine (ashhart#490) on ashhart#463's runtime and the kernel launches of ashhart#617 and ashhart#621: the lane rounds with MTP drafts, the paged attention cache and the radix prompt cache (ashhart#625), chunked prompts (ashhart#623), CUDA-graph rounds, the memory plan, and tensor parallelism over RCCL (comm/: the library, the rank link, the group). The native server takes it with `zig build native-hip -Dhip-arch=...` and the serve flags it lists (ashhart#624); `tf-qwen35-test` runs the model checks on a GPU. `zig build test` compiles both against stub kernels. The engine reads the policy (`--policy`, TF_POLICY) once and hands the kernels `Launcher.Choices`; a GPU other than the one the kernels were built for is refused with both names. round_shape.zig stays in the family: its only reader is the plan.
What this changes
The prompt-cache slice tracked in #491: a paged prompt cache,
core/prompt_radix.zig, for a backend whose attention cache is paged. No backend uses it yet; the Qwen3.5 HIP engine will. This is the mechanism #505 cites from #490 (hip_prefix.zig,prefix.zig), moved to core onprompt_cache.zig's types.prompt_cache.zig's rules: the history, shared system blocks, and withRules.tailthe last whole page.reclaimfrees the least valuable leaf that no stream holds.history_lenandshared_prefixes.LaneHostpasses them through, because a backend that keeps its own states plans marks from them (second commit,lane_host.zigandlanes/stream.zig).prompt_cache.ziggains only the types the two stores share:Pages(who holds each of the backend's pages),Rules.page,Rules.tailandKept. Their defaults leave every existing store as it was.Receipt
mainat 1184cdb (with feat(lanes): a prompt pass a chunk a round, between the other streams' rounds #623), head d6ffe84. Zig 0.17.0, on macOS (Apple silicon) and Linux 7.1.7.prompt_radix_test.zigruns over host memory. A resumed pass keeps exactly the pages and states it should: resume at the history, shared pages below it, marks, a shared cut outliving its conversation, eviction order, refusals past the limits, a failed copy keeping nothing, and reclaim sparing pages a stream holds. "a lane host hands the backend the request's history and shared prefix lengths with its stream" fails with the passthrough removed (expected 6, found 0). With reclaim's holder check broken, "reclaim frees the pages of the least valuable leaf nobody holds" fails. The existingprompt_cacheandlane_host_reusetests are unchanged and pass.zig build test test-golden -Dcpu=apple_m1: 141/141 steps, 993/995 tests (2 skipped); golden 309/319 equal, 0 unexpected.zig build test: 37/37 steps, 398/398 tests, the same count asmain: Linux CI doesn't runengine_api's tests, so these run on macOS.zig fmt --checkis clean on the changed files.lean_check.py: 542 problems, the same asmain.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Its user, the HIP engine, will be held to "resumed equals fresh" on device.)