Skip to content

Commit

Permalink
common : avoid unnecessary logits fetch (ggerganov#8358)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmo314 authored and Neo Zhang committed Jul 13, 2024
1 parent a280d8c commit 029999a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions common/sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ static llama_token llama_sampling_sample_impl(
GGML_ASSERT(!original_logits.empty());
}
llama_token id = 0;
// Get a pointer to the logits
float * logits = llama_get_logits_ith(ctx_main, idx);

if (temp < 0.0) {
// greedy sampling, with probs
Expand Down Expand Up @@ -324,6 +322,9 @@ static llama_token llama_sampling_sample_impl(
}

if (ctx_sampling->grammar != NULL && !is_resampling) {
// Get a pointer to the logits
float * logits = llama_get_logits_ith(ctx_main, idx);

// Create an array with a single token data element for the sampled id
llama_token_data single_token_data = {id, logits[id], 0.0f};
llama_token_data_array single_token_data_array = { &single_token_data, 1, false };
Expand Down

0 comments on commit 029999a

Please sign in to comment.