From d5f4dec93541354fc1ddac21c65dcff61b4e5030 Mon Sep 17 00:00:00 2001 From: l3utterfly Date: Wed, 31 Jan 2024 10:42:28 +0900 Subject: [PATCH] preserve "prev" length during rollback --- common/sampling.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/sampling.cpp b/common/sampling.cpp index a5f1ccb30..0cbb06666 100644 --- a/common/sampling.cpp +++ b/common/sampling.cpp @@ -335,5 +335,9 @@ void llama_sampling_rollback( rollback_num = ctx_sampling->prev.size(); } + // remove rollback_num elements from the end ctx_sampling->prev.erase(ctx_sampling->prev.end() - rollback_num, ctx_sampling->prev.end()); + + // Insert rollback_num zeros at the beginning to preserve the size of prev + ctx_sampling->prev.insert(ctx_sampling->prev.begin(), rollback_num, 0); }