Skip to content

Commit 6ef79a6

Browse files
authored
common : refactor '-o' option (#12278)
As discussed in PR 'llama-tts : add -o option' (#12042): * common_params : 'out_file' string is the only output file name parameter left in common_params. It's intended to be used in all example programs implementing an '-o' option. * cvector-generator, export-lora, imatrix : default output filenames moved from 'common_params' to the 'main()' of each example program.
1 parent 4e39a3c commit 6ef79a6

File tree

5 files changed

+13
-19
lines changed

5 files changed

+13
-19
lines changed

common/arg.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -1867,16 +1867,9 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
18671867
).set_examples({LLAMA_EXAMPLE_PASSKEY}));
18681868
add_opt(common_arg(
18691869
{"-o", "--output", "--output-file"}, "FNAME",
1870-
string_format("output file (default: '%s')",
1871-
ex == LLAMA_EXAMPLE_EXPORT_LORA
1872-
? params.lora_outfile.c_str()
1873-
: ex == LLAMA_EXAMPLE_CVECTOR_GENERATOR
1874-
? params.cvector_outfile.c_str()
1875-
: params.out_file.c_str()),
1870+
string_format("output file (default: '%s')", params.out_file.c_str()),
18761871
[](common_params & params, const std::string & value) {
18771872
params.out_file = value;
1878-
params.cvector_outfile = value;
1879-
params.lora_outfile = value;
18801873
}
18811874
).set_examples({LLAMA_EXAMPLE_IMATRIX, LLAMA_EXAMPLE_CVECTOR_GENERATOR, LLAMA_EXAMPLE_EXPORT_LORA}));
18821875
add_opt(common_arg(

common/common.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,6 @@ struct common_params {
407407
int32_t i_pos = -1; // position of the passkey in the junk text
408408

409409
// imatrix params
410-
std::string out_file = "imatrix.dat"; // save the resulting imatrix to this file
411-
412410
int32_t n_out_freq = 10; // output the imatrix every n_out_freq iterations
413411
int32_t n_save_freq = 0; // save the imatrix every n_save_freq iterations
414412
int32_t i_chunk = 0; // start processing from this chunk
@@ -420,16 +418,16 @@ struct common_params {
420418
int n_pca_batch = 100;
421419
int n_pca_iterations = 1000;
422420
dimre_method cvector_dimre_method = DIMRE_METHOD_PCA;
423-
std::string cvector_outfile = "control_vector.gguf";
424421
std::string cvector_positive_file = "examples/cvector-generator/positive.txt";
425422
std::string cvector_negative_file = "examples/cvector-generator/negative.txt";
426423

427424
bool spm_infill = false; // suffix/prefix/middle pattern for infill
428425

429-
std::string lora_outfile = "ggml-lora-merged-f16.gguf";
430-
431426
// batched-bench params
432427
bool batched_bench_output_jsonl = false;
428+
429+
// common params
430+
std::string out_file; // output filename for all example programs
433431
};
434432

435433
// call once at the start of a program if it uses libcommon

examples/cvector-generator/cvector-generator.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ static int prepare_entries(common_params & params, train_context & ctx_train) {
394394
int main(int argc, char ** argv) {
395395
common_params params;
396396

397+
params.out_file = "control_vector.gguf";
398+
397399
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_CVECTOR_GENERATOR, print_usage)) {
398400
return 1;
399401
}
@@ -498,7 +500,7 @@ int main(int argc, char ** argv) {
498500
}
499501

500502
// write output vectors to gguf
501-
export_gguf(ctx_train.v_final, params.cvector_outfile, model_hint);
503+
export_gguf(ctx_train.v_final, params.out_file, model_hint);
502504

503505
llama_backend_free();
504506

examples/export-lora/export-lora.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -413,20 +413,22 @@ static void print_usage(int, char ** argv) {
413413
int main(int argc, char ** argv) {
414414
common_params params;
415415

416+
params.out_file = "ggml-lora-merged-f16.gguf";
417+
416418
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_EXPORT_LORA, print_usage)) {
417419
return 1;
418420
}
419421

420422
g_verbose = (params.verbosity > 1);
421423
try {
422-
lora_merge_ctx ctx(params.model, params.lora_adapters, params.lora_outfile, params.cpuparams.n_threads);
424+
lora_merge_ctx ctx(params.model, params.lora_adapters, params.out_file, params.cpuparams.n_threads);
423425
ctx.run_merge();
424426
} catch (const std::exception & err) {
425427
fprintf(stderr, "%s\n", err.what());
426428
exit(EXIT_FAILURE);
427429
}
428430

429-
printf("done, output file is %s\n", params.lora_outfile.c_str());
431+
printf("done, output file is %s\n", params.out_file.c_str());
430432

431433
return 0;
432434
}

examples/imatrix/imatrix.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,6 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor * t, bool ask, void *
206206

207207
void IMatrixCollector::save_imatrix(int ncall) const {
208208
auto fname = m_params.out_file;
209-
if (fname.empty()) {
210-
fname = "imatrix.dat";
211-
}
212209

213210
if (ncall > 0) {
214211
fname += ".at_";
@@ -583,6 +580,8 @@ static bool compute_imatrix(llama_context * ctx, const common_params & params) {
583580
int main(int argc, char ** argv) {
584581
common_params params;
585582

583+
params.out_file = "imatrix.dat" ;
584+
586585
params.n_ctx = 512;
587586
params.logits_all = true;
588587
params.escape = false;

0 commit comments

Comments
 (0)