Skip to content

Commit ffd0079

Browse files
authored
common : avoid unnecessary logits fetch (#8358)
1 parent 04ce3a8 commit ffd0079

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

common/sampling.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,6 @@ static llama_token llama_sampling_sample_impl(
282282
GGML_ASSERT(!original_logits.empty());
283283
}
284284
llama_token id = 0;
285-
// Get a pointer to the logits
286-
float * logits = llama_get_logits_ith(ctx_main, idx);
287285

288286
if (temp < 0.0) {
289287
// greedy sampling, with probs
@@ -324,6 +322,9 @@ static llama_token llama_sampling_sample_impl(
324322
}
325323

326324
if (ctx_sampling->grammar != NULL && !is_resampling) {
325+
// Get a pointer to the logits
326+
float * logits = llama_get_logits_ith(ctx_main, idx);
327+
327328
// Create an array with a single token data element for the sampled id
328329
llama_token_data single_token_data = {id, logits[id], 0.0f};
329330
llama_token_data_array single_token_data_array = { &single_token_data, 1, false };

0 commit comments

Comments
 (0)