[PR #126] [CLOSED] Keep and share cached conversation state #355

Closed
opened 2026-10-29 21:24:35 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/126
Author: @ksanislo
Created: 10/12/2026
Status: ❌ Closed

Base: main ← Head: pr-keep-context


📝 Commits (10+)

  • 26db976 multi bench: every sequence against its own run alone
  • 4c45af1 Slots load whatever split wrote them
  • dad8783 multi: a paused request's snapshot checks its own pictures, not the last GEN's
  • b8f3c7c serve: per-request progress records; a request's own DONE via the engine's thread-local
  • 5e2497a Monitor: several answers at once show each one's phase and count
  • e01115a Monitor: a Conversations card for several at once; the live rate comes down when output stops
  • 8112fa4 Monitor: the hero's decode, prefill and context are the totals now
  • dd3a658 Monitor: the Conversations card keeps the last ones that ended
  • 70fb159 multi: the prompt being read has its own cancel flag; a failure resets only the failed requests' contexts
  • b42362a Prompt path: a cancelled prompt keeps what it read

📊 Changes

16 files changed (+2184 additions, -398 deletions)

View changed files

📝 docs/SETTINGS.md (+5 -2)
📝 include/strata/core/glm_model.hpp (+51 -0)
📝 include/strata/hip_compat/cuda_runtime.h (+1 -0)
📝 serve/server.py (+243 -84)
📝 serve/telemetry.py (+1 -1)
📝 serve/test_fair.py (+2 -2)
📝 serve/test_server.py (+116 -12)
📝 serve/web/app.css (+25 -1)
📝 serve/web/app.js (+119 -20)
📝 serve/web/index.html (+7 -1)
📝 src/core/glm_fast_path.cu (+148 -63)
📝 src/core/glm_fast_state.hpp (+5 -0)
📝 src/core/glm_model.cu (+60 -7)
📝 src/core/glm_multi.cu (+657 -6)
📝 src/core/glm_prefill.cu (+228 -87)
📝 src/program/generate.cpp (+516 -112)

📄 Description

Follows PR #125. This branch is built on PR #125, so its first ten commits are identical; this PR's own changes are the last five (from "Slots load whatever split wrote them" on). Please review and merge PR #125 first - this PR then shrinks to those five commits.

A conversation's state was lost more often than it had to be: a cancelled prompt threw away what it read and the
conversation it had restored; a cancelled or dropped answer left a kept state that no next prompt continued (it held
the reply's opening token); a restart onto a different layer split dropped every kept conversation; and conversations
that share a long start (an agent's sessions) each read it again. In five commits:

  1. Slots load whatever split wrote them - each layer's state goes to the part that runs it now (the split follows
    the free VRAM at start).
  2. A cancelled prompt keeps what it read - the pipelined prompt path stops at the first part, every part ends at
    one chunk boundary, and that state becomes the conversation's snapshot.
  3. Prefix checkpoints - the server marks the system part's end (cp=<n>); the engine keeps a shared slot there.
  4. The state is kept before the reply's opening - the server sends gt=<n>, the generation prompt's tokens; the
    next request continues the conversation whether the answer was kept, dropped or cancelled.
  5. Divergence checkpoints - a shared slot where a prompt parts from a kept conversation (an agent's sessions share
    their instructions before a per-session part), and a log line naming the closest kept prefix when nothing is reused.

Measured (Maya-S, 4x T4): a 38K-token prompt cancelled after 10 s kept 12288 tokens, the retry read only the rest;
a 5.5K-token system prompt with another task: 1.3 s instead of 15.2 s (1.2-1.5 s instead of ~17 s beside a decoding
conversation); an answer cancelled after 955 tokens - the next turn took back 27071 tokens and read 44; a conversation
kept under the split [0,11)[11,21)[21,33)[33,45) came back under [0,13)[13,24)[24,35)[35,45) (6022 tokens, 0.2 s).
Seen live with OpenCode: sessions share their first 7239 tokens; a rewritten history diverged at token 119185 of 132056.
Tests: serve PrefixCheckpoint (cp, gt, detection, reaching the engine).


🔄 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/mw00/project-maya/pull/126 **Author:** [@ksanislo](https://github.com/ksanislo) **Created:** 10/12/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr-keep-context` --- ### 📝 Commits (10+) - [`26db976`](https://github.com/mw00/project-maya/commit/26db97674261566107b4ccd6d08953d4953ebeb5) multi bench: every sequence against its own run alone - [`4c45af1`](https://github.com/mw00/project-maya/commit/4c45af12dd47fc0a5c4dd4b0cdcd32c974521154) Slots load whatever split wrote them - [`dad8783`](https://github.com/mw00/project-maya/commit/dad8783c8a187a2e195b399b4bd76070a39998a6) multi: a paused request's snapshot checks its own pictures, not the last GEN's - [`b8f3c7c`](https://github.com/mw00/project-maya/commit/b8f3c7c6aa908dd75d3a121e211c58ec57441d2b) serve: per-request progress records; a request's own DONE via the engine's thread-local - [`5e2497a`](https://github.com/mw00/project-maya/commit/5e2497a797d619884e08f6d0f2062df839555b5f) Monitor: several answers at once show each one's phase and count - [`e01115a`](https://github.com/mw00/project-maya/commit/e01115a65989dec417386bbf6207d55db2d38dbe) Monitor: a Conversations card for several at once; the live rate comes down when output stops - [`8112fa4`](https://github.com/mw00/project-maya/commit/8112fa47ded43cf43c36bb66a64d7481c9f534d0) Monitor: the hero's decode, prefill and context are the totals now - [`dd3a658`](https://github.com/mw00/project-maya/commit/dd3a658ff267fd31d60e9635f172fa52283a0437) Monitor: the Conversations card keeps the last ones that ended - [`70fb159`](https://github.com/mw00/project-maya/commit/70fb15983999004290f5fd257e2b5ff8abf28925) multi: the prompt being read has its own cancel flag; a failure resets only the failed requests' contexts - [`b42362a`](https://github.com/mw00/project-maya/commit/b42362a3196667e2b907e86c3c4a7c3cf0694904) Prompt path: a cancelled prompt keeps what it read ### 📊 Changes **16 files changed** (+2184 additions, -398 deletions) <details> <summary>View changed files</summary> 📝 `docs/SETTINGS.md` (+5 -2) 📝 `include/strata/core/glm_model.hpp` (+51 -0) 📝 `include/strata/hip_compat/cuda_runtime.h` (+1 -0) 📝 `serve/server.py` (+243 -84) 📝 `serve/telemetry.py` (+1 -1) 📝 `serve/test_fair.py` (+2 -2) 📝 `serve/test_server.py` (+116 -12) 📝 `serve/web/app.css` (+25 -1) 📝 `serve/web/app.js` (+119 -20) 📝 `serve/web/index.html` (+7 -1) 📝 `src/core/glm_fast_path.cu` (+148 -63) 📝 `src/core/glm_fast_state.hpp` (+5 -0) 📝 `src/core/glm_model.cu` (+60 -7) 📝 `src/core/glm_multi.cu` (+657 -6) 📝 `src/core/glm_prefill.cu` (+228 -87) 📝 `src/program/generate.cpp` (+516 -112) </details> ### 📄 Description > **Follows PR #125.** This branch is built on PR #125, so its first ten commits are identical; this PR's own changes are the last five (from "Slots load whatever split wrote them" on). Please review and merge PR #125 first - this PR then shrinks to those five commits. A conversation's state was lost more often than it had to be: a cancelled prompt threw away what it read and the conversation it had restored; a cancelled or dropped answer left a kept state that no next prompt continued (it held the reply's opening token); a restart onto a different layer split dropped every kept conversation; and conversations that share a long start (an agent's sessions) each read it again. In five commits: 1. **Slots load whatever split wrote them** - each layer's state goes to the part that runs it now (the split follows the free VRAM at start). 2. **A cancelled prompt keeps what it read** - the pipelined prompt path stops at the first part, every part ends at one chunk boundary, and that state becomes the conversation's snapshot. 3. **Prefix checkpoints** - the server marks the system part's end (`cp=<n>`); the engine keeps a shared slot there. 4. **The state is kept before the reply's opening** - the server sends `gt=<n>`, the generation prompt's tokens; the next request continues the conversation whether the answer was kept, dropped or cancelled. 5. **Divergence checkpoints** - a shared slot where a prompt parts from a kept conversation (an agent's sessions share their instructions before a per-session part), and a log line naming the closest kept prefix when nothing is reused. **Measured** (Maya-S, 4x T4): a 38K-token prompt cancelled after 10 s kept 12288 tokens, the retry read only the rest; a 5.5K-token system prompt with another task: 1.3 s instead of 15.2 s (1.2-1.5 s instead of ~17 s beside a decoding conversation); an answer cancelled after 955 tokens - the next turn took back 27071 tokens and read 44; a conversation kept under the split [0,11)[11,21)[21,33)[33,45) came back under [0,13)[13,24)[24,35)[35,45) (6022 tokens, 0.2 s). Seen live with OpenCode: sessions share their first 7239 tokens; a rewritten history diverged at token 119185 of 132056. Tests: serve `PrefixCheckpoint` (cp, gt, detection, reaching the engine). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:24:35 +07:00
Sign in to join this conversation.
No labels
pull-request
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
mw00/project-maya#355
No description provided.