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

Function llama_sample_token

llama.cpp:8633–8654  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8631}
8632
8633llama_token llama_sample_token(struct llama_context * ctx, llama_token_data_array * candidates) {
8634 GGML_ASSERT(ctx);
8635
8636 const int64_t t_start_sample_us = ggml_time_us();
8637 llama_sample_softmax(nullptr, candidates);
8638
8639 std::vector<float> probs;
8640 probs.reserve(candidates->size);
8641 for (size_t i = 0; i < candidates->size; ++i) {
8642 probs.push_back(candidates->data[i].p);
8643 }
8644
8645 std::discrete_distribution<> dist(probs.begin(), probs.end());
8646 auto & rng = ctx->rng;
8647 int idx = dist(rng);
8648
8649 llama_token result = candidates->data[idx].id;
8650
8651 ctx->t_sample_us += ggml_time_us() - t_start_sample_us;
8652 ctx->n_sample++;
8653 return result;
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();

Callers 6

llama_sampling_sampleFunction · 0.85
sample_idFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 6

llama_sample_softmaxFunction · 0.85
reserveMethod · 0.80
ggml_time_usFunction · 0.70
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected