@@ -299,10 +299,10 @@ bool gguf_read_emplace_helper(const struct gguf_reader & gr, std::vector<struct
299
299
return false ;
300
300
}
301
301
} catch (std::length_error &) {
302
- fprintf (stderr, " %s: encountered length_error while reading value for key '%s'\n " , __func__, key.c_str ());
302
+ GGML_LOG_ERROR ( " %s: encountered length_error while reading value for key '%s'\n " , __func__, key.c_str ());
303
303
return false ;
304
304
} catch (std::bad_alloc &) {
305
- fprintf (stderr, " %s: encountered bad_alloc error while reading value for key '%s'\n " , __func__, key.c_str ());
305
+ GGML_LOG_ERROR ( " %s: encountered bad_alloc error while reading value for key '%s'\n " , __func__, key.c_str ());
306
306
return false ;
307
307
}
308
308
kv.emplace_back (key, value);
@@ -328,14 +328,14 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
328
328
ok = ok && gr.read (magic, 4 );
329
329
330
330
if (!ok) {
331
- fprintf (stderr, " %s: failed to read magic\n " , __func__);
331
+ GGML_LOG_ERROR ( " %s: failed to read magic\n " , __func__);
332
332
gguf_free (ctx);
333
333
return nullptr ;
334
334
}
335
335
336
336
for (uint32_t i = 0 ; i < magic.size (); i++) {
337
337
if (magic[i] != GGUF_MAGIC[i]) {
338
- fprintf (stderr, " %s: invalid magic characters: '%c%c%c%c', expected 'GGUF'\n " , __func__, magic[0 ], magic[1 ], magic[2 ], magic[3 ]);
338
+ GGML_LOG_ERROR ( " %s: invalid magic characters: '%c%c%c%c', expected 'GGUF'\n " , __func__, magic[0 ], magic[1 ], magic[2 ], magic[3 ]);
339
339
gguf_free (ctx);
340
340
return nullptr ;
341
341
}
@@ -348,11 +348,11 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
348
348
349
349
if (ok && gr.read (ctx->version )) {
350
350
if (ctx->version == 1 ) {
351
- fprintf (stderr, " %s: GGUFv1 is no longer supported, please use a more up-to-date version\n " , __func__);
351
+ GGML_LOG_ERROR ( " %s: GGUFv1 is no longer supported, please use a more up-to-date version\n " , __func__);
352
352
ok = false ;
353
353
}
354
354
if (ctx->version > GGUF_VERSION) {
355
- fprintf (stderr, " %s: this GGUF file is version %" PRIu32 " but this software only supports up to version %d\n " ,
355
+ GGML_LOG_ERROR ( " %s: this GGUF file is version %" PRIu32 " but this software only supports up to version %d\n " ,
356
356
__func__, ctx->version , GGUF_VERSION);
357
357
ok = false ;
358
358
}
@@ -363,7 +363,7 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
363
363
if (ok && gr.read (n_tensors)) {
364
364
static_assert (sizeof (size_t ) <= 8 && sizeof (gguf_tensor_info) >= 2 , " int64_t insufficient for indexing" );
365
365
if (n_tensors < 0 || n_tensors > int64_t (SIZE_MAX/sizeof (gguf_tensor_info))) {
366
- fprintf (stderr, " %s: number of tensors is %" PRIi64 " but must be in [0, %zu]\n " ,
366
+ GGML_LOG_ERROR ( " %s: number of tensors is %" PRIi64 " but must be in [0, %zu]\n " ,
367
367
__func__, n_tensors, SIZE_MAX/sizeof (gguf_tensor_info));
368
368
ok = false ;
369
369
}
@@ -374,7 +374,7 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
374
374
if (ok && gr.read (n_kv)) {
375
375
static_assert (sizeof (size_t ) <= 8 && sizeof (gguf_tensor_info) >= 2 , " int64_t insufficient for indexing" );
376
376
if (n_kv < 0 || n_kv > int64_t (SIZE_MAX/sizeof (gguf_kv))) {
377
- fprintf (stderr, " %s: number of key value pairs is %" PRIi64 " but must be in [0, %zu]\n " ,
377
+ GGML_LOG_ERROR ( " %s: number of key value pairs is %" PRIi64 " but must be in [0, %zu]\n " ,
378
378
__func__, n_kv, SIZE_MAX/sizeof (gguf_kv));
379
379
ok = false ;
380
380
}
@@ -383,7 +383,7 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
383
383
}
384
384
385
385
if (!ok) {
386
- fprintf (stderr, " %s: failed to read header\n " , __func__);
386
+ GGML_LOG_ERROR ( " %s: failed to read header\n " , __func__);
387
387
gguf_free (ctx);
388
388
return nullptr ;
389
389
}
@@ -399,15 +399,15 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
399
399
try {
400
400
ok = ok && gr.read (key);
401
401
} catch (std::length_error &) {
402
- fprintf (stderr, " %s: encountered length_error while reading key %" PRIi64 " \n " , __func__, i);
402
+ GGML_LOG_ERROR ( " %s: encountered length_error while reading key %" PRIi64 " \n " , __func__, i);
403
403
ok = false ;
404
404
} catch (std::bad_alloc &) {
405
- fprintf (stderr, " %s: encountered bad_alloc error while reading key %" PRIi64 " \n " , __func__, i);
405
+ GGML_LOG_ERROR ( " %s: encountered bad_alloc error while reading key %" PRIi64 " \n " , __func__, i);
406
406
ok = false ;
407
407
}
408
408
for (size_t j = 0 ; ok && j < ctx->kv .size (); ++j) {
409
409
if (key == ctx->kv [j].key ) {
410
- fprintf (stderr, " %s: duplicate key '%s' for tensors %zu and %" PRIi64 " \n " , __func__, key.c_str (), j, i);
410
+ GGML_LOG_ERROR ( " %s: duplicate key '%s' for tensors %zu and %" PRIi64 " \n " , __func__, key.c_str (), j, i);
411
411
ok = false ;
412
412
}
413
413
}
@@ -441,14 +441,14 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
441
441
case GGUF_TYPE_ARRAY:
442
442
default :
443
443
{
444
- fprintf (stderr, " %s: key '%s' has invalid GGUF type %d\n " , __func__, key.c_str (), type);
444
+ GGML_LOG_ERROR ( " %s: key '%s' has invalid GGUF type %d\n " , __func__, key.c_str (), type);
445
445
ok = false ;
446
446
} break ;
447
447
}
448
448
}
449
449
450
450
if (!ok) {
451
- fprintf (stderr, " %s: failed to read key-value pairs\n " , __func__);
451
+ GGML_LOG_ERROR ( " %s: failed to read key-value pairs\n " , __func__);
452
452
gguf_free (ctx);
453
453
return nullptr ;
454
454
}
@@ -458,7 +458,7 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
458
458
ctx->alignment = alignment_idx == -1 ? GGUF_DEFAULT_ALIGNMENT : gguf_get_val_u32 (ctx, alignment_idx);
459
459
460
460
if (ctx->alignment == 0 || (ctx->alignment & (ctx->alignment - 1 )) != 0 ) {
461
- fprintf (stderr, " %s: alignment %zu is not a power of 2\n " , __func__, ctx->alignment );
461
+ GGML_LOG_ERROR ( " %s: alignment %zu is not a power of 2\n " , __func__, ctx->alignment );
462
462
gguf_free (ctx);
463
463
return nullptr ;
464
464
}
@@ -474,14 +474,14 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
474
474
try {
475
475
ok = ok && gr.read (name);
476
476
} catch (std::length_error &) {
477
- fprintf (stderr, " %s: encountered length_error while reading tensor name %" PRIi64 " \n " , __func__, i);
477
+ GGML_LOG_ERROR ( " %s: encountered length_error while reading tensor name %" PRIi64 " \n " , __func__, i);
478
478
ok = false ;
479
479
} catch (std::bad_alloc &) {
480
- fprintf (stderr, " %s: encountered bad_alloc error while reading tensor name %" PRIi64 " \n " , __func__, i);
480
+ GGML_LOG_ERROR ( " %s: encountered bad_alloc error while reading tensor name %" PRIi64 " \n " , __func__, i);
481
481
ok = false ;
482
482
}
483
483
if (name.length () >= GGML_MAX_NAME) {
484
- fprintf (stderr, " %s: tensor name %" PRIi64 " is too long: %zu >= %d\n " , __func__, i, name.length (), GGML_MAX_NAME);
484
+ GGML_LOG_ERROR ( " %s: tensor name %" PRIi64 " is too long: %zu >= %d\n " , __func__, i, name.length (), GGML_MAX_NAME);
485
485
ok = false ;
486
486
break ;
487
487
}
@@ -490,7 +490,7 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
490
490
// make sure there are no duplicate tensor names
491
491
for (int64_t j = 0 ; ok && j < i; ++j) {
492
492
if (strcmp (info.t .name , ctx->info [j].t .name ) == 0 ) {
493
- fprintf (stderr, " %s: duplicate tensor name '%s' for tensors %" PRIi64 " and %" PRIi64 " \n " , __func__, info.t .name , j, i);
493
+ GGML_LOG_ERROR ( " %s: duplicate tensor name '%s' for tensors %" PRIi64 " and %" PRIi64 " \n " , __func__, info.t .name , j, i);
494
494
ok = false ;
495
495
break ;
496
496
}
@@ -505,7 +505,7 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
505
505
uint32_t n_dims = -1 ;
506
506
ok = ok && gr.read (n_dims);
507
507
if (n_dims > GGML_MAX_DIMS) {
508
- fprintf (stderr, " %s: tensor '%s' has invalid number of dimensions: %" PRIu32 " > %" PRIu32 " \n " ,
508
+ GGML_LOG_ERROR ( " %s: tensor '%s' has invalid number of dimensions: %" PRIu32 " > %" PRIu32 " \n " ,
509
509
__func__, info.t .name , n_dims, GGML_MAX_DIMS);
510
510
ok = false ;
511
511
break ;
@@ -518,7 +518,7 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
518
518
519
519
// check that all ne are non-negative
520
520
if (info.t .ne [j] < 0 ) {
521
- fprintf (stderr, " %s: tensor '%s' dimension %" PRIu32 " has invalid number of elements: %" PRIi64 " < 0\n " ,
521
+ GGML_LOG_ERROR ( " %s: tensor '%s' dimension %" PRIu32 " has invalid number of elements: %" PRIi64 " < 0\n " ,
522
522
__func__, info.t .name , j, info.t .ne [j]);
523
523
ok = false ;
524
524
break ;
@@ -530,7 +530,7 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
530
530
(INT64_MAX/info.t .ne [2 ] <= info.t .ne [0 ]*info.t .ne [1 ]) ||
531
531
(INT64_MAX/info.t .ne [3 ] <= info.t .ne [0 ]*info.t .ne [1 ]*info.t .ne [2 ]))) {
532
532
533
- fprintf (stderr, " %s: total number of elements in tensor '%s' with shape "
533
+ GGML_LOG_ERROR ( " %s: total number of elements in tensor '%s' with shape "
534
534
" (%" PRIi64 " , %" PRIi64 " , %" PRIi64 " , %" PRIi64 " ) is >= %" PRIi64 " \n " ,
535
535
__func__, info.t .name , info.t .ne [0 ], info.t .ne [1 ], info.t .ne [2 ], info.t .ne [3 ], INT64_MAX);
536
536
ok = false ;
@@ -547,7 +547,7 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
547
547
548
548
// check that tensor type is within defined range
549
549
if (info.t .type < 0 || info.t .type >= GGML_TYPE_COUNT) {
550
- fprintf (stderr, " %s: tensor '%s' has invalid ggml type %d (%s)\n " ,
550
+ GGML_LOG_ERROR ( " %s: tensor '%s' has invalid ggml type %d (%s)\n " ,
551
551
__func__, info.t .name , info.t .type , ggml_type_name (info.t .type ));
552
552
ok = false ;
553
553
break ;
@@ -557,7 +557,7 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
557
557
558
558
// check that row size is divisible by block size
559
559
if (blck_size == 0 || info.t .ne [0 ] % blck_size != 0 ) {
560
- fprintf (stderr, " %s: tensor '%s' of type %d (%s) has %" PRId64 " elements per row, "
560
+ GGML_LOG_ERROR ( " %s: tensor '%s' of type %d (%s) has %" PRId64 " elements per row, "
561
561
" not a multiple of block size (%" PRId64 " )\n " ,
562
562
__func__, info.t .name , (int ) info.t .type , ggml_type_name (info.t .type ), info.t .ne [0 ], blck_size);
563
563
ok = false ;
@@ -582,15 +582,15 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
582
582
}
583
583
584
584
if (!ok) {
585
- fprintf (stderr, " %s: failed to read tensor info\n " , __func__);
585
+ GGML_LOG_ERROR ( " %s: failed to read tensor info\n " , __func__);
586
586
gguf_free (ctx);
587
587
return nullptr ;
588
588
}
589
589
GGML_ASSERT (int64_t (ctx->info .size ()) == n_tensors);
590
590
591
591
// we require the data section to be aligned, so take into account any padding
592
592
if (fseek (file, GGML_PAD (ftell (file), ctx->alignment ), SEEK_SET) != 0 ) {
593
- fprintf (stderr, " %s: failed to seek to beginning of data section\n " , __func__);
593
+ GGML_LOG_ERROR ( " %s: failed to seek to beginning of data section\n " , __func__);
594
594
gguf_free (ctx);
595
595
return nullptr ;
596
596
}
@@ -604,9 +604,9 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
604
604
for (size_t i = 0 ; i < ctx->info .size (); ++i) {
605
605
const gguf_tensor_info & ti = ctx->info [i];
606
606
if (ti.offset != ctx->size ) {
607
- fprintf (stderr, " %s: tensor '%s' has offset %" PRIu64 " , expected %zu\n " ,
607
+ GGML_LOG_ERROR ( " %s: tensor '%s' has offset %" PRIu64 " , expected %zu\n " ,
608
608
__func__, ti.t .name , ti.offset , ctx->size );
609
- fprintf (stderr, " %s: failed to read tensor data\n " , __func__);
609
+ GGML_LOG_ERROR ( " %s: failed to read tensor data\n " , __func__);
610
610
gguf_free (ctx);
611
611
return nullptr ;
612
612
}
@@ -634,7 +634,7 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
634
634
635
635
*params.ctx = ggml_init (pdata);
636
636
if (*params.ctx == nullptr ) {
637
- fprintf (stderr, " %s: failed to initialize ggml context for storing tensors\n " , __func__);
637
+ GGML_LOG_ERROR ( " %s: failed to initialize ggml context for storing tensors\n " , __func__);
638
638
gguf_free (ctx);
639
639
return nullptr ;
640
640
}
@@ -656,7 +656,7 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
656
656
ok = ok && gr.read (data->data , ctx->size );
657
657
658
658
if (!ok) {
659
- fprintf (stderr, " %s: failed to read tensor data binary blob\n " , __func__);
659
+ GGML_LOG_ERROR ( " %s: failed to read tensor data binary blob\n " , __func__);
660
660
ggml_free (ctx_data);
661
661
*params.ctx = nullptr ;
662
662
gguf_free (ctx);
@@ -689,7 +689,7 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
689
689
}
690
690
691
691
if (!ok) {
692
- fprintf (stderr, " %s: failed to create tensors\n " , __func__);
692
+ GGML_LOG_ERROR ( " %s: failed to create tensors\n " , __func__);
693
693
ggml_free (ctx_data);
694
694
*params.ctx = nullptr ;
695
695
gguf_free (ctx);
@@ -706,7 +706,7 @@ struct gguf_context * gguf_init_from_file(const char * fname, struct gguf_init_p
706
706
FILE * file = ggml_fopen (fname, " rb" );
707
707
708
708
if (!file) {
709
- fprintf (stderr, " %s: failed to open GGUF file '%s'\n " , __func__, fname);
709
+ GGML_LOG_ERROR ( " %s: failed to open GGUF file '%s'\n " , __func__, fname);
710
710
return nullptr ;
711
711
}
712
712
@@ -1305,7 +1305,7 @@ bool gguf_write_to_file(const struct gguf_context * ctx, const char * fname, boo
1305
1305
FILE * file = ggml_fopen (fname, " wb" );
1306
1306
1307
1307
if (!file) {
1308
- fprintf (stderr, " %s: failed to open file '%s' for writing GGUF data\n " , __func__, fname);
1308
+ GGML_LOG_ERROR ( " %s: failed to open file '%s' for writing GGUF data\n " , __func__, fname);
1309
1309
return false ;
1310
1310
}
1311
1311
0 commit comments