From f12295b8a9336962bf02a359beb1be0d322b4be7 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sun, 8 Sep 2024 00:33:33 +0300 Subject: [PATCH] llama : fix empty ring buffer push (#9358) --- common/sampling.cpp | 2 +- src/llama-sampling.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/common/sampling.cpp b/common/sampling.cpp index c81b4d233..7806b77e0 100644 --- a/common/sampling.cpp +++ b/common/sampling.cpp @@ -145,7 +145,7 @@ struct gpt_sampler * gpt_sampler_init(const struct llama_model * model, const st /* .params = */ params, /* .grmr = */ llama_sampler_init_grammar(model, params.grammar.c_str(), "root"), /* .chain = */ llama_sampler_chain_init(lparams), - /* .prev = */ ring_buffer(params.n_prev), + /* .prev = */ ring_buffer(std::max(32, params.n_prev)), /* .cur = */ {}, /* .cur_p = */ {}, }; diff --git a/src/llama-sampling.cpp b/src/llama-sampling.cpp index 61f4cbb92..1661d9a83 100644 --- a/src/llama-sampling.cpp +++ b/src/llama-sampling.cpp @@ -1226,7 +1226,9 @@ static struct llama_sampler_i llama_sampler_penalties_i = { /* .name = */ [](const struct llama_sampler * /*smpl*/) { return "penalties"; }, /* .accept = */ [](struct llama_sampler * smpl, llama_token token) { auto * ctx = (llama_sampler_penalties *) smpl->ctx; - ctx->prev.push_back(token); + if (ctx->prev.size()) { + ctx->prev.push_back(token); + } }, /* .apply = */ [](struct llama_sampler * smpl, llama_token_data_array * cur_p) { auto * ctx = (llama_sampler_penalties *) smpl->ctx;