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

Function test_typical

tests/test-sampling.cpp:84–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82}
83
84static void test_typical(const std::vector<float> & probs, const std::vector<float> & expected_probs, float p) {
85 size_t n_vocab = probs.size();
86 std::vector<llama_token_data> candidates;
87 candidates.reserve(n_vocab);
88 for (llama_token token_id = 0; token_id < (llama_token)n_vocab; token_id++) {
89 float logit = log(probs[token_id]);
90 candidates.emplace_back(llama_token_data{token_id, logit, 0.0f});
91 }
92
93 llama_token_data_array candidates_p = { candidates.data(), candidates.size(), false };
94 DUMP(&candidates_p);
95 llama_sample_typical(nullptr, &candidates_p, p, 1);
96 DUMP(&candidates_p);
97
98 GGML_ASSERT(candidates_p.size == expected_probs.size());
99 for (size_t i = 0; i < candidates_p.size; i++) {
100 GGML_ASSERT(fabs(candidates_p.data[i].p - expected_probs[i]) < 1e-3);
101 }
102}
103
104static void test_repetition_penalties(
105 const std::vector<float> & probs, const std::vector<llama_token> & last_tokens,

Callers 1

mainFunction · 0.70

Calls 5

logFunction · 0.85
llama_sample_typicalFunction · 0.85
reserveMethod · 0.80
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected