[PR #2526] [Engine] Preserve decoded batch-slot conversations before slot reuse #4099

Open
opened 2026-11-07 15:33:12 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2526
Author: @hotschmoe
Created: 10/15/2026
Status: 🔄 Open

Base: main ← Head: batch-slot-cache-preservation-main


📝 Commits (1)

  • 4972d47 Preserve decoded batch-slot conversations before slot reuse

📊 Changes

4 files changed (+363 additions, -55 deletions)

View changed files

📝 include/strata/core/conversation_cache.hpp (+31 -0)
📝 src/core/conversation_cache_test.cpp (+104 -0)
📝 src/program/generate.cpp (+120 -34)
📝 sycl/src/program/generate.cpp (+108 -21)

📄 Description

Problem and result

With --parallel/--batch slots, an admission (or a prompt read that gives way, BYIELD) copies a new conversation over an idle slot while the conversation cache holds only that slot conversation's prompt as it was read before admission. When the user returns to that chat, the engine reads the decoded reply again, or the whole prefix if the cache evicted the older copies meanwhile. Still the case on 0.2.0-beta (measured below: a returning 10,329-token conversation replayed all 10,329 tokens).

With this change an idle text slot is parked into the conversation cache before it is overwritten, so the returning turn reuses everything the engine held: on the same test, 0 tokens replayed for both returning conversations.

none (a correctness fix to existing conversation-cache behaviour; no new flag or default).

Approach

  • park_slot parks an idle text slot's sessions, checkpoints and per-slot draft K/V through the same budget, RAM admission and snapshot path as park_current (renamed park_source), unless the main session or a parked conversation already holds that state (ConversationCache::holds, new).
  • A slot that gives its conversation back to the main session gives its checkpoints with it, so newer versions supersede the older parked copies (#342); with STRATA_SLOT_CKPT_MOVE they move as the one continued from did.
  • Image slots, and MTP without a per-slot batch drafter, are not parked (logged), as before.
  • Files: include/strata/core/conversation_cache.hpp, src/core/conversation_cache_test.cpp (new cases), src/program/generate.cpp (CUDA) and sycl/src/program/generate.cpp (SYCL) with the same logic.

Validation

Setup: 0.2.0-beta main e88ee39d against this branch rebased on it (head 4972d47c). 2x Intel Arc Pro B70 32 GB, kernel 7.1, Compute Runtime 26.22.38646.4, SYCL AOT bmg-g31 built with the repository dev image. Qwen3.8-Flash-Next ISTA GSQ-RCO IQ3_XXS, --layer-split 30, "parallel": 2, --max-context 16384 --vram-reserve-mib 512 --kv int8 --spec 4 (no MTP: a SYCL layer split turns batch MTP off, and MTP slots without a per-slot drafter are not parked), --conversation-cache-mib 32768 --conversation-cache-slots 4.

Test (the same script for both builds): conversations A and B (10,074-token prompts, each with three code words spread through it) decode 256-token replies in the two slots; C and D are then admitted into those slots; A and B return one at a time with their replies kept verbatim and ask for the code words. Expected: the returning turn reuses prompt + reply - 1 = 10,329 tokens.

Passed:

  • This branch: A returned with cache_n 10,329, prompt_n 28, replayed 0; B with cache_n 10,329, prompt_n 28, replayed 0. The engine logged one conversation cache: parked 10329 tokens from slot 0 in 212.5 ms (main logs none). Both replies repeat their three code words.
  • main e88ee39d, same test: A replayed 0 (its slot was not overwritten), B returned with cache_n 0 and replayed all 10,329 tokens (the failure this fixes). Code words correct in both builds.
  • CPU tests of this branch in the oneAPI build image (g++ -std=c++20): conversation_cache_test: 4824 checks passed; conversation_split_failure_test rc=0 (allocation-failure cases preserved at 1, 2 and 3 stages).
  • The SYCL engine of this branch builds (strata, AOT bmg-g31). Per-card health passed after both runs.

Failed: none observed.

Not run: CUDA build and GPU run (src/program/generate.cpp was edited to mirror the SYCL change and reviewed, not compiled: no NVIDIA card here); MTP slots with a per-slot batch drafter (--batch-mtp, refused on a SYCL layer split); image slots (not parked by design); long contexts (on 0.1.x a 199,501-token four-chat RAM-return test on an expert-parallel development stack reused 199,839 held tokens and replayed 0 reply tokens; not re-run on 0.2.0).

Limits

  • Latest text continuations are covered; returning to an arbitrary shorter branch point of a conversation is outside this guarantee.
  • No latency claim: parking costs a snapshot copy into the cache budget at admission time.
  • Independent of #2511.
  • Prepared with AI assistance (Claude Code): the code, the measurements and this text were produced by Claude on the submitter's two Arc Pro B70s, at the submitter's request.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/2526 **Author:** [@hotschmoe](https://github.com/hotschmoe) **Created:** 10/15/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `batch-slot-cache-preservation-main` --- ### 📝 Commits (1) - [`4972d47`](https://github.com/Niko1221/Strata/commit/4972d47c97f65596f159adc11f231120f02223d6) Preserve decoded batch-slot conversations before slot reuse ### 📊 Changes **4 files changed** (+363 additions, -55 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/core/conversation_cache.hpp` (+31 -0) 📝 `src/core/conversation_cache_test.cpp` (+104 -0) 📝 `src/program/generate.cpp` (+120 -34) 📝 `sycl/src/program/generate.cpp` (+108 -21) </details> ### 📄 Description ## Problem and result With `--parallel`/`--batch` slots, an admission (or a prompt read that gives way, BYIELD) copies a new conversation over an idle slot while the conversation cache holds only that slot conversation's prompt as it was read before admission. When the user returns to that chat, the engine reads the decoded reply again, or the whole prefix if the cache evicted the older copies meanwhile. Still the case on 0.2.0-beta (measured below: a returning 10,329-token conversation replayed all 10,329 tokens). With this change an idle text slot is parked into the conversation cache before it is overwritten, so the returning turn reuses everything the engine held: on the same test, 0 tokens replayed for both returning conversations. ## Related discussion none (a correctness fix to existing conversation-cache behaviour; no new flag or default). ## Approach - `park_slot` parks an idle text slot's sessions, checkpoints and per-slot draft K/V through the same budget, RAM admission and snapshot path as `park_current` (renamed `park_source`), unless the main session or a parked conversation already holds that state (`ConversationCache::holds`, new). - A slot that gives its conversation back to the main session gives its checkpoints with it, so newer versions supersede the older parked copies (#342); with `STRATA_SLOT_CKPT_MOVE` they move as the one continued from did. - Image slots, and MTP without a per-slot batch drafter, are not parked (logged), as before. - Files: `include/strata/core/conversation_cache.hpp`, `src/core/conversation_cache_test.cpp` (new cases), `src/program/generate.cpp` (CUDA) and `sycl/src/program/generate.cpp` (SYCL) with the same logic. ## Validation Setup: 0.2.0-beta `main` e88ee39d against this branch rebased on it (head 4972d47c). 2x Intel Arc Pro B70 32 GB, kernel 7.1, Compute Runtime 26.22.38646.4, SYCL AOT `bmg-g31` built with the repository dev image. Qwen3.8-Flash-Next ISTA GSQ-RCO IQ3_XXS, `--layer-split 30`, `"parallel": 2`, `--max-context 16384 --vram-reserve-mib 512 --kv int8 --spec 4` (no MTP: a SYCL layer split turns batch MTP off, and MTP slots without a per-slot drafter are not parked), `--conversation-cache-mib 32768 --conversation-cache-slots 4`. Test (the same script for both builds): conversations A and B (10,074-token prompts, each with three code words spread through it) decode 256-token replies in the two slots; C and D are then admitted into those slots; A and B return one at a time with their replies kept verbatim and ask for the code words. Expected: the returning turn reuses prompt + reply - 1 = 10,329 tokens. **Passed:** - This branch: A returned with `cache_n` 10,329, `prompt_n` 28, replayed 0; B with `cache_n` 10,329, `prompt_n` 28, replayed 0. The engine logged one `conversation cache: parked 10329 tokens from slot 0 in 212.5 ms` (main logs none). Both replies repeat their three code words. - `main` e88ee39d, same test: A replayed 0 (its slot was not overwritten), B returned with `cache_n` 0 and replayed all 10,329 tokens (the failure this fixes). Code words correct in both builds. - CPU tests of this branch in the oneAPI build image (`g++ -std=c++20`): `conversation_cache_test: 4824 checks passed`; `conversation_split_failure_test` rc=0 (allocation-failure cases preserved at 1, 2 and 3 stages). - The SYCL engine of this branch builds (`strata`, AOT bmg-g31). Per-card health passed after both runs. **Failed:** none observed. **Not run:** CUDA build and GPU run (`src/program/generate.cpp` was edited to mirror the SYCL change and reviewed, not compiled: no NVIDIA card here); MTP slots with a per-slot batch drafter (`--batch-mtp`, refused on a SYCL layer split); image slots (not parked by design); long contexts (on 0.1.x a 199,501-token four-chat RAM-return test on an expert-parallel development stack reused 199,839 held tokens and replayed 0 reply tokens; not re-run on 0.2.0). ## Limits - Latest text continuations are covered; returning to an arbitrary shorter branch point of a conversation is outside this guarantee. - No latency claim: parking costs a snapshot copy into the cache budget at admission time. - Independent of #2511. - Prepared with AI assistance (Claude Code): the code, the measurements and this text were produced by Claude on the submitter's two Arc Pro B70s, at the submitter's request. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#4099
No description provided.