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

Function llama_sample_min_p

llama.cpp:8226–8250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8224}
8225
8226void llama_sample_min_p(struct llama_context * ctx, llama_token_data_array * candidates, float p, size_t min_keep) {
8227 if (p <= 0.0f || !candidates->size) {
8228 return;
8229 }
8230
8231 llama_sample_softmax(ctx, candidates);
8232
8233 const int64_t t_start_sample_us = ggml_time_us();
8234
8235 float scale = candidates->data[0].p; // scale by max prob
8236 size_t i = 1; // first token always matches
8237
8238 for (; i < candidates->size; ++i) {
8239 if (candidates->data[i].p < p * scale && i >= min_keep) {
8240 break; // prob too small
8241 }
8242 }
8243
8244 // Resize the output vector to keep only the matching tokens
8245 candidates->size = i;
8246
8247 if (ctx) {
8248 ctx->t_sample_us += ggml_time_us() - t_start_sample_us;
8249 }
8250}
8251
8252void llama_sample_tail_free(struct llama_context * ctx, llama_token_data_array * candidates, float z, size_t min_keep) {
8253 if (z >= 1.0f || candidates->size <= 2) {

Callers 1

llama_sampling_sampleFunction · 0.85

Calls 2

llama_sample_softmaxFunction · 0.85
ggml_time_usFunction · 0.70

Tested by

no test coverage detected