@@ -21,11 +21,13 @@ void YamlHandler::ReadYamlFile(const std::string& file_path) {
21
21
22
22
try {
23
23
yaml_node_ = YAML::LoadFile (file_path);
24
+ auto nomalize_path = [](std::string p) {
25
+ std::replace (p.begin (), p.end (), ' \\ ' , ' /' );
26
+ return p;
27
+ };
24
28
// incase of model.yml file, we don't have files yet, create them
25
29
if (!yaml_node_[" files" ]) {
26
- auto s = file_path;
27
- // normalize path
28
- std::replace (s.begin (), s.end (), ' \\ ' , ' /' );
30
+ auto s = nomalize_path (file_path);
29
31
std::vector<std::string> v;
30
32
if (yaml_node_[" engine" ] &&
31
33
(yaml_node_[" engine" ].as <std::string>() == kLlamaRepo ||
@@ -41,6 +43,18 @@ void YamlHandler::ReadYamlFile(const std::string& file_path) {
41
43
// TODO(any) need to support mutiple gguf files
42
44
yaml_node_[" files" ] = v;
43
45
}
46
+
47
+ // add mmproj file to yml if exists
48
+ if (!yaml_node_[" mmproj" ]) {
49
+ auto s = nomalize_path (file_path);
50
+ auto abs_path = s.substr (0 , s.find_last_of (' /' )) + " /mmproj.gguf" ;
51
+ CTL_DBG (" mmproj: " << abs_path);
52
+ auto rel_path = fmu::ToRelativeCortexDataPath (fs::path (abs_path));
53
+ if (std::filesystem::exists (abs_path)) {
54
+ yaml_node_[" mmproj" ] = rel_path.string ();
55
+ }
56
+ }
57
+
44
58
} catch (const YAML::BadFile& e) {
45
59
throw ;
46
60
}
@@ -131,6 +145,8 @@ void YamlHandler::ModelConfigFromYaml() {
131
145
tmp.stop = yaml_node_[" stop" ].as <std::vector<std::string>>();
132
146
if (yaml_node_[" files" ])
133
147
tmp.files = yaml_node_[" files" ].as <std::vector<std::string>>();
148
+ if (yaml_node_[" mmproj" ])
149
+ tmp.mmproj = yaml_node_[" mmproj" ].as <std::string>();
134
150
if (yaml_node_[" created" ])
135
151
tmp.created = yaml_node_[" created" ].as <std::size_t >();
136
152
@@ -239,6 +255,9 @@ void YamlHandler::UpdateModelConfig(ModelConfig new_model_config) {
239
255
if (model_config_.files .size () > 0 )
240
256
yaml_node_[" files" ] = model_config_.files ;
241
257
258
+ if (!model_config_.mmproj .empty ())
259
+ yaml_node_[" mmproj" ] = model_config_.mmproj ;
260
+
242
261
if (!std::isnan (static_cast <double >(model_config_.seed )))
243
262
yaml_node_[" seed" ] = model_config_.seed ;
244
263
if (!std::isnan (model_config_.dynatemp_range ))
@@ -301,17 +320,21 @@ void YamlHandler::WriteYamlFile(const std::string& file_path) const {
301
320
" Model ID which is used for request construct - should be "
302
321
" unique between models (author / quantization)" );
303
322
out_file << format_utils::WriteKeyValue (" name" , yaml_node_[" name" ],
304
- " metadata.general.name" );
323
+ " metadata.general.name" );
305
324
if (yaml_node_[" version" ]) {
306
- out_file << " version: " << yaml_node_[" version" ].as <std::string>() << " \n " ;
325
+ out_file << " version: " << yaml_node_[" version" ].as <std::string>()
326
+ << " \n " ;
307
327
}
308
328
if (yaml_node_[" files" ] && yaml_node_[" files" ].size ()) {
309
329
out_file << " files: # Can be relative OR absolute local file "
310
- " path\n " ;
330
+ " path\n " ;
311
331
for (const auto & source : yaml_node_[" files" ]) {
312
332
out_file << " - " << source << " \n " ;
313
333
}
314
334
}
335
+ if (yaml_node_[" mmproj" ]) {
336
+ out_file << " mmproj: " << yaml_node_[" mmproj" ].as <std::string>() << " \n " ;
337
+ }
315
338
316
339
out_file << " # END GENERAL GGUF METADATA\n " ;
317
340
out_file << " \n " ;
@@ -330,9 +353,9 @@ void YamlHandler::WriteYamlFile(const std::string& file_path) const {
330
353
out_file << " # BEGIN OPTIONAL\n " ;
331
354
out_file << format_utils::WriteKeyValue (" size" , yaml_node_[" size" ]);
332
355
out_file << format_utils::WriteKeyValue (" stream" , yaml_node_[" stream" ],
333
- " Default true?" );
356
+ " Default true?" );
334
357
out_file << format_utils::WriteKeyValue (" top_p" , yaml_node_[" top_p" ],
335
- " Ranges: 0 to 1" );
358
+ " Ranges: 0 to 1" );
336
359
out_file << format_utils::WriteKeyValue (
337
360
" temperature" , yaml_node_[" temperature" ], " Ranges: 0 to 1" );
338
361
out_file << format_utils::WriteKeyValue (
@@ -344,26 +367,26 @@ void YamlHandler::WriteYamlFile(const std::string& file_path) const {
344
367
" Should be default to context length" );
345
368
out_file << format_utils::WriteKeyValue (" seed" , yaml_node_[" seed" ]);
346
369
out_file << format_utils::WriteKeyValue (" dynatemp_range" ,
347
- yaml_node_[" dynatemp_range" ]);
370
+ yaml_node_[" dynatemp_range" ]);
348
371
out_file << format_utils::WriteKeyValue (" dynatemp_exponent" ,
349
- yaml_node_[" dynatemp_exponent" ]);
372
+ yaml_node_[" dynatemp_exponent" ]);
350
373
out_file << format_utils::WriteKeyValue (" top_k" , yaml_node_[" top_k" ]);
351
374
out_file << format_utils::WriteKeyValue (" min_p" , yaml_node_[" min_p" ]);
352
375
out_file << format_utils::WriteKeyValue (" tfs_z" , yaml_node_[" tfs_z" ]);
353
376
out_file << format_utils::WriteKeyValue (" typ_p" , yaml_node_[" typ_p" ]);
354
377
out_file << format_utils::WriteKeyValue (" repeat_last_n" ,
355
- yaml_node_[" repeat_last_n" ]);
378
+ yaml_node_[" repeat_last_n" ]);
356
379
out_file << format_utils::WriteKeyValue (" repeat_penalty" ,
357
- yaml_node_[" repeat_penalty" ]);
380
+ yaml_node_[" repeat_penalty" ]);
358
381
out_file << format_utils::WriteKeyValue (" mirostat" , yaml_node_[" mirostat" ]);
359
382
out_file << format_utils::WriteKeyValue (" mirostat_tau" ,
360
- yaml_node_[" mirostat_tau" ]);
383
+ yaml_node_[" mirostat_tau" ]);
361
384
out_file << format_utils::WriteKeyValue (" mirostat_eta" ,
362
- yaml_node_[" mirostat_eta" ]);
385
+ yaml_node_[" mirostat_eta" ]);
363
386
out_file << format_utils::WriteKeyValue (" penalize_nl" ,
364
- yaml_node_[" penalize_nl" ]);
387
+ yaml_node_[" penalize_nl" ]);
365
388
out_file << format_utils::WriteKeyValue (" ignore_eos" ,
366
- yaml_node_[" ignore_eos" ]);
389
+ yaml_node_[" ignore_eos" ]);
367
390
out_file << format_utils::WriteKeyValue (" n_probs" , yaml_node_[" n_probs" ]);
368
391
out_file << format_utils::WriteKeyValue (" min_keep" , yaml_node_[" min_keep" ]);
369
392
out_file << format_utils::WriteKeyValue (" grammar" , yaml_node_[" grammar" ]);
@@ -374,7 +397,7 @@ void YamlHandler::WriteYamlFile(const std::string& file_path) const {
374
397
out_file << " # BEGIN MODEL LOAD PARAMETERS\n " ;
375
398
out_file << " # BEGIN REQUIRED\n " ;
376
399
out_file << format_utils::WriteKeyValue (" engine" , yaml_node_[" engine" ],
377
- " engine to run model" );
400
+ " engine to run model" );
378
401
out_file << " prompt_template:" ;
379
402
out_file << " " << yaml_node_[" prompt_template" ] << " \n " ;
380
403
out_file << " # END REQUIRED\n " ;
@@ -384,11 +407,11 @@ void YamlHandler::WriteYamlFile(const std::string& file_path) const {
384
407
" ctx_len" , yaml_node_[" ctx_len" ],
385
408
" llama.context_length | 0 or undefined = loaded from model" );
386
409
out_file << format_utils::WriteKeyValue (" n_parallel" ,
387
- yaml_node_[" n_parallel" ]);
410
+ yaml_node_[" n_parallel" ]);
388
411
out_file << format_utils::WriteKeyValue (" cpu_threads" ,
389
- yaml_node_[" cpu_threads" ]);
412
+ yaml_node_[" cpu_threads" ]);
390
413
out_file << format_utils::WriteKeyValue (" ngl" , yaml_node_[" ngl" ],
391
- " Undefined = loaded from model" );
414
+ " Undefined = loaded from model" );
392
415
out_file << " # END OPTIONAL\n " ;
393
416
out_file << " # END MODEL LOAD PARAMETERS\n " ;
394
417
0 commit comments