| 8489 | } |
| 8490 | |
| 8491 | void llama_sample_classifier_free_guidance( |
| 8492 | struct llama_context * ctx, |
| 8493 | llama_token_data_array * candidates, |
| 8494 | struct llama_context * guidance_ctx, |
| 8495 | float scale) { |
| 8496 | int64_t t_start_sample_us = ggml_time_us(); |
| 8497 | |
| 8498 | GGML_ASSERT(ctx); |
| 8499 | |
| 8500 | auto n_vocab = llama_n_vocab(llama_get_model(ctx)); |
| 8501 | |
| 8502 | GGML_ASSERT(n_vocab == (int)candidates->size); |
| 8503 | GGML_ASSERT(!candidates->sorted); |
| 8504 | |
| 8505 | std::vector<float> logits_base; |
| 8506 | logits_base.reserve(candidates->size); |
| 8507 | for (size_t i = 0; i < candidates->size; ++i) { |
| 8508 | logits_base.push_back(candidates->data[i].logit); |
| 8509 | } |
| 8510 | llama_log_softmax(logits_base.data(), candidates->size); |
| 8511 | |
| 8512 | float* logits_guidance = llama_get_logits(guidance_ctx); |
| 8513 | llama_log_softmax(logits_guidance, n_vocab); |
| 8514 | |
| 8515 | for (int i = 0; i < n_vocab; ++i) { |
| 8516 | float logit_guidance = logits_guidance[i]; |
| 8517 | float logit_base = logits_base[i]; |
| 8518 | candidates->data[i].logit = scale * (logit_base - logit_guidance) + logit_guidance; |
| 8519 | } |
| 8520 | |
| 8521 | if (ctx) { |
| 8522 | ctx->t_sample_us += ggml_time_us() - t_start_sample_us; |
| 8523 | } |
| 8524 | } |
| 8525 | |
| 8526 | llama_token llama_sample_token_mirostat(struct llama_context * ctx, llama_token_data_array * candidates, float tau, float eta, int m, float * mu) { |
| 8527 | GGML_ASSERT(ctx); |
no test coverage detected