@@ -119,6 +119,8 @@ void YamlHandler::ModelConfigFromYaml() {
119119 tmp.ctx_len = yaml_node_[" ctx_len" ].as <int >();
120120 if (yaml_node_[" n_parallel" ])
121121 tmp.n_parallel = yaml_node_[" n_parallel" ].as <int >();
122+ if (yaml_node_[" cpu_threads" ])
123+ tmp.cpu_threads = yaml_node_[" cpu_threads" ].as <int >();
122124 if (yaml_node_[" tp" ])
123125 tmp.tp = yaml_node_[" tp" ].as <int >();
124126 if (yaml_node_[" stream" ])
@@ -224,6 +226,8 @@ void YamlHandler::UpdateModelConfig(ModelConfig new_model_config) {
224226 yaml_node_[" ctx_len" ] = model_config_.ctx_len ;
225227 if (!std::isnan (static_cast <double >(model_config_.n_parallel )))
226228 yaml_node_[" n_parallel" ] = model_config_.n_parallel ;
229+ if (!std::isnan (static_cast <double >(model_config_.cpu_threads )))
230+ yaml_node_[" cpu_threads" ] = model_config_.cpu_threads ;
227231 if (!std::isnan (static_cast <double >(model_config_.tp )))
228232 yaml_node_[" tp" ] = model_config_.tp ;
229233 if (!std::isnan (static_cast <double >(model_config_.stream )))
@@ -283,110 +287,112 @@ void YamlHandler::UpdateModelConfig(ModelConfig new_model_config) {
283287// Method to write all attributes to a YAML file
284288void YamlHandler::WriteYamlFile (const std::string& file_path) const {
285289 try {
286- std::ofstream outFile (file_path);
287- if (!outFile ) {
290+ std::ofstream out_file (file_path);
291+ if (!out_file ) {
288292 throw std::runtime_error (" Failed to open output file." );
289293 }
290294 // Write GENERAL GGUF METADATA
291- outFile << " # BEGIN GENERAL GGUF METADATA\n " ;
292- outFile << format_utils::writeKeyValue (
295+ out_file << " # BEGIN GENERAL GGUF METADATA\n " ;
296+ out_file << format_utils::WriteKeyValue (
293297 " id" , yaml_node_[" id" ],
294298 " Model ID unique between models (author / quantization)" );
295- outFile << format_utils::writeKeyValue (
299+ out_file << format_utils::WriteKeyValue (
296300 " model" , yaml_node_[" model" ],
297301 " Model ID which is used for request construct - should be "
298302 " unique between models (author / quantization)" );
299- outFile << format_utils::writeKeyValue (" name" , yaml_node_[" name" ],
303+ out_file << format_utils::WriteKeyValue (" name" , yaml_node_[" name" ],
300304 " metadata.general.name" );
301305 if (yaml_node_[" version" ]) {
302- outFile << " version: " << yaml_node_[" version" ].as <std::string>() << " \n " ;
306+ out_file << " version: " << yaml_node_[" version" ].as <std::string>() << " \n " ;
303307 }
304308 if (yaml_node_[" files" ] && yaml_node_[" files" ].size ()) {
305- outFile << " files: # Can be relative OR absolute local file "
309+ out_file << " files: # Can be relative OR absolute local file "
306310 " path\n " ;
307311 for (const auto & source : yaml_node_[" files" ]) {
308- outFile << " - " << source << " \n " ;
312+ out_file << " - " << source << " \n " ;
309313 }
310314 }
311315
312- outFile << " # END GENERAL GGUF METADATA\n " ;
313- outFile << " \n " ;
316+ out_file << " # END GENERAL GGUF METADATA\n " ;
317+ out_file << " \n " ;
314318 // Write INFERENCE PARAMETERS
315- outFile << " # BEGIN INFERENCE PARAMETERS\n " ;
316- outFile << " # BEGIN REQUIRED\n " ;
319+ out_file << " # BEGIN INFERENCE PARAMETERS\n " ;
320+ out_file << " # BEGIN REQUIRED\n " ;
317321 if (yaml_node_[" stop" ] && yaml_node_[" stop" ].size ()) {
318- outFile << " stop: # tokenizer.ggml.eos_token_id\n " ;
322+ out_file << " stop: # tokenizer.ggml.eos_token_id\n " ;
319323 for (const auto & stop : yaml_node_[" stop" ]) {
320- outFile << " - " << stop << " \n " ;
324+ out_file << " - " << stop << " \n " ;
321325 }
322326 }
323327
324- outFile << " # END REQUIRED\n " ;
325- outFile << " \n " ;
326- outFile << " # BEGIN OPTIONAL\n " ;
327- outFile << format_utils::writeKeyValue (" size" , yaml_node_[" size" ]);
328- outFile << format_utils::writeKeyValue (" stream" , yaml_node_[" stream" ],
328+ out_file << " # END REQUIRED\n " ;
329+ out_file << " \n " ;
330+ out_file << " # BEGIN OPTIONAL\n " ;
331+ out_file << format_utils::WriteKeyValue (" size" , yaml_node_[" size" ]);
332+ out_file << format_utils::WriteKeyValue (" stream" , yaml_node_[" stream" ],
329333 " Default true?" );
330- outFile << format_utils::writeKeyValue (" top_p" , yaml_node_[" top_p" ],
334+ out_file << format_utils::WriteKeyValue (" top_p" , yaml_node_[" top_p" ],
331335 " Ranges: 0 to 1" );
332- outFile << format_utils::writeKeyValue (
336+ out_file << format_utils::WriteKeyValue (
333337 " temperature" , yaml_node_[" temperature" ], " Ranges: 0 to 1" );
334- outFile << format_utils::writeKeyValue (
338+ out_file << format_utils::WriteKeyValue (
335339 " frequency_penalty" , yaml_node_[" frequency_penalty" ], " Ranges: 0 to 1" );
336- outFile << format_utils::writeKeyValue (
340+ out_file << format_utils::WriteKeyValue (
337341 " presence_penalty" , yaml_node_[" presence_penalty" ], " Ranges: 0 to 1" );
338- outFile << format_utils::writeKeyValue (
342+ out_file << format_utils::WriteKeyValue (
339343 " max_tokens" , yaml_node_[" max_tokens" ],
340344 " Should be default to context length" );
341- outFile << format_utils::writeKeyValue (" seed" , yaml_node_[" seed" ]);
342- outFile << format_utils::writeKeyValue (" dynatemp_range" ,
345+ out_file << format_utils::WriteKeyValue (" seed" , yaml_node_[" seed" ]);
346+ out_file << format_utils::WriteKeyValue (" dynatemp_range" ,
343347 yaml_node_[" dynatemp_range" ]);
344- outFile << format_utils::writeKeyValue (" dynatemp_exponent" ,
348+ out_file << format_utils::WriteKeyValue (" dynatemp_exponent" ,
345349 yaml_node_[" dynatemp_exponent" ]);
346- outFile << format_utils::writeKeyValue (" top_k" , yaml_node_[" top_k" ]);
347- outFile << format_utils::writeKeyValue (" min_p" , yaml_node_[" min_p" ]);
348- outFile << format_utils::writeKeyValue (" tfs_z" , yaml_node_[" tfs_z" ]);
349- outFile << format_utils::writeKeyValue (" typ_p" , yaml_node_[" typ_p" ]);
350- outFile << format_utils::writeKeyValue (" repeat_last_n" ,
350+ out_file << format_utils::WriteKeyValue (" top_k" , yaml_node_[" top_k" ]);
351+ out_file << format_utils::WriteKeyValue (" min_p" , yaml_node_[" min_p" ]);
352+ out_file << format_utils::WriteKeyValue (" tfs_z" , yaml_node_[" tfs_z" ]);
353+ out_file << format_utils::WriteKeyValue (" typ_p" , yaml_node_[" typ_p" ]);
354+ out_file << format_utils::WriteKeyValue (" repeat_last_n" ,
351355 yaml_node_[" repeat_last_n" ]);
352- outFile << format_utils::writeKeyValue (" repeat_penalty" ,
356+ out_file << format_utils::WriteKeyValue (" repeat_penalty" ,
353357 yaml_node_[" repeat_penalty" ]);
354- outFile << format_utils::writeKeyValue (" mirostat" , yaml_node_[" mirostat" ]);
355- outFile << format_utils::writeKeyValue (" mirostat_tau" ,
358+ out_file << format_utils::WriteKeyValue (" mirostat" , yaml_node_[" mirostat" ]);
359+ out_file << format_utils::WriteKeyValue (" mirostat_tau" ,
356360 yaml_node_[" mirostat_tau" ]);
357- outFile << format_utils::writeKeyValue (" mirostat_eta" ,
361+ out_file << format_utils::WriteKeyValue (" mirostat_eta" ,
358362 yaml_node_[" mirostat_eta" ]);
359- outFile << format_utils::writeKeyValue (" penalize_nl" ,
363+ out_file << format_utils::WriteKeyValue (" penalize_nl" ,
360364 yaml_node_[" penalize_nl" ]);
361- outFile << format_utils::writeKeyValue (" ignore_eos" ,
365+ out_file << format_utils::WriteKeyValue (" ignore_eos" ,
362366 yaml_node_[" ignore_eos" ]);
363- outFile << format_utils::writeKeyValue (" n_probs" , yaml_node_[" n_probs" ]);
364- outFile << format_utils::writeKeyValue (" min_keep" , yaml_node_[" min_keep" ]);
365- outFile << format_utils::writeKeyValue (" grammar" , yaml_node_[" grammar" ]);
366- outFile << " # END OPTIONAL\n " ;
367- outFile << " # END INFERENCE PARAMETERS\n " ;
368- outFile << " \n " ;
367+ out_file << format_utils::WriteKeyValue (" n_probs" , yaml_node_[" n_probs" ]);
368+ out_file << format_utils::WriteKeyValue (" min_keep" , yaml_node_[" min_keep" ]);
369+ out_file << format_utils::WriteKeyValue (" grammar" , yaml_node_[" grammar" ]);
370+ out_file << " # END OPTIONAL\n " ;
371+ out_file << " # END INFERENCE PARAMETERS\n " ;
372+ out_file << " \n " ;
369373 // Write MODEL LOAD PARAMETERS
370- outFile << " # BEGIN MODEL LOAD PARAMETERS\n " ;
371- outFile << " # BEGIN REQUIRED\n " ;
372- outFile << format_utils::writeKeyValue (" engine" , yaml_node_[" engine" ],
374+ out_file << " # BEGIN MODEL LOAD PARAMETERS\n " ;
375+ out_file << " # BEGIN REQUIRED\n " ;
376+ out_file << format_utils::WriteKeyValue (" engine" , yaml_node_[" engine" ],
373377 " engine to run model" );
374- outFile << " prompt_template:" ;
375- outFile << " " << yaml_node_[" prompt_template" ] << " \n " ;
376- outFile << " # END REQUIRED\n " ;
377- outFile << " \n " ;
378- outFile << " # BEGIN OPTIONAL\n " ;
379- outFile << format_utils::writeKeyValue (
378+ out_file << " prompt_template:" ;
379+ out_file << " " << yaml_node_[" prompt_template" ] << " \n " ;
380+ out_file << " # END REQUIRED\n " ;
381+ out_file << " \n " ;
382+ out_file << " # BEGIN OPTIONAL\n " ;
383+ out_file << format_utils::WriteKeyValue (
380384 " ctx_len" , yaml_node_[" ctx_len" ],
381385 " llama.context_length | 0 or undefined = loaded from model" );
382- outFile << format_utils::writeKeyValue (" n_parallel" ,
386+ out_file << format_utils::WriteKeyValue (" n_parallel" ,
383387 yaml_node_[" n_parallel" ]);
384- outFile << format_utils::writeKeyValue (" ngl" , yaml_node_[" ngl" ],
388+ out_file << format_utils::WriteKeyValue (" cpu_threads" ,
389+ yaml_node_[" cpu_threads" ]);
390+ out_file << format_utils::WriteKeyValue (" ngl" , yaml_node_[" ngl" ],
385391 " Undefined = loaded from model" );
386- outFile << " # END OPTIONAL\n " ;
387- outFile << " # END MODEL LOAD PARAMETERS\n " ;
392+ out_file << " # END OPTIONAL\n " ;
393+ out_file << " # END MODEL LOAD PARAMETERS\n " ;
388394
389- outFile .close ();
395+ out_file .close ();
390396 } catch (const std::exception& e) {
391397 std::cerr << " Error writing to file: " << e.what () << std::endl;
392398 throw ;
0 commit comments