From 56995caa48f29a589911839043e77a977c70691a Mon Sep 17 00:00:00 2001 From: Ycros <18012+ycros@users.noreply.github.com> Date: Sun, 23 Jul 2023 11:52:03 +1000 Subject: [PATCH] Fix mirostatv2. (#338) --- gpttype_adapter.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gpttype_adapter.cpp b/gpttype_adapter.cpp index 05a39518b948f..7eafa55c317a9 100644 --- a/gpttype_adapter.cpp +++ b/gpttype_adapter.cpp @@ -178,6 +178,11 @@ llama_token sample_token_mirostat_v2(llama_token_data_array * candidates, std::m candidates->size = std::distance(candidates->data, std::find_if(candidates->data, candidates->data + candidates->size, [&](const llama_token_data & candidate) { return -log2f(candidate.p) > *mu; })); + + if (candidates->size == 0) { + candidates->size = 1; + } + // Normalize the probabilities of the remaining words llama_sample_softmax(nullptr, candidates); // Sample the next word X from the remaining words