Skip to content

kv-cache : separate recurrent vs non-recurrent impl #12799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
22bda48
kv-cache : serparate recurrent vs non-recurrent impl (wip)
ggerganov Apr 7, 2025
8145799
kv-cache : init -> contructor + add llama_memory_params
ggerganov Apr 15, 2025
49aa8b8
kv-cache : fix callback reference
ggerganov Apr 15, 2025
838b3cc
context : llama_kv_cache -> llama_memory_i
ggerganov Apr 17, 2025
8e4d3ba
context : move memory creation logic to model
ggerganov Apr 17, 2025
7fec081
llama : remove reference of memory during encode
ggerganov Apr 17, 2025
59af92b
kv-cache : hide padding details in the implementation
ggerganov Apr 23, 2025
6413b93
kv-cache : add ubatch_next()
ggerganov Apr 23, 2025
e869515
context : simplify sbatch logic
ggerganov Apr 23, 2025
ae2cd00
kv-cache : hide defrag logic in the implementation
ggerganov Apr 23, 2025
fdb7206
context : hide kv cache details in implementation
ggerganov Apr 23, 2025
13d69a5
build : fix
ggerganov Apr 23, 2025
5ef7559
cont : another fix
ggerganov Apr 23, 2025
6b50ba7
kv-cache : simplify interface (wip)
ggerganov Apr 24, 2025
cb02ac8
kv-cache : use separate KV cell structs for unified/recurrent
ggerganov Apr 24, 2025
f584750
kv-cache : clean-up
ggerganov Apr 24, 2025
458f2a5
model : better llama_model::create_model() signature
ggerganov Apr 24, 2025
92e626b
kv-cache : fix recurrent seq_rm()
ggerganov Apr 25, 2025
43cbf38
kv-cache : replace `struct callbacks` with `llama_model &`
ggerganov Apr 30, 2025
6619832
kv-cache : replace `struct graph_params` with `llama_context &`
ggerganov Apr 30, 2025
95a9f8b
kv-cache : fix offload check
ggerganov Apr 30, 2025
8737e65
context : avoid passing unique_ptr
ggerganov Apr 30, 2025
c9bddfc
kv-cache : avoid using the backends from the llama_context
ggerganov Apr 30, 2025
09195eb
kv-cache : more consistent debug logs [no ci]
ggerganov Apr 30, 2025
58e1d40
kv-cache : do not pass the full llama_context for kv graphs
ggerganov Apr 30, 2025
903e46f
kv-cache : remove comment
ggerganov May 2, 2025
00cde5f
kv-cache : ggml_rope_ext_inplace -> ggml_rope_ext
ggerganov May 2, 2025
7e79a42
kv-cache : fix recurrent multi-user case
ggerganov May 2, 2025
5883c90
memory : remove comments [no ci]
ggerganov May 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/llama-batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ llama_ubatch llama_sbatch::split_seq(size_t n_ubatch) {
return ubatch;
}

void llama_sbatch::from_batch(const llama_batch & batch, size_t n_embd, bool simple_split, bool logits_all) {
llama_sbatch::llama_sbatch(const llama_batch & batch, size_t n_embd, bool simple_split, bool logits_all) {
GGML_ASSERT(batch.n_tokens >= 0);
this->batch = &batch;
this->n_embd = n_embd;
Expand All @@ -203,6 +203,7 @@ void llama_sbatch::from_batch(const llama_batch & batch, size_t n_embd, bool sim
for (size_t i = 0; i < n_tokens; ++i) {
ids[i] = i;
}

if (simple_split) {
seq.resize(1);
llama_sbatch_seq & s = seq[0];
Expand All @@ -212,6 +213,7 @@ void llama_sbatch::from_batch(const llama_batch & batch, size_t n_embd, bool sim
s.length = n_tokens;
return;
}

std::sort(ids.begin(), ids.end(),
[&batch](size_t a, size_t b) {
int32_t n_seq_a = batch.n_seq_id ? batch.n_seq_id[a] : 1;
Expand Down Expand Up @@ -239,6 +241,7 @@ void llama_sbatch::from_batch(const llama_batch & batch, size_t n_embd, bool sim
return n_seq_a > n_seq_b;
}
);

// init seq
llama_sbatch_seq * last_seq = nullptr;

Expand All @@ -262,6 +265,7 @@ void llama_sbatch::from_batch(const llama_batch & batch, size_t n_embd, bool sim
seq.push_back(new_seq);
last_seq = &seq.back();
}

// keep shared prompts first at the end, then sort by length descending.
std::sort(seq.begin(), seq.end(),
[](llama_sbatch_seq & a, llama_sbatch_seq & b) {
Expand Down
3 changes: 2 additions & 1 deletion src/llama-batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ struct llama_sbatch {
// sequence-wise split
llama_ubatch split_seq(size_t n_ubatch);

void from_batch(const llama_batch & batch, size_t n_embd, bool simple_split = false, bool logits_all = false);
llama_sbatch() = default;
llama_sbatch(const llama_batch & batch, size_t n_embd, bool simple_split = false, bool logits_all = false);
};

// temporary allocate memory for the input batch if needed
Expand Down
Loading