mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2025-06-29 20:45:04 +00:00
kv-cache : simplify + fix warning for recurrent models (#12756)
ggml-ci
This commit is contained in:
@ -2474,7 +2474,12 @@ int32_t llama_get_kv_cache_token_count(const llama_context * ctx) {
|
||||
}
|
||||
|
||||
int32_t llama_kv_self_n_tokens(const llama_context * ctx) {
|
||||
return llama_kv_cache_n_tokens(ctx->get_kv_self());
|
||||
const auto * kv = ctx->get_kv_self();
|
||||
if (!kv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return kv->get_n_tokens();
|
||||
}
|
||||
|
||||
// deprecated
|
||||
@ -2483,7 +2488,12 @@ int32_t llama_get_kv_cache_used_cells(const llama_context * ctx) {
|
||||
}
|
||||
|
||||
int32_t llama_kv_self_used_cells(const llama_context * ctx) {
|
||||
return llama_kv_cache_used_cells(ctx->get_kv_self());
|
||||
const auto * kv = ctx->get_kv_self();
|
||||
if (!kv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return kv->get_used_cells();
|
||||
}
|
||||
|
||||
// deprecated
|
||||
@ -2492,7 +2502,12 @@ void llama_kv_cache_clear(llama_context * ctx) {
|
||||
}
|
||||
|
||||
void llama_kv_self_clear(llama_context * ctx) {
|
||||
llama_kv_cache_clear(ctx->get_kv_self());
|
||||
auto * kv = ctx->get_kv_self();
|
||||
if (!kv) {
|
||||
return;
|
||||
}
|
||||
|
||||
kv->clear();
|
||||
}
|
||||
|
||||
// deprecated
|
||||
@ -2509,7 +2524,12 @@ bool llama_kv_self_seq_rm(
|
||||
llama_seq_id seq_id,
|
||||
llama_pos p0,
|
||||
llama_pos p1) {
|
||||
return llama_kv_cache_seq_rm(ctx->get_kv_self(), seq_id, p0, p1);
|
||||
auto * kv = ctx->get_kv_self();
|
||||
if (!kv) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return kv->seq_rm(seq_id, p0, p1);
|
||||
}
|
||||
|
||||
// deprecated
|
||||
@ -2528,7 +2548,12 @@ void llama_kv_self_seq_cp(
|
||||
llama_seq_id seq_id_dst,
|
||||
llama_pos p0,
|
||||
llama_pos p1) {
|
||||
return llama_kv_cache_seq_cp(ctx->get_kv_self(), seq_id_src, seq_id_dst, p0, p1);
|
||||
auto * kv = ctx->get_kv_self();
|
||||
if (!kv) {
|
||||
return;
|
||||
}
|
||||
|
||||
return kv->seq_cp(seq_id_src, seq_id_dst, p0, p1);
|
||||
}
|
||||
|
||||
// deprecated
|
||||
@ -2539,7 +2564,12 @@ void llama_kv_cache_seq_keep(
|
||||
}
|
||||
|
||||
void llama_kv_self_seq_keep(llama_context * ctx, llama_seq_id seq_id) {
|
||||
return llama_kv_cache_seq_keep(ctx->get_kv_self(), seq_id);
|
||||
auto * kv = ctx->get_kv_self();
|
||||
if (!kv) {
|
||||
return;
|
||||
}
|
||||
|
||||
return kv->seq_keep(seq_id);
|
||||
}
|
||||
|
||||
// deprecated
|
||||
@ -2558,7 +2588,12 @@ void llama_kv_self_seq_add(
|
||||
llama_pos p0,
|
||||
llama_pos p1,
|
||||
llama_pos delta) {
|
||||
return llama_kv_cache_seq_add(ctx->get_kv_self(), seq_id, p0, p1, delta);
|
||||
auto * kv = ctx->get_kv_self();
|
||||
if (!kv) {
|
||||
return;
|
||||
}
|
||||
|
||||
return kv->seq_add(seq_id, p0, p1, delta);
|
||||
}
|
||||
|
||||
// deprecated
|
||||
@ -2577,7 +2612,12 @@ void llama_kv_self_seq_div(
|
||||
llama_pos p0,
|
||||
llama_pos p1,
|
||||
int d) {
|
||||
return llama_kv_cache_seq_div(ctx->get_kv_self(), seq_id, p0, p1, d);
|
||||
auto * kv = ctx->get_kv_self();
|
||||
if (!kv) {
|
||||
return;
|
||||
}
|
||||
|
||||
return kv->seq_div(seq_id, p0, p1, d);
|
||||
}
|
||||
|
||||
// deprecated
|
||||
@ -2586,7 +2626,12 @@ llama_pos llama_kv_cache_seq_pos_max(llama_context * ctx, llama_seq_id seq_id) {
|
||||
}
|
||||
|
||||
llama_pos llama_kv_self_seq_pos_max(llama_context * ctx, llama_seq_id seq_id) {
|
||||
return llama_kv_cache_seq_pos_max(ctx->get_kv_self(), seq_id);
|
||||
const auto * kv = ctx->get_kv_self();
|
||||
if (!kv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return kv->seq_pos_max(seq_id);
|
||||
}
|
||||
|
||||
// deprecated
|
||||
@ -2595,7 +2640,12 @@ void llama_kv_cache_defrag(llama_context * ctx) {
|
||||
}
|
||||
|
||||
void llama_kv_self_defrag(llama_context * ctx) {
|
||||
llama_kv_cache_defrag(ctx->get_kv_self());
|
||||
auto * kv = ctx->get_kv_self();
|
||||
if (!kv) {
|
||||
return;
|
||||
}
|
||||
|
||||
return kv->defrag();
|
||||
}
|
||||
|
||||
// deprecated
|
||||
@ -2604,7 +2654,12 @@ bool llama_kv_cache_can_shift(const llama_context * ctx) {
|
||||
}
|
||||
|
||||
bool llama_kv_self_can_shift(const llama_context * ctx) {
|
||||
return llama_kv_cache_can_shift(ctx->get_kv_self());
|
||||
const auto * kv = ctx->get_kv_self();
|
||||
if (!kv) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return kv->get_can_shift();
|
||||
}
|
||||
|
||||
// deprecated
|
||||
|
Reference in New Issue
Block a user