From 2afd2184793541f67f660ca1aabe399aaa71719e Mon Sep 17 00:00:00 2001 From: xaedes Date: Sun, 21 May 2023 21:12:10 +0200 Subject: [PATCH] fix bug in llama_sample_token_mirostat_v2 when all candidates are filtered out through mu threshold, the following soft_max operation will fail. so keep at least one. --- llama.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/llama.cpp b/llama.cpp index 98f49abd7..ca61a69e0 100644 --- a/llama.cpp +++ b/llama.cpp @@ -1882,6 +1882,10 @@ llama_token llama_sample_token_mirostat_v2(struct llama_context * ctx, llama_tok return -log2f(candidate.p) > *mu; })); + if (candidates->size == 0) { + candidates->size = 1; + } + // Normalize the probabilities of the remaining words llama_sample_softmax(ctx, candidates);