diff --git a/src/llama-context.cpp b/src/llama-context.cpp index 872894d66a56..6d198d301829 100644 --- a/src/llama-context.cpp +++ b/src/llama-context.cpp @@ -2578,11 +2578,11 @@ llama_persona_move llama_context::persona_save(llama_seq_id seq_id, llama_person if (!memory) { return llama_persona_move::unsupported; } - synchronize(); // a decode returns before its writes land; the raw copies read the same device memory const llama_persona_move checked = memory->persona_check_save(seq_id, out); if (checked != llama_persona_move::done) { return checked; } + synchronize(); // The validated move reads rows that an earlier decode may still be writing. memory->persona_commit_save(seq_id, out); out.owned = true; // a completed save stamps her blocks with her owner out.owner = who.persona; @@ -2597,12 +2597,12 @@ llama_persona_move llama_context::persona_load(llama_seq_id seq_id, uint32_t str if (!in.belongs_to(who)) { return llama_persona_move::wrong_owner; // refused before anything is written } - synchronize(); llama_persona_slot slot; const llama_persona_move checked = memory->persona_check_load(seq_id, stream, in, slot); if (checked != llama_persona_move::done) { return checked; } + synchronize(); // Finish pending device work before writing into the admitted destination. memory->persona_commit_load(seq_id, slot, in); return llama_persona_move::done; } diff --git a/tests/test-persona-blocks.cpp b/tests/test-persona-blocks.cpp index 16dbbfe63539..5058b857179a 100644 --- a/tests/test-persona-blocks.cpp +++ b/tests/test-persona-blocks.cpp @@ -243,8 +243,10 @@ int main(int argc, char ** argv) { llama_memory_clear(llama_get_memory(f.ctx), true); f.prompt(0, 1); f.prompt(1, 2); + const auto completed_before_refusal = llama_perf_context(f.ctx).n_p_eval; llama_persona_blocks unprepared; require(ctx.persona_save(0, unprepared, A) != llama_persona_move::done, "an unprepared save is refused"); + require(llama_perf_context(f.ctx).n_p_eval == completed_before_refusal, "refusal leaves the pending decode with its owner"); require(f.pos_max(0) == f.n_prompt - 1, "a refused save leaves her in place"); require_move(ctx.persona_save(0, a, A), llama_persona_move::done, "a out (refusal setup)");