[PR #573] glm: a cancelled prompt read keeps its last checkpoint and stops between calls #605

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/573
Author: @rushisan
Created: 10/27/2026
Status: 🔄 Open

Base: main ← Head: glm-cancelled-read-keeps-checkpoint


📝 Commits (1)

  • fa09079 glm: a cancelled prompt read keeps its last checkpoint and stops between calls

📊 Changes

2 files changed (+45 additions, -3 deletions)

View changed files

📝 docs/SETTINGS.md (+1 -0)
📝 src/program/generate.cpp (+44 -3)

📄 Description

Problem

Two things about a prompt read the client cancels, with one conversation (no --parallel):

  1. The cancel is often not seen until the read ends. Since the checkpoints a read is cut into calls at the checkpoint marks. Inside a call the progress callback is asked only between chunks (c + 1 < nc), and between calls nothing asks read_stopped() (only prompt_between, which is the several-conversation path's). A call of one chunk - MAYA_GLM_CKPT_EVERY at or below the chunk size, or the last piece - never sees the cancel, so the read runs to its end for a client that has gone.
  2. When the cancel is seen, everything read is dropped (snap_tokens.clear(); model.reset(); ckpt_drop_past(0)), including the checkpoints this read had just kept. An agent that gave up waiting and sends the same prompt again reads it from token 0, gives up again at the same point, and so on: on our server (2x RTX 3080, ~950 tokens/s of prefill, a 182K-token prompt, a proxy that waits ~180 s for the first token) that loop held the GPUs for 20 minutes without one answer.

Change

  • After a call ends, with one conversation, read_stopped() is asked; a cancel ends the read there.
  • A cancelled read restores the longest checkpoint of this prompt it has reached (ckpt_restore, then snapshot_save) and makes it the snapshot instead of resetting the model. The same prompt again continues from it; a conversation that runs in between sets it aside in a slot as usual. The DSA rows before the checkpoint were written by calls that ended, and ckpt_restore synchronizes the compute stream, so the cancelled call's work in flight cannot land on the restored state.
  • MAYA_GLM_KEEP_CANCELLED=0: dropped as before. A row in docs/SETTINGS.md.

Text prompts only (checkpoints are), one conversation only. If #572 (the snapshot before the generation prompt) is merged too, the new guard reads at < snap_at there instead of at < prompt.size() - 1.

Measured

v1.1.33, 4x RTX 2080 Ti 22 GB (sm_75, CUDA 12.2), 2x Xeon E5-2673 v4, 247 GB RAM, GLM-5.3 · Maya-S24, 131072 context, greedy, thinking off. A ~35.8K-token prompt with a code word near its start; the client closes the stream at 70% of the measured read time, then sends the same prompt again (optionally with another 3.8K-token chat in between) and asks for the code word:

scenario this PR, MAYA_GLM_CKPTS=16 MAYA_GLM_KEEP_CANCELLED=0
cancelled at 52 s of 74 s, sent again 32768 of 35719 cached, 7.1 s, answer correct 0 of 35719, 72.8 s
the same, another chat in between 32768 of 35783 cached (taken back from a slot), 8.2 s, answer correct -
with the default MAYA_GLM_CKPT_EVERY (16384) 16384 of 35719 / 35783, answers correct -

Before this change (v1.1.33 as released) the cancelled read in the first row was not stopped at all - done: 0 tokens in 73 s (cancel) - so it was cached whole; the read itself kept the GPUs for its full length after the client had gone. With the change it stops at the next call boundary and keeps the checkpoint there.

The same scenarios on 2x RTX 3080 (huihui's abliterated GLM-5.3-Flash UD-Q4_K_XL, 1M context, --kv int8, layer split): 32768 of 35719 / 35783 cached, answers correct.

Not measured: Windows / AMD.


🔄 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/573 **Author:** [@rushisan](https://github.com/rushisan) **Created:** 10/27/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `glm-cancelled-read-keeps-checkpoint` --- ### 📝 Commits (1) - [`fa09079`](https://github.com/mw00/project-maya/commit/fa090792062a56fe665fcd3bdbc06079401577cc) glm: a cancelled prompt read keeps its last checkpoint and stops between calls ### 📊 Changes **2 files changed** (+45 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `docs/SETTINGS.md` (+1 -0) 📝 `src/program/generate.cpp` (+44 -3) </details> ### 📄 Description ## Problem Two things about a prompt read the client cancels, with one conversation (no `--parallel`): 1. **The cancel is often not seen until the read ends.** Since the checkpoints a read is cut into calls at the checkpoint marks. Inside a call the progress callback is asked only between chunks (`c + 1 < nc`), and between calls nothing asks `read_stopped()` (only `prompt_between`, which is the several-conversation path's). A call of one chunk - `MAYA_GLM_CKPT_EVERY` at or below the chunk size, or the last piece - never sees the cancel, so the read runs to its end for a client that has gone. 2. **When the cancel is seen, everything read is dropped** (`snap_tokens.clear(); model.reset(); ckpt_drop_past(0)`), including the checkpoints this read had just kept. An agent that gave up waiting and sends the same prompt again reads it from token 0, gives up again at the same point, and so on: on our server (2x RTX 3080, ~950 tokens/s of prefill, a 182K-token prompt, a proxy that waits ~180 s for the first token) that loop held the GPUs for 20 minutes without one answer. ## Change - After a call ends, with one conversation, `read_stopped()` is asked; a cancel ends the read there. - A cancelled read restores the longest checkpoint of this prompt it has reached (`ckpt_restore`, then `snapshot_save`) and makes it the snapshot instead of resetting the model. The same prompt again continues from it; a conversation that runs in between sets it aside in a slot as usual. The DSA rows before the checkpoint were written by calls that ended, and `ckpt_restore` synchronizes the compute stream, so the cancelled call's work in flight cannot land on the restored state. - `MAYA_GLM_KEEP_CANCELLED=0`: dropped as before. A row in `docs/SETTINGS.md`. Text prompts only (checkpoints are), one conversation only. If #572 (the snapshot before the generation prompt) is merged too, the new guard reads `at < snap_at` there instead of `at < prompt.size() - 1`. ## Measured v1.1.33, 4x RTX 2080 Ti 22 GB (sm_75, CUDA 12.2), 2x Xeon E5-2673 v4, 247 GB RAM, GLM-5.3 · Maya-S24, 131072 context, greedy, thinking off. A ~35.8K-token prompt with a code word near its start; the client closes the stream at 70% of the measured read time, then sends the same prompt again (optionally with another 3.8K-token chat in between) and asks for the code word: | scenario | this PR, `MAYA_GLM_CKPTS=16` | `MAYA_GLM_KEEP_CANCELLED=0` | |---|---:|---:| | cancelled at 52 s of 74 s, sent again | **32768 of 35719** cached, 7.1 s, answer correct | 0 of 35719, 72.8 s | | the same, another chat in between | **32768 of 35783** cached (taken back from a slot), 8.2 s, answer correct | - | | with the default `MAYA_GLM_CKPT_EVERY` (16384) | 16384 of 35719 / 35783, answers correct | - | Before this change (v1.1.33 as released) the cancelled read in the first row was not stopped at all - `done: 0 tokens in 73 s (cancel)` - so it was cached whole; the read itself kept the GPUs for its full length after the client had gone. With the change it stops at the next call boundary and keeps the checkpoint there. The same scenarios on 2x RTX 3080 (huihui's abliterated GLM-5.3-Flash UD-Q4_K_XL, 1M context, `--kv int8`, layer split): 32768 of 35719 / 35783 cached, answers correct. Not measured: Windows / AMD. --- <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 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#605
No description provided.