Skip to content

server : evict checkpoints within min-step of each other#25472

Merged
aldehir merged 4 commits into
ggml-org:masterfrom
aldehir:server-checkpoint-eviction-min-step
Jul 12, 2026
Merged

server : evict checkpoints within min-step of each other#25472
aldehir merged 4 commits into
ggml-org:masterfrom
aldehir:server-checkpoint-eviction-min-step

Conversation

@aldehir

@aldehir aldehir commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Overview

Continuation of #24176 (review)

When creating a new checkpoint, evict any checkpoints that are within min-step of an earlier one.

Since we create two checkpoints towards the end of the prompt, it is possible that the last checkpoint evicts the penultimate checkpoint. To avoid this, I keep track of the task id in the checkpoint and only evict checkpoints created from prior tasks. Let me know if there is a better approach.

fixes #25023

Requirements

@aldehir aldehir requested review from a team as code owners July 9, 2026 04:37
@github-actions github-actions Bot added the server label Jul 9, 2026
@ggerganov ggerganov self-assigned this Jul 9, 2026
@aldehir

aldehir commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Hmm, turns out the near end checkpoint isn't being created if within min-step, which I don't believe was intended.

I also opened #25420 to address prefill issues.

I can roll these fixes into a single PR if desired.

@ggerganov

Copy link
Copy Markdown
Member

I also opened #25420 to address prefill issues.

I think it's safe to merge #25420.

@ggerganov

Copy link
Copy Markdown
Member

Hmm, turns out the near end checkpoint isn't being created if within min-step, which I don't believe was intended.

Think we just have to allow near_prompt_end and it should be good:

diff --git a/tools/server/server-context.cpp b/tools/server/server-context.cpp
index 17941d9e9..f477d7a3a 100644
--- a/tools/server/server-context.cpp
+++ b/tools/server/server-context.cpp
@@ -3506,7 +3506,10 @@ private:
                     do_checkpoint = do_checkpoint && !has_mtmd;
 
                     // no need to create checkpoints that are too close together, unless it's the last user message
-                    do_checkpoint = do_checkpoint && (slot.prompt.checkpoints.empty() || is_last_user_message || n_tokens_start > slot.prompt.checkpoints.back().n_tokens + params_base.checkpoint_min_step);
+                    do_checkpoint = do_checkpoint && (
+                            slot.prompt.checkpoints.empty() ||
+                            is_last_user_message || near_prompt_end ||
+                            n_tokens_start > slot.prompt.checkpoints.back().n_tokens + params_base.checkpoint_min_step);
                     SLT_DBG(slot, "main/do_checkpoint = %s, pos_min = %d, pos_max = %d\n", do_checkpoint ? "yes" : "no", pos_min, pos_max);
 
                     // note: we create the checkpoint before calling llama_decode(), so the current batch is not

Doing some testing.

Comment thread tools/server/server-context.cpp Outdated
@aldehir aldehir force-pushed the server-checkpoint-eviction-min-step branch from 5add0ff to 33ac581 Compare July 10, 2026 03:59
@ali0une

ali0une commented Jul 10, 2026

Copy link
Copy Markdown

@aldehir did you see my comment with the clean diff?

isn't prevention at checkpoint creation time better than the id_task field + eviction loop in create_checkpoint()?

@ali0une

ali0une commented Jul 10, 2026

Copy link
Copy Markdown

@ggerganov @aldehir thanks for the work on this. I wanted to share some benchmark data that might help decide between the eviction approach and prevention at creation time.

I tested a prevention-based approach on a 29-request agent workload (branching conversations, sleep/wake, MTP). The numbers vs pre-bug baseline:

Metric Pre-bug Prevention
Old checkpoint evictions 157 43 (-72%)
"Looking for better prompt" events 15 5
Catastrophic resets multiple 0

The approach combines the near_prompt_end bypass you suggested with a relaxed floor (checkpoint_min_step / 2) for is_last_user_message instead of a full bypass. This prevents clustered checkpoints at the source, so no id_task field or post-creation eviction loop is needed:

diff --git a/tools/server/server-context.cpp b/tools/server/server-context.cpp
--- a/tools/server/server-context.cpp
+++ b/tools/server/server-context.cpp
@@ -3522,12 +3522,15 @@ private:
                     // do not checkpoint after mtmd chunks
                     do_checkpoint = do_checkpoint && !has_mtmd;

-                    // no need to create checkpoints that are too close together, unless it's the last user message
-                    // apply a relaxed floor for is_last_user_message to prevent pathological clustering (#25023)
+                    // no need to create checkpoints that are too close together, unless it's the last user
+                    // message or we are near the end of the prompt (#25023)
+                    // apply a relaxed floor for is_last_user_message to prevent pathological clustering;
+                    // near_prompt_end fires unconditionally to ensure the critical end-of-prompt checkpoint exists
                     const int32_t checkpoint_floor = slot.prompt.checkpoints.empty()
                         ? 0
                         : slot.prompt.checkpoints.back().n_tokens + params_base.checkpoint_min_step / 2;
                     do_checkpoint = do_checkpoint && (slot.prompt.checkpoints.empty()
+                        || near_prompt_end
                         || (is_last_user_message && n_tokens_start > checkpoint_floor)
                         || n_tokens_start > slot.prompt.checkpoints.back().n_tokens + params_base.checkpoint_min_step);
                     SLT_DBG(slot, "main/do_checkpoint = %s, pos_min = %d, pos_max = %d\n", do_checkpoint ? "yes" : "no", pos_min, pos_max);

Full analysis : post-enhanced-fix-analyse.md
router-post-enhanced-fix.log

@aldehir aldehir merged commit 0c4fa7a into ggml-org:master Jul 12, 2026
23 of 25 checks passed
@aldehir

aldehir commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

@ali0une I'm merging this in now and will continue to look for improvements. To do that, however, I need to find a way to benchmark this.

Regarding your min-step / 2 approach, I don't believe this really addresses the issue of the min-step invariant being violated for all user message derived checkpoints except for the last. On consecutive requests in an ongoing conversation, it would instead collapse the distance to min-step / 2, which is not what we want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Checkpoint erasure during normal conversation flow due to is_last_user_message bypass of checkpoint_min_step

6 participants