]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commit
common : fix state save in common_prompt_batch_decode (#23468)
authorDaniel Bevenius <redacted>
Tue, 2 Jun 2026 13:44:15 +0000 (15:44 +0200)
committerGitHub <redacted>
Tue, 2 Jun 2026 13:44:15 +0000 (15:44 +0200)
commit0b7154066e8544ed88d92ae2132cc1e055cf6304
tree1020a771795f406b8891d18ee607b4da3783fa7f
parent60130d18f9ac7f42cb4d7f6060b088a45d8f242e
common : fix state save in common_prompt_batch_decode (#23468)

* common : fix state save in common_prompt_batch_decode

This commit addresses a bug in common_prompt_batch_decode that affects
the session state store/restore in completion.cpp and
save-load-state.cpp.

The motivation for this is that currently the code is saving n-1 tokens
in both the session_tokens and in the KV cache. Then when loading the
session tokens, and if the prompt matches, it would replay the last
saved token (n-1) into the next position, effectively replaying the
same token in the wrong position.

The fix is to store all n tokens in session_tokens, while the memory
state only reflects n-1 processed tokens as the saving happens before
the last token is decoded in common_prompt_batch_decode.

I ran both completion.cpp and save-load-state.cpp with a transformer, a
recurrent, and a hybrid model.

Resolves: https://github.com/ggml-org/llama.cpp/issues/23400

Co-authored-by: fairydreaming <redacted>
common/common.cpp
common/common.h
tests/test-save-load-state.cpp
tools/completion/completion.cpp