Skip to content

Commit 1423fce

Browse files
committed
server: infinite loop, move in process_token
server: infinite loop: set stop limit to true
1 parent 5d64ffd commit 1423fce

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

examples/server/server.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,25 @@ struct server_context {
12081208
LOG_VERBOSE("eos token found", {});
12091209
}
12101210

1211+
auto n_ctx_train = llama_n_ctx_train(model);
1212+
if (slot.params.n_predict < 1 && slot.ga_n == 1 && slot.n_decoded >= n_ctx_train) {
1213+
LOG_WARNING(
1214+
"n_predict is not set and self-context extend is disabled. Limiting generated tokens to n_ctx_train to avoid EOS-less generation infinite loop",
1215+
{
1216+
{ "id_slot", slot.id },
1217+
{ "params.n_predict", slot.params.n_predict },
1218+
{ "slot.n_predict", slot.n_predict },
1219+
{ "slot.n_decoded", slot.n_decoded },
1220+
{ "n_slots", params.n_parallel },
1221+
{ "n_ctx", n_ctx },
1222+
{ "n_ctx_train", n_ctx_train },
1223+
{ "ga_n", slot.ga_n },
1224+
});
1225+
slot.truncated = true;
1226+
slot.has_next_token = false; // stop prediction
1227+
slot.stopped_limit = true;
1228+
}
1229+
12111230
LOG_VERBOSE("next token", {
12121231
{"id_slot", slot.id},
12131232
{"id_task", slot.id_task},
@@ -2258,23 +2277,7 @@ struct server_context {
22582277
});
22592278
}
22602279

2261-
auto n_ctx_train = llama_n_ctx_train(model);
2262-
bool stop_prediction = false;
2263-
if (slot.params.n_predict < 1 && slot.ga_n == 1 && slot.n_decoded >= n_ctx_train) {
2264-
LOG_WARNING("n_predict is not set and self-context extend is disabled. Limiting generated tokens to n_ctx_train to avoid EOS-less generation infinite loop", {
2265-
{"params.n_predict", slot.params.n_predict},
2266-
{"slot.n_predict", slot.n_predict},
2267-
{"slot.n_decoded", slot.n_decoded},
2268-
{"n_slots", params.n_parallel},
2269-
{"n_ctx", n_ctx},
2270-
{"n_ctx_train", n_ctx_train},
2271-
{"ga_n", slot.ga_n},
2272-
});
2273-
slot.truncated = true;
2274-
stop_prediction = true;
2275-
}
2276-
2277-
if (!process_token(result, slot) || stop_prediction) {
2280+
if (!process_token(result, slot)) {
22782281
slot.release();
22792282
slot.print_timings();
22802283
send_final_response(slot);

0 commit comments

Comments
 (0)