From db8bc40731d2dde3eab96292b463a7008355c1f5 Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Sat, 4 Apr 2026 23:16:26 +0800 Subject: [PATCH] add some warnings if shifting fails --- gpttype_adapter.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gpttype_adapter.cpp b/gpttype_adapter.cpp index 35620c3af..558dc005f 100644 --- a/gpttype_adapter.cpp +++ b/gpttype_adapter.cpp @@ -2030,11 +2030,12 @@ bool DoContextShifting(llama_context * ctx, llama_context * draft_ctx, std::vect int found = ArrFindIndexOf(current_context_tokens,shared); if(found>=0 && found > trimstart) { + bool ok = true; if(!dryrun) { //extract the unwanted tokens out from context and KV int diff = found - trimstart; - llama_memory_seq_rm(llama_get_memory(ctx), 0, trimstart, trimstart + diff); + ok = llama_memory_seq_rm(llama_get_memory(ctx), 0, trimstart, trimstart + diff); llama_memory_seq_add(llama_get_memory(ctx), 0, trimstart + diff, -1, -diff); if(draft_ctx) { @@ -2045,7 +2046,14 @@ bool DoContextShifting(llama_context * ctx, llama_context * draft_ctx, std::vect { current_context_tokens[i - diff] = current_context_tokens[i]; } - printf("\n[Context Shifting: Erased %d tokens at position %d]", diff, trimstart + 1); + if(ok) + { + printf("\n[Context Shifting: Erased %d tokens at position %d]", diff, trimstart + 1); + } + else + { + printf("\n[Warning: Context Shifting FAILED to erase %d tokens at position %d]", diff, trimstart + 1); + } current_context_tokens.resize(current_context_tokens.size() - diff); } return true;