Skip to content

Commit 393d3af

Browse files
committed
fix seg fault when length of system prompt is more than n_batch
1 parent a21c6fd commit 393d3af

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

examples/server/server.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,13 +1137,14 @@ struct server_context {
11371137
system_tokens = ::llama_tokenize(ctx, system_prompt, true);
11381138

11391139
llama_batch_clear(batch);
1140+
const int32_t n_batch = llama_n_batch(ctx);
1141+
const int32_t batch_size = std::max(n_batch, (int)system_tokens.size());
1142+
batch = llama_batch_init(batch_size, 0, 1);
11401143

11411144
for (int i = 0; i < (int)system_tokens.size(); ++i) {
11421145
llama_batch_add(batch, system_tokens[i], i, { 0 }, false);
11431146
}
11441147

1145-
const int32_t n_batch = llama_n_batch(ctx);
1146-
11471148
for (int32_t i = 0; i < batch.n_tokens; i += n_batch) {
11481149
const int32_t n_tokens = std::min(params.n_batch, batch.n_tokens - i);
11491150
llama_batch batch_view = {

0 commit comments

Comments
 (0)