22
22
static void print_usage (int , char ** argv) {
23
23
LOG (" \n example usage:\n " );
24
24
LOG (" \n %s \\\n "
25
- " -m model.gguf -f some-text.txt [-o imatrix.dat] [--process-output] [--verbosity 1] \\\n "
25
+ " -m model.gguf -f some-text.txt [-o imatrix.dat] [--process-output] \\\n "
26
26
" [--no-ppl] [--chunk 123] [--output-frequency 10] [--save-frequency 0] \\\n "
27
27
" [--in-file imatrix-prev-0.dat --in-file imatrix-prev-1.dat ...]\n " , argv[0 ]);
28
28
LOG (" \n " );
@@ -129,9 +129,7 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor * t, bool ask, void *
129
129
LOG_ERR (" %s: inconsistent size for %s (%d vs %d)\n " , __func__, wname.c_str (), (int )e.values .size (), (int )src1->ne [0 ]*n_as);
130
130
exit (1 ); // GGML_ABORT("fatal error");
131
131
}
132
- if (m_params.verbosity > 1 ) {
133
- printf (" %s[%d]: %32s, %s, %5d x %5d, %d\n " , __func__, m_last_call, wname.c_str (), ggml_op_name (t->op ), (int )src1->ne [0 ], (int )src1->ne [2 ], (int )src1->type );
134
- }
132
+ LOG_DBGV (2 , " %s[%d]: %32s, %s, %5d x %5d, %d\n " , __func__, m_last_call, wname.c_str (), ggml_op_name (t->op ), (int )src1->ne [0 ], (int )src1->ne [2 ], (int )src1->type );
135
133
// loop over all possible experts, regardless if they are used or not in the batch
136
134
for (int ex = 0 ; ex < n_as; ++ex) {
137
135
size_t e_start = ex*src1->ne [0 ];
@@ -180,9 +178,7 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor * t, bool ask, void *
180
178
exit (1 ); // GGML_ABORT("fatal error");
181
179
}
182
180
++e.ncall ;
183
- if (m_params.verbosity > 1 ) {
184
- LOG (" %s[%d]: %32s, %s, %5d x %5d, %d\n " , __func__, m_last_call, wname.c_str (), ggml_op_name (t->op ), (int )src1->ne [0 ], (int )src1->ne [1 ], (int )src1->type );
185
- }
181
+ LOG_DBGV (2 , " %s[%d]: %32s, %s, %5d x %5d, %d\n " , __func__, m_last_call, wname.c_str (), ggml_op_name (t->op ), (int )src1->ne [0 ], (int )src1->ne [1 ], (int )src1->type );
186
182
for (int row = 0 ; row < (int )src1->ne [1 ]; ++row) {
187
183
const float * x = data + row * src1->ne [0 ];
188
184
for (int j = 0 ; j < (int )src1->ne [0 ]; ++j) {
@@ -292,29 +288,28 @@ void IMatrixCollector::save_imatrix(int ncall) const {
292
288
out.write (m_params.prompt_file .c_str (), len);
293
289
}
294
290
295
- if (m_params.verbosity > 0 ) {
296
- LOG_INF (" \n %s: stored collected data after %d chunks in %s\n " , __func__, m_last_call, fname.c_str ());
297
- }
291
+ LOGV (1 , " \n " );
292
+ LOG_DBGV (1 , " %s: stored collected data after %d chunks in %s\n " , __func__, m_last_call, fname.c_str ());
298
293
}
299
294
300
295
bool IMatrixCollector::load_imatrix (const char * fname) {
301
296
std::ifstream in (fname, std::ios::binary);
302
297
if (!in) {
303
- printf (" %s: failed to open %s\n " ,__func__, fname);
298
+ LOG_ERR (" %s: failed to open %s\n " ,__func__, fname);
304
299
return false ;
305
300
}
306
301
int n_entries;
307
302
in.read ((char *)&n_entries, sizeof (n_entries));
308
303
if (in.fail () || n_entries < 1 ) {
309
- printf (" %s: no data in file %s\n " , __func__, fname);
304
+ LOG_ERR (" %s: no data in file %s\n " , __func__, fname);
310
305
return false ;
311
306
}
312
307
for (int i = 0 ; i < n_entries; ++i) {
313
308
int len; in.read ((char *)&len, sizeof (len));
314
309
std::vector<char > name_as_vec (len+1 );
315
310
in.read ((char *)name_as_vec.data (), len);
316
311
if (in.fail ()) {
317
- printf (" %s: failed reading name for entry %d from %s\n " ,__func__,i+1 , fname);
312
+ LOG_ERR (" %s: failed reading name for entry %d from %s\n " ,__func__,i+1 , fname);
318
313
return false ;
319
314
}
320
315
name_as_vec[len] = 0 ;
@@ -325,7 +320,7 @@ bool IMatrixCollector::load_imatrix(const char * fname) {
325
320
int nval;
326
321
in.read ((char *)&nval, sizeof (nval));
327
322
if (in.fail () || nval < 1 ) {
328
- printf (" %s: failed reading number of values for entry %d\n " ,__func__,i);
323
+ LOG_ERR (" %s: failed reading number of values for entry %d\n " ,__func__,i);
329
324
m_stats = {};
330
325
return false ;
331
326
}
@@ -338,7 +333,7 @@ bool IMatrixCollector::load_imatrix(const char * fname) {
338
333
std::vector<float > tmp (nval);
339
334
in.read ((char *)tmp.data (), nval*sizeof (float ));
340
335
if (in.fail ()) {
341
- printf (" %s: failed reading data for entry %d\n " ,__func__,i);
336
+ LOG_ERR (" %s: failed reading data for entry %d\n " ,__func__,i);
342
337
m_stats = {};
343
338
return false ;
344
339
}
@@ -548,13 +543,13 @@ static bool compute_imatrix(llama_context * ctx, const gpt_params & params) {
548
543
workers, nll, nll2, logit_history.data () + start + first, prob_history.data () + start + first);
549
544
count += n_ctx - first - 1 ;
550
545
551
- printf (" [%d]%.4lf," , i + 1 , std::exp (nll / count));
546
+ LOG (" [%d]%.4lf," , i + 1 , std::exp (nll / count));
552
547
fflush (stdout);
553
548
554
549
logits.clear ();
555
550
}
556
551
}
557
- printf (" \n " );
552
+ LOG (" \n " );
558
553
559
554
if (params.compute_ppl ) {
560
555
nll2 /= count;
@@ -563,9 +558,9 @@ static bool compute_imatrix(llama_context * ctx, const gpt_params & params) {
563
558
nll2 -= nll * nll;
564
559
if (nll2 > 0 ) {
565
560
nll2 = sqrt (nll2/(count-1 ));
566
- printf (" Final estimate: PPL = %.4lf +/- %.5lf\n " , ppl, nll2*ppl);
561
+ LOG (" Final estimate: PPL = %.4lf +/- %.5lf\n " , ppl, nll2*ppl);
567
562
} else {
568
- printf (" Unexpected negative standard deviation of log(prob)\n " );
563
+ LOG (" Unexpected negative standard deviation of log(prob)\n " );
569
564
}
570
565
}
571
566
@@ -577,7 +572,6 @@ int main(int argc, char ** argv) {
577
572
578
573
params.n_ctx = 512 ;
579
574
params.logits_all = true ;
580
- params.verbosity = 1 ;
581
575
582
576
if (!gpt_params_parse (argc, argv, params, LLAMA_EXAMPLE_IMATRIX, print_usage)) {
583
577
return 1 ;
@@ -590,15 +584,15 @@ int main(int argc, char ** argv) {
590
584
g_collector.set_params (params);
591
585
592
586
for (const auto & in_file : params.in_files ) {
593
- printf (" %s : loading imatrix from '%s'\n " , __func__, in_file.c_str ());
587
+ LOG_INF (" %s : loading imatrix from '%s'\n " , __func__, in_file.c_str ());
594
588
if (!g_collector.load_imatrix (in_file.c_str ())) {
595
589
LOG_ERR (" %s : failed to load %s\n " , __func__, in_file.c_str ());
596
590
return 1 ;
597
591
}
598
592
}
599
593
600
594
if (params.in_files .size () > 1 ) {
601
- printf (" %s : saving combined imatrix to '%s'\n " , __func__, params.out_file .c_str ());
595
+ LOG_INF (" %s : saving combined imatrix to '%s'\n " , __func__, params.out_file .c_str ());
602
596
g_collector.save_imatrix ();
603
597
}
604
598
0 commit comments