MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / llama_sampling_init

Function llama_sampling_init

common/sampling.cpp:3–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include "sampling.h"
2
3struct llama_sampling_context * llama_sampling_init(const struct llama_sampling_params & params) {
4 struct llama_sampling_context * result = new llama_sampling_context();
5
6 result->params = params;
7 result->grammar = nullptr;
8
9 // if there is a grammar, parse it
10 if (!params.grammar.empty()) {
11 result->parsed_grammar = grammar_parser::parse(params.grammar.c_str());
12
13 // will be empty (default) if there are parse errors
14 if (result->parsed_grammar.rules.empty()) {
15 fprintf(stderr, "%s: failed to parse grammar\n", __func__);
16 return nullptr;
17 }
18
19 std::vector<const llama_grammar_element *> grammar_rules(result->parsed_grammar.c_rules());
20
21 result->grammar = llama_grammar_init(
22 grammar_rules.data(),
23 grammar_rules.size(), result->parsed_grammar.symbol_ids.at("root"));
24 }
25
26 result->prev.resize(params.n_prev);
27
28 return result;
29}
30
31void llama_sampling_free(struct llama_sampling_context * ctx) {
32 if (ctx->grammar != NULL) {

Callers 5

mainFunction · 0.85
mainFunction · 0.85
launch_slot_with_dataMethod · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 9

fprintfFunction · 0.85
llama_grammar_initFunction · 0.85
parseFunction · 0.70
emptyMethod · 0.45
c_strMethod · 0.45
c_rulesMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45

Tested by 1

mainFunction · 0.68