Skip to content

Commit 7703bed

Browse files
Temp: Fix Needlessly Iterating on Candidates During Greedy Sampling (#1854)
1 parent b281d25 commit 7703bed

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

gpttype_adapter.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,13 +1540,10 @@ void sample_entropy(llama_token_data_array * cur_p, float min_temp, float max_te
15401540

15411541
void sample_temperature(llama_token_data_array * candidates_p, float temp, float smoothing_factor, float smoothing_curve)
15421542
{
1543-
bool isgreedy = false;
15441543
if (temp <= 0)
15451544
{
1546-
// Imitate greedy sampling
1547-
temp = 0.00390625f; //cannot be zero else div0, this is 1/256
1548-
smoothing_factor = 0;
1549-
isgreedy = true;
1545+
sample_top_k(candidates_p, 1); //only want first candidate
1546+
return;
15501547
}
15511548

15521549
for (size_t i = 0; i < candidates_p->size; ++i) {
@@ -1565,11 +1562,6 @@ void sample_temperature(llama_token_data_array * candidates_p, float temp, float
15651562
}
15661563
sample_softmax(candidates_p);
15671564
}
1568-
1569-
if(isgreedy)
1570-
{
1571-
sample_top_k(candidates_p, 1); //only want first candidate
1572-
}
15731565
}
15741566

15751567
void sample_grammar(FileFormat file_format, int32_t n_vocab, llama_token_data_array * candidates, const struct llama_grammar * grammar) {

0 commit comments

Comments
 (0)