| 2306 | } |
| 2307 | |
| 2308 | static void llama_sampler_infill_apply(struct llama_sampler * smpl, llama_token_data_array * cur_p) { |
| 2309 | auto * ctx = (llama_sampler_infill *) smpl->ctx; |
| 2310 | |
| 2311 | llama_sampler_softmax_impl(cur_p); |
| 2312 | |
| 2313 | #if defined(GGML_DEBUG_SAMPLER_INFILL) |
| 2314 | #define LOG_DBG_CUR LLAMA_LOG_DEBUG |
| 2315 | #else |
| 2316 | #define LOG_DBG_CUR(...) |
| 2317 | #endif |
| 2318 | |
| 2319 | for (size_t i = 0; i < cur_p->size; ++i) { |
| 2320 | LOG_DBG_CUR("%s: cur_p[%3zu] = { id: %6d, p: %.6f, logit: %6.3f }\n", __func__, i, cur_p->data[i].id, cur_p->data[i].p, cur_p->data[i].logit); |
| 2321 | } |
| 2322 | |
| 2323 | float p_txt_sum = 0.0f; |
| 2324 | float p_eog_sum = 0.0f; |
| 2325 | |
| 2326 | for (size_t i = 0; i < cur_p->size; ++i) { |
| 2327 | if (ctx->vocab->is_eog(cur_p->data[i].id)) { |
| 2328 | p_eog_sum += cur_p->data[i].p; |
| 2329 | } else { |
| 2330 | p_txt_sum += cur_p->data[i].p; |
| 2331 | } |
| 2332 | } |
| 2333 | |
| 2334 | const float rat = p_eog_sum == 0.0 ? INFINITY : p_txt_sum / p_eog_sum; GGML_UNUSED(rat); |
| 2335 | |
| 2336 | LOG_DBG_CUR("%s: p_txt_sum = %.2f, p_eog_sum = %.2f, rat = %.2f, n = %zu\n", __func__, p_txt_sum, p_eog_sum, rat, cur_p->size); |
| 2337 | |
| 2338 | if (3*p_eog_sum*cur_p->size > p_txt_sum) { |
| 2339 | LOG_DBG_CUR("%s: the ratio p_txt/p_eog = %.2f is too low -> sampling EOG\n", __func__, p_txt_sum/p_eog_sum); |
| 2340 | |
| 2341 | // keep just the EOG tokens |
| 2342 | const auto size_org = cur_p->size; |
| 2343 | |
| 2344 | cur_p->size = 0; |
| 2345 | |
| 2346 | float p_sum = 0.0f; |
| 2347 | |
| 2348 | for (size_t i = 0; i < size_org; ++i) { |
| 2349 | if (ctx->vocab->is_eog(cur_p->data[i].id)) { |
| 2350 | p_sum += cur_p->data[i].p; |
| 2351 | |
| 2352 | cur_p->data[cur_p->size++] = cur_p->data[i]; |
| 2353 | } |
| 2354 | } |
| 2355 | |
| 2356 | // normalize probs |
| 2357 | for (size_t i = 0; i < cur_p->size; ++i) { |
| 2358 | cur_p->data[i].p /= p_sum; |
| 2359 | } |
| 2360 | |
| 2361 | return; |
| 2362 | } |
| 2363 | |
| 2364 | size_t n_combined = 0; GGML_UNUSED(n_combined); |
| 2365 |
nothing calls this directly
no test coverage detected