[GH-ISSUE #1962] [Engine] Share identical KV prefix blocks across concurrent conversations #782

Open
opened 2026-11-04 01:45:48 +07:00 by bsakaguchi · 9 comments
Owner

Originally created by @shoucandanghehe on GitHub (Oct 11, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1962

Area

[Engine]

What do you want to do?

Allow concurrent conversations to reference the same physical KV blocks when they share an identical prefix, instead of storing a separate copy in every batch slot. The goal is vLLM-style prefix-block sharing, especially for multi-agent workloads with long common system prompts, tool definitions, or conversation history.

Why this matters

Reusing prefix computation and sharing prefix storage are different optimizations. Strata can reuse an already-computed prefix, but separate concurrent slots still have their own KV storage. With KV streaming, this duplication consumes host RAM as well as the per-slot device state.

For example, if four agents branch from the same 50K-token prefix, the desired behavior is to store that prefix's KV once and let all four conversations reference it, while allocating their differing suffixes separately. This would reduce duplicate memory use and make more useful concurrency possible on memory-constrained machines.

Requested behavior

  • Share compatible, immutable prefix blocks across concurrent conversations.
  • Keep each branch's new suffix and mutable execution state independent.
  • Release a shared block only when no conversation or retained cache entry still references it; use copy-on-write or an exclusive tail block where a branch needs to diverge.
  • Match the full prefix and relevant model/execution identity, including image inputs where applicable, rather than treating identical text fragments as interchangeable KV.

The primary request is physical KV deduplication in RAM, not a requirement to first implement a complete GPU PagedAttention stack. Sharing QSA KV should also preserve isolation of GDN/PLE, indexer, and checkpoint state.

  • #1614 provides a shared pinned-RAM KV allocation pool and on-demand chunks. Sharing an allocator does not by itself make identical prefixes share physical blocks.
  • #1164 copies a prefix from a parked conversation while preserving the original history. This helps reuse without taking over that conversation, but still copies the KV.
  • #1938 proposes limiting how much prefix each parked conversation retains, rather than deduplicating that prefix across conversations.
  • This discussion in #52 already describes page-level prefix sharing and reference counting in a contributor's own engine.

Would cross-conversation physical prefix sharing be in scope for Strata, possibly as a follow-up to the shared KV pool?

0.2.0-beta source re-check

Reproduction status: unconfirmed static analysis. I reviewed source at f57c0adcb31c00f3f216550c004dac4e713a9f70 (product 0.2.0-beta, engine 0.1.45.3). The core allocation, batch admission, and KV copy paths cited below are unchanged from the v0.2.0-beta tag. I did not run model inference or measure RAM usage for this re-check.

The requested physical prefix sharing is still absent in the inspected paths:

This request remains specifically about deduplicating identical prefix KV in RAM, with independent mutable branch state. It is not satisfied by prefix-computation reuse or the shared-capacity allocator proposed in #1614.

Originally created by @shoucandanghehe on GitHub (Oct 11, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/1962 ### Area [Engine] ## What do you want to do? Allow concurrent conversations to reference the same physical KV blocks when they share an identical prefix, instead of storing a separate copy in every batch slot. The goal is vLLM-style prefix-block sharing, especially for multi-agent workloads with long common system prompts, tool definitions, or conversation history. ### Why this matters Reusing prefix computation and sharing prefix storage are different optimizations. Strata can reuse an already-computed prefix, but separate concurrent slots still have their own KV storage. With KV streaming, this duplication consumes host RAM as well as the per-slot device state. For example, if four agents branch from the same 50K-token prefix, the desired behavior is to store that prefix's KV once and let all four conversations reference it, while allocating their differing suffixes separately. This would reduce duplicate memory use and make more useful concurrency possible on memory-constrained machines. ### Requested behavior - Share compatible, immutable prefix blocks across concurrent conversations. - Keep each branch's new suffix and mutable execution state independent. - Release a shared block only when no conversation or retained cache entry still references it; use copy-on-write or an exclusive tail block where a branch needs to diverge. - Match the full prefix and relevant model/execution identity, including image inputs where applicable, rather than treating identical text fragments as interchangeable KV. The primary request is physical KV deduplication in RAM, not a requirement to first implement a complete GPU PagedAttention stack. Sharing QSA KV should also preserve isolation of GDN/PLE, indexer, and checkpoint state. ### Related work, but a different goal - #1614 provides a shared pinned-RAM KV allocation pool and on-demand chunks. Sharing an allocator does not by itself make identical prefixes share physical blocks. - #1164 copies a prefix from a parked conversation while preserving the original history. This helps reuse without taking over that conversation, but still copies the KV. - #1938 proposes limiting how much prefix each parked conversation retains, rather than deduplicating that prefix across conversations. - [This discussion in #52](https://github.com/Niko1221/Strata/pull/52#issuecomment-5898751157) already describes page-level prefix sharing and reference counting in a contributor's own engine. Would cross-conversation physical prefix sharing be in scope for Strata, possibly as a follow-up to the shared KV pool? ## 0.2.0-beta source re-check **Reproduction status: unconfirmed static analysis.** I reviewed source at `f57c0adcb31c00f3f216550c004dac4e713a9f70` (product 0.2.0-beta, engine 0.1.45.3). The core allocation, batch admission, and KV copy paths cited below are unchanged from the `v0.2.0-beta` tag. I did not run model inference or measure RAM usage for this re-check. The requested physical prefix sharing is still absent in the inspected paths: - [Each batch slot creates a separate session](https://github.com/Niko1221/Strata/blob/f57c0adcb31c00f3f216550c004dac4e713a9f70/src/program/generate.cpp#L5207-L5222), and [each streamed QSA state allocates its own pinned host KV storage](https://github.com/Niko1221/Strata/blob/f57c0adcb31c00f3f216550c004dac4e713a9f70/src/core/layer.cpp#L903-L935). - [Batch admission saves/restores KV into the destination slot](https://github.com/Niko1221/Strata/blob/f57c0adcb31c00f3f216550c004dac4e713a9f70/src/program/generate.cpp#L11073-L11095). The optional direct-copy path also [copies between source and destination pools](https://github.com/Niko1221/Strata/blob/f57c0adcb31c00f3f216550c004dac4e713a9f70/src/core/conversation_snapshot.cpp#L223-L251); it does not make both conversations reference the same immutable prefix blocks. - Borrowing a parked prefix likewise [copies its KV payload into the target state](https://github.com/Niko1221/Strata/blob/f57c0adcb31c00f3f216550c004dac4e713a9f70/src/core/conversation_snapshot.cpp#L266-L284), while preserving the donor. - [The current documentation explicitly says cross-slot copy-on-write KV pages are not built](https://github.com/Niko1221/Strata/blob/f57c0adcb31c00f3f216550c004dac4e713a9f70/docs/RESEARCH_RUNS.md#L38-L39): pinning the prefix removes the re-read, not the copy. This request remains specifically about deduplicating identical prefix KV in RAM, with independent mutable branch state. It is not satisfied by prefix-computation reuse or the shared-capacity allocator proposed in #1614.
Author
Owner

@CC-David-CC commented on GitHub (Oct 11, 2026):

this is closer to what i am working on

<!-- gh-comment-id:6111077792 --> @CC-David-CC commented on GitHub (Oct 11, 2026): this is closer to what i am working on
Author
Owner

@Niko1221 commented on GitHub (Oct 19, 2026):

Thanks for taking the time to report this.

We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected.

To reopen it takes about two minutes:

  1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see.
  2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other].
  3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system.
  4. Comment /reopen. A check runs and either reopens the issue or lists what is still missing.

The rules are in CONTRIBUTING.md.

<!-- gh-comment-id:6270735575 --> @Niko1221 commented on GitHub (Oct 19, 2026): Thanks for taking the time to report this. We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected. To reopen it takes about two minutes: 1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see. 2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other]. 3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system. 4. Comment `/reopen`. A check runs and either reopens the issue or lists what is still missing. The rules are in [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
Author
Owner

@shoucandanghehe commented on GitHub (Oct 20, 2026):

/reopen

Updated the title and feature-request Area, and added a source re-check for 0.2.0-beta with code references. This is explicitly unconfirmed static analysis, not a hardware runtime or RAM benchmark. The requested cross-conversation physical prefix sharing remains absent in the inspected allocation and copy paths.

<!-- gh-comment-id:6281313240 --> @shoucandanghehe commented on GitHub (Oct 20, 2026): /reopen Updated the title and feature-request Area, and added a source re-check for 0.2.0-beta with code references. This is explicitly unconfirmed static analysis, not a hardware runtime or RAM benchmark. The requested cross-conversation physical prefix sharing remains absent in the inspected allocation and copy paths.
Author
Owner

@github-actions[bot] commented on GitHub (Oct 20, 2026):

Reopened, thank you. A maintainer will pick it up from here.

<!-- gh-comment-id:6281315317 --> @github-actions[bot] commented on GitHub (Oct 20, 2026): Reopened, thank you. A maintainer will pick it up from here.
Author
Owner

@CC-David-CC commented on GitHub (Oct 21, 2026):

shoucandanghehe @shoucandanghehe

this is based on strata but i made some design decisions away from main that i am working to rectify
https://github.com/CC-David-CC/Private_Context_COW
i think how you share kv prefix blocks might gain from studying this (or having your agent do so)

<!-- gh-comment-id:6305267196 --> @CC-David-CC commented on GitHub (Oct 21, 2026): [shoucandanghehe](https://github.com/shoucandanghehe) @shoucandanghehe this is based on strata but i made some design decisions away from main that i am working to rectify https://github.com/CC-David-CC/Private_Context_COW i think how you share kv prefix blocks might gain from studying this (or having your agent do so)
Author
Owner

@Niko1221 commented on GitHub (Nov 5, 2026):

Thanks for taking the time to report this.

Strata has changed a lot since this was opened, and 0.2.11 is out now, so many older reports no longer apply. We're closing issues older than a week that have had no new reports in the last week. Closed here does not mean rejected.

To reopen it takes about two minutes:

  1. Re-test on 0.2.11. It may already be fixed. Write down what you see.
  2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other].
  3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system.
  4. Comment /reopen. A check runs and either reopens the issue or lists what is still missing.

The rules are in CONTRIBUTING.md.

<!-- gh-comment-id:6659218854 --> @Niko1221 commented on GitHub (Nov 5, 2026): Thanks for taking the time to report this. Strata has changed a lot since this was opened, and 0.2.11 is out now, so many older reports no longer apply. We're closing issues older than a week that have had no new reports in the last week. Closed here does not mean rejected. To reopen it takes about two minutes: 1. Re-test on 0.2.11. It may already be fixed. Write down what you see. 2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other]. 3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system. 4. Comment `/reopen`. A check runs and either reopens the issue or lists what is still missing. The rules are in [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
Author
Owner

@shoucandanghehe commented on GitHub (Nov 5, 2026):

/reopen

Source re-check on v0.2.11 (c3b3f5035506f3e966f1b4b7b188aeaabae92f1d), also checked against current main 5d37280d: unconfirmed static analysis; no new inference or RAM benchmark.

The inspected paths still allocate host K/V per streamed state (layer.cpp, lines 922–956). Admission still copies the prefix into the destination slot (generate.cpp, lines 14100–14120); direct copy moves the same payload rather than retaining physical blocks (conversation_snapshot.cpp, lines 433–466).

I have a local implementation that shares completed 4,096-cell host K/V chunks between concurrent slots and RAM snapshots, retains references until the last owner releases them, and copies before rewriting a shared chunk. Partial tails, VRAM K/V, GDN/PLE, indexer and draft state stay private. It is opt-in (--kv-share-prefix) and currently depends on the host chunk pool from #1614.

Before preparing an upstream feature PR: is this scope wanted, and should it be a follow-up stacked on #1614 or contributed to that branch first? I will not duplicate the allocator PR or include the separate disk-cache and slot-scheduling experiments. Current-head backend and whole-model validation would be reported separately; older local runs are not evidence for 0.2.11.

<!-- gh-comment-id:6660042575 --> @shoucandanghehe commented on GitHub (Nov 5, 2026): /reopen Source re-check on v0.2.11 (`c3b3f5035506f3e966f1b4b7b188aeaabae92f1d`), also checked against current main `5d37280d`: **unconfirmed static analysis; no new inference or RAM benchmark**. The inspected paths still allocate host K/V per streamed state ([layer.cpp, lines 922–956](https://github.com/Niko1221/Strata/blob/c3b3f5035506f3e966f1b4b7b188aeaabae92f1d/src/core/layer.cpp#L922-L956)). Admission still copies the prefix into the destination slot ([generate.cpp, lines 14100–14120](https://github.com/Niko1221/Strata/blob/c3b3f5035506f3e966f1b4b7b188aeaabae92f1d/src/program/generate.cpp#L14100-L14120)); direct copy moves the same payload rather than retaining physical blocks ([conversation_snapshot.cpp, lines 433–466](https://github.com/Niko1221/Strata/blob/c3b3f5035506f3e966f1b4b7b188aeaabae92f1d/src/core/conversation_snapshot.cpp#L433-L466)). I have a local implementation that shares completed 4,096-cell host K/V chunks between concurrent slots and RAM snapshots, retains references until the last owner releases them, and copies before rewriting a shared chunk. Partial tails, VRAM K/V, GDN/PLE, indexer and draft state stay private. It is opt-in (`--kv-share-prefix`) and currently depends on the host chunk pool from #1614. Before preparing an upstream feature PR: is this scope wanted, and should it be a follow-up stacked on #1614 or contributed to that branch first? I will not duplicate the allocator PR or include the separate disk-cache and slot-scheduling experiments. Current-head backend and whole-model validation would be reported separately; older local runs are not evidence for 0.2.11.
Author
Owner

@github-actions[bot] commented on GitHub (Nov 5, 2026):

Reopened, thank you. A maintainer will pick it up from here.

<!-- gh-comment-id:6660046816 --> @github-actions[bot] commented on GitHub (Nov 5, 2026): Reopened, thank you. A maintainer will pick it up from here.
Author
Owner

@shoucandanghehe commented on GitHub (Nov 6, 2026):

The implementation is now available as a self-contained branch on current main:

upstream/host-kv-prefix-sharing · diff against upstream main

It includes the pinned host pool from #1614, with credit to @noon-at-cgn and Danny, and adds physical prefix sharing between streaming sessions and RAM snapshots. Completed chunks are reference-counted; writes copy shared chunks first. Partial tails, VRAM windows, GDN/PLE, indexer and drafter state stay private.

--kv-pool-tokens and --kv-share-prefix are opt-in. --kv-chunk-tokens selects the allocation/sharing/COW granularity at startup; its default remains 4096.

Validation: full CUDA and HIP builds; 10 native tests on an RTX 4060, including synthetic GPU append/resolve/attention and snapshot/COW checks at 1024, 4096 and 8192 tokens; launch configuration checks; native reservation probes for pipelined MTP and co-prefill.

This replaces my earlier proposal to stack on #1614. Can you confirm that a self-contained upstream PR including both the necessary pool storage and physical prefix sharing is in scope?

<!-- gh-comment-id:6698394250 --> @shoucandanghehe commented on GitHub (Nov 6, 2026): The implementation is now available as a self-contained branch on current `main`: [upstream/host-kv-prefix-sharing](https://github.com/shoucandanghehe/Strata/tree/upstream/host-kv-prefix-sharing) · [diff against upstream main](https://github.com/Niko1221/Strata/compare/main...shoucandanghehe:Strata:upstream/host-kv-prefix-sharing) It includes the pinned host pool from #1614, with credit to @noon-at-cgn and Danny, and adds physical prefix sharing between streaming sessions and RAM snapshots. Completed chunks are reference-counted; writes copy shared chunks first. Partial tails, VRAM windows, GDN/PLE, indexer and drafter state stay private. `--kv-pool-tokens` and `--kv-share-prefix` are opt-in. `--kv-chunk-tokens` selects the allocation/sharing/COW granularity at startup; its default remains 4096. Validation: full CUDA and HIP builds; 10 native tests on an RTX 4060, including synthetic GPU append/resolve/attention and snapshot/COW checks at 1024, 4096 and 8192 tokens; launch configuration checks; native reservation probes for pipelined MTP and co-prefill. This replaces my earlier proposal to stack on #1614. Can you confirm that a self-contained upstream PR including both the necessary pool storage and physical prefix sharing is in scope?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#782
No description provided.