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

Function test_repetition_penalties

tests/test-sampling.cpp:104–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102}
103
104static void test_repetition_penalties(
105 const std::vector<float> & probs, const std::vector<llama_token> & last_tokens,
106 const std::vector<float> & expected_probs, float repeat_penalty, float alpha_frequency, float alpha_presence
107) {
108 GGML_ASSERT(probs.size() == expected_probs.size());
109
110 size_t n_vocab = probs.size();
111 std::vector<llama_token_data> candidates;
112 candidates.reserve(n_vocab);
113 for (llama_token token_id = 0; token_id < (llama_token)n_vocab; token_id++) {
114 float logit = log(probs[token_id]);
115 candidates.emplace_back(llama_token_data{token_id, logit, 0.0f});
116 }
117
118 llama_token_data_array candidates_p = { candidates.data(), candidates.size(), false };
119 llama_sample_softmax(nullptr, &candidates_p);
120 DUMP(&candidates_p);
121 llama_sample_repetition_penalties(nullptr, &candidates_p, (const llama_token *) last_tokens.data(), last_tokens.size(), repeat_penalty, alpha_frequency, alpha_presence);
122 llama_sample_softmax(nullptr, &candidates_p);
123 DUMP(&candidates_p);
124
125 GGML_ASSERT(candidates_p.size == expected_probs.size());
126 for (size_t i = 0; i < candidates_p.size; i++) {
127 GGML_ASSERT(fabs(candidates_p.data[i].p - expected_probs[i]) < 1e-3);
128 }
129}
130
131int main(void) {
132 ggml_time_init();

Callers 1

mainFunction · 0.85

Calls 6

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

Tested by

no test coverage detected