Skip to content

Commit 4aa1fb0

Browse files
committed
llama : add option for greedy sampling with probs
1 parent 34b2a5e commit 4aa1fb0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Diff for: common/sampling.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,13 @@ llama_token llama_sampling_sample(
167167
llama_sample_grammar(ctx_main, &cur_p, ctx_sampling->grammar);
168168
}
169169

170-
if (temp <= 0) {
171-
// greedy sampling
170+
if (temp < 0.0) {
171+
// greedy sampling, no probs
172172
id = llama_sample_token_greedy(ctx_main, &cur_p);
173+
} else if (temp == 0.0) {
174+
// greedy sampling, with probs
175+
llama_sample_softmax(ctx_main, &cur_p);
176+
id = cur_p.data[0].id;
173177
} else {
174178
if (mirostat == 1) {
175179
const int mirostat_m = 100;

Diff for: examples/speculative/speculative.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ int main(int argc, char ** argv) {
118118
std::vector<seq_draft> drafts(n_seq_dft);
119119

120120
params.sparams.grammar.clear(); // the draft samplers will copy the target sampler's grammar
121-
params.sparams.temp = std::max(0.01f, params.sparams.temp);
121+
params.sparams.temp = 0.0f;
122122

123123
for (int s = 0; s < n_seq_dft; ++s) {
124124
drafts[s].ctx_sampling = llama_sampling_init(params.sparams);

0 commit comments

Comments
 (0)