Skip to content

server : fix swa checkpoint invalidation logic - #30666

Merged
ServeurpersoCom merged 2 commits into
ggml-org:masterfrom
tdakhran:tarek/fix/swa-checkpoint
Oct 19, 2026
Merged

ServeurpersoCom merged 2 commits into
ggml-org:masterfrom
tdakhran:tarek/fix/swa-checkpoint

Conversation

@tdakhran

Copy link
Copy Markdown
Contributor

Overview

Fix llama-server restoring SWA checkpoints saved from a previous unrelated prompt.

Additional information

Add an A/B test case that fails before the fix and works after.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES, debugging and drafting the test case

@tdakhran
tdakhran requested a review from a team as a code owner October 16, 2026 10:30
@ggerganov ggerganov self-assigned this Oct 16, 2026

@ggerganov ggerganov left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix seems to be correct, although I am wondering if it would be cleaner to just move the checkpoint erasure logic before the checkpoint search block (i.e. before line 3794). This way we don't need the temporary n_prefix local and it's simpler to reason.

Edit: nvm, it has to be after the search block.

for (auto it = slot.prompt.checkpoints.begin(); it != slot.prompt.checkpoints.end();) {
const auto & cur = *it;
if (cur.pos_max > pos_next) {
if (cur.pos_max > pos_next || cur.n_tokens > n_prefix) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you see any problem with simply comparing to n_past instead of introducing the n_prefix?

Suggested change
if (cur.pos_max > pos_next || cur.n_tokens > n_prefix) {
if (cur.pos_max > pos_next || cur.n_tokens > n_past) {

I think it would be correct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing to n_past is stricter and will drop the checkpoint that was just restored, because n_past is rewound to it->n_tokens - 1. Let me add some test cases that catch it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed the test case that fails with comparison to n_past, not sure if it should go into upstream.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it.

@ggerganov ggerganov added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants