@@ -18,7 +18,7 @@ struct llama_sampling_context * llama_sampling_init(const struct llama_model * m
1818 lparams.top_p = params.top_p ;
1919 lparams.min_p = params.min_p ;
2020 lparams.tfs_z = params.tfs_z ;
21- lparams.typical_p = params.typical_p ;
21+ lparams.typ_p = params.typ_p ;
2222 lparams.temp = params.temp ;
2323 lparams.dynatemp_range = params.dynatemp_range ;
2424 lparams.dynatemp_exponent = params.dynatemp_exponent ;
@@ -94,7 +94,7 @@ std::string llama_sampling_print(const gpt_sampling_params & params) {
9494 " \t top_k = %d, tfs_z = %.3f, top_p = %.3f, min_p = %.3f, typical_p = %.3f, temp = %.3f\n "
9595 " \t mirostat = %d, mirostat_lr = %.3f, mirostat_ent = %.3f" ,
9696 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 ,
9898 params.mirostat , params.mirostat_eta , params.mirostat_tau );
9999
100100 return std::string (result);
@@ -132,7 +132,7 @@ std::string llama_sampling_type_to_str(llama_sampler_type sampler_type) {
132132 switch (sampler_type) {
133133 case LLAMA_SAMPLER_TYPE_TOP_K: return " top_k" ;
134134 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 " ;
136136 case LLAMA_SAMPLER_TYPE_TOP_P: return " top_p" ;
137137 case LLAMA_SAMPLER_TYPE_MIN_P: return " min_p" ;
138138 case LLAMA_SAMPLER_TYPE_TEMPERATURE: return " temperature" ;
@@ -144,7 +144,7 @@ std::vector<llama_sampler_type> llama_sampling_types_from_names(const std::vecto
144144 std::unordered_map<std::string, llama_sampler_type> sampler_canonical_name_map {
145145 { " top_k" , LLAMA_SAMPLER_TYPE_TOP_K },
146146 { " top_p" , LLAMA_SAMPLER_TYPE_TOP_P },
147- { " typical_p " , LLAMA_SAMPLER_TYPE_TYPICAL_P },
147+ { " typ_p " , LLAMA_SAMPLER_TYPE_TYPICAL_P },
148148 { " min_p" , LLAMA_SAMPLER_TYPE_MIN_P },
149149 { " tfs_z" , LLAMA_SAMPLER_TYPE_TFS_Z },
150150 { " temperature" , LLAMA_SAMPLER_TYPE_TEMPERATURE },
@@ -158,6 +158,8 @@ std::vector<llama_sampler_type> llama_sampling_types_from_names(const std::vecto
158158 { " nucleus" , LLAMA_SAMPLER_TYPE_TOP_P },
159159 { " typical-p" , LLAMA_SAMPLER_TYPE_TYPICAL_P },
160160 { " typical" , LLAMA_SAMPLER_TYPE_TYPICAL_P },
161+ { " typ-p" , LLAMA_SAMPLER_TYPE_TYPICAL_P },
162+ { " typ" , LLAMA_SAMPLER_TYPE_TYPICAL_P },
161163 { " min-p" , LLAMA_SAMPLER_TYPE_MIN_P },
162164 { " tfs-z" , LLAMA_SAMPLER_TYPE_TFS_Z },
163165 { " tfs" , LLAMA_SAMPLER_TYPE_TFS_Z },
@@ -205,29 +207,6 @@ std::vector<llama_sampler_type> llama_sampling_types_from_chars(const std::strin
205207 return sampler_types;
206208}
207209
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-
231210void llama_sampling_prepare (
232211 struct llama_sampling_context * ctx_sampling,
233212 struct llama_context * ctx_main,
@@ -238,47 +217,7 @@ void llama_sampling_prepare(
238217static llama_token llama_sampling_sample (
239218 struct llama_sampling_context * ctx_sampling,
240219 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);
282221}
283222
284223llama_token llama_sampling_sample (
0 commit comments