From 064cc596ac44308dc326a17c9e3163c34a6f29d1 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Mon, 12 May 2025 15:12:27 +0300 Subject: [PATCH] context : fix state io for memory-less contexts (#13470) ggml-ci --- src/llama-context.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/llama-context.cpp b/src/llama-context.cpp index a12849f0..0cb6ebc9 100644 --- a/src/llama-context.cpp +++ b/src/llama-context.cpp @@ -1788,10 +1788,13 @@ size_t llama_context::state_read_data(llama_io_read_i & io) { } } - LLAMA_LOG_DEBUG("%s: - reading KV self\n", __func__); - llama_kv_cache * kv_self = static_cast(memory.get()); + if (memory) { + LLAMA_LOG_DEBUG("%s: - reading KV self\n", __func__); - kv_self->state_read(io); + llama_kv_cache * kv_self = static_cast(memory.get()); + + kv_self->state_read(io); + } return io.n_bytes(); } @@ -1799,9 +1802,11 @@ size_t llama_context::state_read_data(llama_io_read_i & io) { size_t llama_context::state_seq_write_data(llama_io_write_i & io, llama_seq_id seq_id) { GGML_UNUSED(seq_id); - llama_kv_cache * kv_self = static_cast(memory.get()); + if (memory) { + llama_kv_cache * kv_self = static_cast(memory.get()); - kv_self->state_write(io, seq_id); + kv_self->state_write(io, seq_id); + } return io.n_bytes(); } @@ -1809,9 +1814,11 @@ size_t llama_context::state_seq_write_data(llama_io_write_i & io, llama_seq_id s size_t llama_context::state_seq_read_data(llama_io_read_i & io, llama_seq_id seq_id) { GGML_UNUSED(seq_id); - llama_kv_cache * kv_self = static_cast(memory.get()); + if (memory) { + llama_kv_cache * kv_self = static_cast(memory.get()); - kv_self->state_read(io, seq_id); + kv_self->state_read(io, seq_id); + } return io.n_bytes(); }