]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commit
kv-cache : avoid modifying recurrent cells when setting inputs (#13834)
authorcompilade <redacted>
Tue, 10 Jun 2025 22:20:14 +0000 (18:20 -0400)
committerGitHub <redacted>
Tue, 10 Jun 2025 22:20:14 +0000 (18:20 -0400)
commitdad5c44398b78467943ed0a603ea427fe9f6fc62
treeef3a9d2225e6afcb701ec551e57f1838a5171679
parent55f6b9fa6563f6ae49113f9abdc980c12348cc1c
kv-cache : avoid modifying recurrent cells when setting inputs (#13834)

* kv-cache : avoid modifying recurrent cells when setting inputs

* kv-cache : remove inp_s_mask

It was replaced with equivalent and simpler functionality
with rs_z (the first zeroed state) and the already-existing inp_s_copy.

* kv-cache : fix non-consecutive token pos warning for recurrent models

The problem was apparently caused by how the tail cells were swapped.

* graph : simplify logic for recurrent state copies

* kv-cache : use cell without src refs for rs_z in recurrent cache

* llama-graph : fix recurrent state copy

The `state_copy` shuffle assumes everything is moved at once,
which is not true when `states_extra` is copied back to the cache
before copying the range of states between `head` and `head + n_seqs`.
This is only a problem if any of the cells in [`head`, `head + n_seqs`)
have an `src` in [`head + n_seqs`, `head + n_kv`),
which does happen when `n_ubatch > 1` in the `llama-parallel` example.

Changing the order of the operations avoids the potential overwrite
before use, although when copies are avoided (like with Mamba2),
this will require further changes.

* llama-graph : rename n_state to state_size in build_recurrent_state

This naming should reduce confusion between the state size
and the number of states.
src/llama-graph.cpp
src/llama-graph.h
src/llama-kv-cache-recurrent.cpp
src/llama-kv-cache-recurrent.h
src/llama-kv-cache-unified.cpp
src/llama-model.cpp