Skip to content

Commit 33134bd

Browse files
ggerganovMinh141120
authored andcommitted
memory : correctly handle failure in apply() (ggml-org#14438)
ggml-ci
1 parent 7240127 commit 33134bd

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

src/llama-kv-cache-unified-iswa.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ bool llama_kv_cache_unified_iswa_context::next() {
246246
}
247247

248248
bool llama_kv_cache_unified_iswa_context::apply() {
249-
assert(status == LLAMA_MEMORY_STATUS_SUCCESS);
249+
assert(!llama_memory_status_is_fail(status));
250250

251251
bool res = true;
252252

src/llama-kv-cache-unified.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,7 @@ bool llama_kv_cache_unified_context::next() {
17851785
}
17861786

17871787
bool llama_kv_cache_unified_context::apply() {
1788-
assert(status == LLAMA_MEMORY_STATUS_SUCCESS);
1788+
assert(!llama_memory_status_is_fail(status));
17891789

17901790
// no ubatches -> this is a KV cache update
17911791
if (ubatches.empty()) {

src/llama-memory-hybrid.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ bool llama_memory_hybrid_context::next() {
218218
}
219219

220220
bool llama_memory_hybrid_context::apply() {
221-
assert(status == LLAMA_MEMORY_STATUS_SUCCESS);
221+
assert(!llama_memory_status_is_fail(status));
222222

223223
bool res = true;
224224

src/llama-memory-recurrent.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,15 @@ bool llama_memory_recurrent_context::next() {
10711071
}
10721072

10731073
bool llama_memory_recurrent_context::apply() {
1074-
assert(status == LLAMA_MEMORY_STATUS_SUCCESS);
1074+
assert(!llama_memory_status_is_fail(status));
1075+
1076+
// no ubatches -> this is an update
1077+
if (ubatches.empty()) {
1078+
// recurrent cache never performs updates
1079+
assert(status == LLAMA_MEMORY_STATUS_NO_UPDATE);
1080+
1081+
return true;
1082+
}
10751083

10761084
mem->find_slot(ubatches[i_next]);
10771085

src/llama-memory.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ enum llama_memory_status {
3232
// useful for implementing hybrid memory types (e.g. iSWA)
3333
llama_memory_status llama_memory_status_combine(llama_memory_status s0, llama_memory_status s1);
3434

35+
// helper function for checking if a memory status indicates a failure
36+
bool llama_memory_status_is_fail(llama_memory_status status);
37+
3538
// the interface for managing the memory context during batch processing
3639
// this interface is implemented per memory type. see:
3740
// - llama_kv_cache_unified_context

0 commit comments

Comments
 (0)