more cleanups
This commit is contained in:
parent
28cac497a6
commit
2dd09c792f
2 changed files with 8 additions and 19 deletions
|
@ -151,22 +151,16 @@ struct common_sampler * common_sampler_init(const struct llama_model * model, co
|
|||
|
||||
lparams.no_perf = params.no_perf;
|
||||
|
||||
std::vector<const char *> c_trigger_words;
|
||||
c_trigger_words.reserve(params.grammar_trigger_words.size());
|
||||
std::vector<const char *> trigger_words;
|
||||
trigger_words.reserve(params.grammar_trigger_words.size());
|
||||
for (const auto & str : params.grammar_trigger_words) {
|
||||
c_trigger_words.push_back(str.c_str());
|
||||
trigger_words.push_back(str.c_str());
|
||||
}
|
||||
auto * result = new common_sampler {
|
||||
/* .params = */ params,
|
||||
/* .grmr = */ llama_sampler_init_grammar(
|
||||
vocab,
|
||||
params.grammar.c_str(),
|
||||
"root",
|
||||
c_trigger_words.data(),
|
||||
c_trigger_words.size(),
|
||||
params.grammar_trigger_tokens.data(),
|
||||
params.grammar_trigger_tokens.size()
|
||||
),
|
||||
/* .grmr = */ llama_sampler_init_grammar(vocab, params.grammar.c_str(), "root",
|
||||
trigger_words.data(), trigger_words.size(),
|
||||
params.grammar_trigger_tokens.data(), params.grammar_trigger_tokens.size()),
|
||||
/* .chain = */ llama_sampler_chain_init(lparams),
|
||||
/* .prev = */ ring_buffer<llama_token>(std::max(32, params.n_prev)),
|
||||
/* .cur = */ {},
|
||||
|
@ -237,9 +231,7 @@ struct common_sampler * common_sampler_init(const struct llama_model * model, co
|
|||
|
||||
void common_sampler_free(struct common_sampler * gsmpl) {
|
||||
if (gsmpl) {
|
||||
if (gsmpl->grmr) {
|
||||
llama_sampler_free(gsmpl->grmr);
|
||||
}
|
||||
|
||||
llama_sampler_free(gsmpl->chain);
|
||||
|
||||
|
@ -258,9 +250,7 @@ void common_sampler_accept(struct common_sampler * gsmpl, llama_token token, boo
|
|||
}
|
||||
|
||||
void common_sampler_reset(struct common_sampler * gsmpl) {
|
||||
if (gsmpl->grmr) {
|
||||
llama_sampler_reset(gsmpl->grmr);
|
||||
}
|
||||
|
||||
llama_sampler_reset(gsmpl->chain);
|
||||
}
|
||||
|
|
|
@ -1504,7 +1504,6 @@ struct llama_sampler * llama_sampler_init_grammar(
|
|||
size_t num_trigger_words,
|
||||
const llama_token * trigger_tokens,
|
||||
size_t num_trigger_tokens) {
|
||||
// struct llama_sampler * llama_sampler_init_grammar(const struct llama_vocab * vocab, const char * grammar_str, const char * grammar_root) {
|
||||
auto * ctx = new llama_sampler_grammar;
|
||||
|
||||
if (grammar_str != nullptr && grammar_str[0] != '\0') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue