Skip to content

Commit f709a32

Browse files
committed
cont : handle failures to restore the old state
1 parent 08a3c4a commit f709a32

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tools/llama-bench/llama-bench.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,10 +2144,18 @@ int main(int argc, char ** argv) {
21442144
llama_memory_clear(llama_get_memory(ctx), false);
21452145

21462146
if (t.n_depth > 0) {
2147-
if (t.n_depth == cstate.depth) {
2147+
bool is_cached = t.n_depth == cstate.depth;
2148+
2149+
if (is_cached) {
21482150
// if previously we have computed at this depth, just restore the state
2149-
llama_state_seq_set_data(ctx, cstate.buf.data(), cstate.buf.size(), 0);
2150-
} else {
2151+
const size_t ret = llama_state_seq_set_data(ctx, cstate.buf.data(), cstate.buf.size(), 0);
2152+
if (ret == 0) {
2153+
// if the old state is incompatible with the current context - reprocess from scratch
2154+
is_cached = false;
2155+
}
2156+
}
2157+
2158+
if (!is_cached) {
21512159
if (params.progress) {
21522160
fprintf(stderr, "llama-bench: benchmark %d/%zu: depth run %d/%d\n", params_idx, params_count,
21532161
i + 1, params.reps);

0 commit comments

Comments
 (0)