Skip to content

Commit f1c9db4

Browse files
authored
fix-loss-of-destroyed-tokens-in-grammar-pre-pass (#1600)
1 parent 5bac0fb commit f1c9db4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

gpttype_adapter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,15 +1653,15 @@ const std::vector<samplers> & sampler_order, llama_grammar * grammar, float dyna
16531653

16541654
//prefilter to top 3k tokens for improved speed
16551655
bool use_grammar = grammar != nullptr;
1656-
size_t n_pre_cull = candidates_p.size;
1656+
std::vector<llama_token_data> precache = (use_grammar ? std::vector<llama_token_data>(candidates) : std::vector<llama_token_data>(0));
16571657

16581658
sample_top_k(&candidates_p, 3000);
16591659

16601660
if (use_grammar) {
16611661
sample_grammar(file_format, n_vocab, &candidates_p, grammar);
16621662
// if top_k 3000 doesn't contain a valid candidate for this grammar, try again pre-cull
16631663
if (candidates_p.size <= 0) {
1664-
candidates_p.size = n_pre_cull;
1664+
candidates_p = { precache.data(), precache.size(), false };
16651665
sample_grammar(file_format, n_vocab, &candidates_p, grammar);
16661666
sample_top_k(&candidates_p, 3000);
16671667
}

0 commit comments

Comments
 (0)