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

Function llama_grammar_accept_token

llama.cpp:8656–8680  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8654}
8655
8656void llama_grammar_accept_token(struct llama_context * ctx, struct llama_grammar * grammar, llama_token token) {
8657 const int64_t t_start_sample_us = ggml_time_us();
8658
8659 if (token == llama_token_eos(&ctx->model)) {
8660 for (const auto & stack : grammar->stacks) {
8661 if (stack.empty()) {
8662 return;
8663 }
8664 }
8665 GGML_ASSERT(false);
8666 }
8667
8668 const std::string piece = llama_token_to_piece(ctx, token);
8669
8670 // Note terminating 0 in decoded string
8671 const auto decoded = decode_utf8(piece.c_str(), grammar->partial_utf8);
8672 const auto & code_points = decoded.first;
8673 for (auto it = code_points.begin(), end = code_points.end() - 1; it != end; ++it) {
8674 grammar->stacks = llama_grammar_accept(grammar->rules, grammar->stacks, *it);
8675 }
8676 grammar->partial_utf8 = decoded.second;
8677 GGML_ASSERT(!grammar->stacks.empty());
8678
8679 ctx->t_sample_us += ggml_time_us() - t_start_sample_us;
8680}
8681
8682//
8683// Beam search

Callers 1

llama_sampling_acceptFunction · 0.85

Calls 9

ggml_time_usFunction · 0.70
llama_token_eosFunction · 0.70
llama_token_to_pieceFunction · 0.70
decode_utf8Function · 0.70
llama_grammar_acceptFunction · 0.70
emptyMethod · 0.45
c_strMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected