From: Georgi Gerganov Date: Sat, 7 Sep 2024 21:33:33 +0000 (+0300) Subject: llama : fix empty ring buffer push (#9358) X-Git-Tag: upstream/0.0.4488~801 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=f12295b8a9336962bf02a359beb1be0d322b4be7;p=pkg%2Fggml%2Fsources%2Fllama.cpp llama : fix empty ring buffer push (#9358) --- diff --git a/common/sampling.cpp b/common/sampling.cpp index c81b4d23..7806b77e 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 61f4cbb9..1661d9a8 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;