@@ -18,7 +18,7 @@ struct llama_sampling_context * llama_sampling_init(const struct llama_model * m
18
18
lparams.top_p = params.top_p ;
19
19
lparams.min_p = params.min_p ;
20
20
lparams.tfs_z = params.tfs_z ;
21
- lparams.typical_p = params.typical_p ;
21
+ lparams.typ_p = params.typ_p ;
22
22
lparams.temp = params.temp ;
23
23
lparams.dynatemp_range = params.dynatemp_range ;
24
24
lparams.dynatemp_exponent = params.dynatemp_exponent ;
@@ -94,7 +94,7 @@ std::string llama_sampling_print(const gpt_sampling_params & params) {
94
94
" \t top_k = %d, tfs_z = %.3f, top_p = %.3f, min_p = %.3f, typical_p = %.3f, temp = %.3f\n "
95
95
" \t mirostat = %d, mirostat_lr = %.3f, mirostat_ent = %.3f" ,
96
96
params.penalty_last_n , params.penalty_repeat , params.penalty_freq , params.penalty_present ,
97
- params.top_k , params.tfs_z , params.top_p , params.min_p , params.typical_p , params.temp ,
97
+ params.top_k , params.tfs_z , params.top_p , params.min_p , params.typ_p , params.temp ,
98
98
params.mirostat , params.mirostat_eta , params.mirostat_tau );
99
99
100
100
return std::string (result);
@@ -132,7 +132,7 @@ std::string llama_sampling_type_to_str(llama_sampler_type sampler_type) {
132
132
switch (sampler_type) {
133
133
case LLAMA_SAMPLER_TYPE_TOP_K: return " top_k" ;
134
134
case LLAMA_SAMPLER_TYPE_TFS_Z: return " tfs_z" ;
135
- case LLAMA_SAMPLER_TYPE_TYPICAL_P: return " typical_p " ;
135
+ case LLAMA_SAMPLER_TYPE_TYPICAL_P: return " typ_p " ;
136
136
case LLAMA_SAMPLER_TYPE_TOP_P: return " top_p" ;
137
137
case LLAMA_SAMPLER_TYPE_MIN_P: return " min_p" ;
138
138
case LLAMA_SAMPLER_TYPE_TEMPERATURE: return " temperature" ;
@@ -144,7 +144,7 @@ std::vector<llama_sampler_type> llama_sampling_types_from_names(const std::vecto
144
144
std::unordered_map<std::string, llama_sampler_type> sampler_canonical_name_map {
145
145
{ " top_k" , LLAMA_SAMPLER_TYPE_TOP_K },
146
146
{ " top_p" , LLAMA_SAMPLER_TYPE_TOP_P },
147
- { " typical_p " , LLAMA_SAMPLER_TYPE_TYPICAL_P },
147
+ { " typ_p " , LLAMA_SAMPLER_TYPE_TYPICAL_P },
148
148
{ " min_p" , LLAMA_SAMPLER_TYPE_MIN_P },
149
149
{ " tfs_z" , LLAMA_SAMPLER_TYPE_TFS_Z },
150
150
{ " temperature" , LLAMA_SAMPLER_TYPE_TEMPERATURE },
@@ -158,6 +158,8 @@ std::vector<llama_sampler_type> llama_sampling_types_from_names(const std::vecto
158
158
{ " nucleus" , LLAMA_SAMPLER_TYPE_TOP_P },
159
159
{ " typical-p" , LLAMA_SAMPLER_TYPE_TYPICAL_P },
160
160
{ " typical" , LLAMA_SAMPLER_TYPE_TYPICAL_P },
161
+ { " typ-p" , LLAMA_SAMPLER_TYPE_TYPICAL_P },
162
+ { " typ" , LLAMA_SAMPLER_TYPE_TYPICAL_P },
161
163
{ " min-p" , LLAMA_SAMPLER_TYPE_MIN_P },
162
164
{ " tfs-z" , LLAMA_SAMPLER_TYPE_TFS_Z },
163
165
{ " tfs" , LLAMA_SAMPLER_TYPE_TFS_Z },
@@ -205,29 +207,6 @@ std::vector<llama_sampler_type> llama_sampling_types_from_chars(const std::strin
205
207
return sampler_types;
206
208
}
207
209
208
- // no reasons to expose this function in header
209
- static void sampler_queue (
210
- struct llama_sampling_context * ctx_sampling,
211
- struct llama_token_data_array * cur_p) {
212
- llama_sampling * smpl = ctx_sampling->smpl ;
213
-
214
- const gpt_sampling_params & params = ctx_sampling->params ;
215
-
216
- const std::vector<llama_sampler_type> & samplers = params.samplers ;
217
-
218
- for (const auto & sampler : samplers) {
219
- switch (sampler) {
220
- case LLAMA_SAMPLER_TYPE_TOP_K: llama_sampling_top_k (smpl, cur_p); break ;
221
- case LLAMA_SAMPLER_TYPE_TFS_Z: llama_sampling_tail_free (smpl, cur_p); break ;
222
- case LLAMA_SAMPLER_TYPE_TYPICAL_P: llama_sampling_typical (smpl, cur_p); break ;
223
- case LLAMA_SAMPLER_TYPE_TOP_P: llama_sampling_top_p (smpl, cur_p); break ;
224
- case LLAMA_SAMPLER_TYPE_MIN_P: llama_sampling_min_p (smpl, cur_p); break ;
225
- case LLAMA_SAMPLER_TYPE_TEMPERATURE: llama_sampling_temp (smpl, cur_p); break ;
226
- default : break ;
227
- }
228
- }
229
- }
230
-
231
210
void llama_sampling_prepare (
232
211
struct llama_sampling_context * ctx_sampling,
233
212
struct llama_context * ctx_main,
@@ -238,47 +217,7 @@ void llama_sampling_prepare(
238
217
static llama_token llama_sampling_sample (
239
218
struct llama_sampling_context * ctx_sampling,
240
219
struct llama_token_data_array * cur_p) {
241
- llama_sampling * smpl = ctx_sampling->smpl ;
242
-
243
- const gpt_sampling_params & params = ctx_sampling->params ;
244
-
245
- const float temp = params.temp ;
246
- const int mirostat = params.mirostat ;
247
-
248
- llama_token id = 0 ;
249
-
250
- if (temp < 0 .0f || (temp == 0 .0f && params.n_probs > 0 )) {
251
- // greedy sampling, with probs
252
- llama_sampling_softmax (smpl, cur_p);
253
- id = cur_p->data [0 ].id ;
254
- } else if (temp == 0 .0f ) {
255
- // greedy sampling, no probs
256
- id = llama_sampling_sample_greedy (smpl, cur_p);
257
- } else {
258
- if (mirostat != 0 ) {
259
- llama_sampling_temp (smpl, cur_p);
260
- id = llama_sampling_sample_mirostat (smpl, cur_p);
261
- } else {
262
- sampler_queue (ctx_sampling, cur_p);
263
-
264
- id = llama_sampling_sample_dist (smpl, cur_p);
265
-
266
- // {
267
- // const int n_top = 10;
268
- // LOG("top %d candidates:\n", n_top);
269
-
270
- // for (int i = 0; i < n_top; i++) {
271
- // const llama_token id = cur_p.data[i].id;
272
- // (void)id; // To avoid a warning that id is unused when logging is disabled.
273
- // LOG(" - %5d: '%12s' (%.3f)\n", id, llama_token_to_piece(smpl, id).c_str(), cur_p.data[i].p);
274
- // }
275
- // }
276
-
277
- // LOG("sampled token: %5d: '%s'\n", id, llama_token_to_piece(smpl, id).c_str());
278
- }
279
- }
280
-
281
- return id;
220
+ return llama_sampling_sample (ctx_sampling->smpl , cur_p);
282
221
}
283
222
284
223
llama_token llama_sampling_sample (
0 commit comments