Skip to content

Commit f12295b

Browse files
authored
llama : fix empty ring buffer push (#9358)
1 parent faf69d4 commit f12295b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

common/sampling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ struct gpt_sampler * gpt_sampler_init(const struct llama_model * model, const st
145145
/* .params = */ params,
146146
/* .grmr = */ llama_sampler_init_grammar(model, params.grammar.c_str(), "root"),
147147
/* .chain = */ llama_sampler_chain_init(lparams),
148-
/* .prev = */ ring_buffer<llama_token>(params.n_prev),
148+
/* .prev = */ ring_buffer<llama_token>(std::max(32, params.n_prev)),
149149
/* .cur = */ {},
150150
/* .cur_p = */ {},
151151
};

src/llama-sampling.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,9 @@ static struct llama_sampler_i llama_sampler_penalties_i = {
12261226
/* .name = */ [](const struct llama_sampler * /*smpl*/) { return "penalties"; },
12271227
/* .accept = */ [](struct llama_sampler * smpl, llama_token token) {
12281228
auto * ctx = (llama_sampler_penalties *) smpl->ctx;
1229-
ctx->prev.push_back(token);
1229+
if (ctx->prev.size()) {
1230+
ctx->prev.push_back(token);
1231+
}
12301232
},
12311233
/* .apply = */ [](struct llama_sampler * smpl, llama_token_data_array * cur_p) {
12321234
auto * ctx = (llama_sampler_penalties *) smpl->ctx;

0 commit comments

Comments
 (0)