Skip to content

Commit 6b6eede

Browse files
committed
Revert "add gguf_init_from_file_ext impl"
This reverts commit d9f1d13.
1 parent 9b365e8 commit 6b6eede

File tree

1 file changed

+14
-49
lines changed

1 file changed

+14
-49
lines changed

ggml/src/gguf.cpp

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ bool gguf_read_emplace_helper(const struct gguf_reader & gr, std::vector<struct
316316
return true;
317317
}
318318

319-
static struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_params params, tensor_shape_read_cb_t on_tensor_shape_read) {
319+
struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_params params) {
320320
const struct gguf_reader gr(file);
321321
struct gguf_context * ctx = new gguf_context;
322322

@@ -525,52 +525,25 @@ static struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_i
525525
{
526526
uint32_t n_dims = -1;
527527
ok = ok && gr.read(n_dims);
528-
529-
std::vector<int64_t> ne(n_dims);
530-
for (uint32_t j = 0; ok && j < n_dims; ++j) {
531-
ne[j] = 1;
528+
if (n_dims > GGML_MAX_DIMS) {
529+
GGML_LOG_ERROR("%s: tensor '%s' has invalid number of dimensions: %" PRIu32 " > %" PRIu32 "\n",
530+
__func__, info.t.name, n_dims, GGML_MAX_DIMS);
531+
ok = false;
532+
break;
533+
}
534+
for (uint32_t j = 0; ok && j < GGML_MAX_DIMS; ++j) {
535+
info.t.ne[j] = 1;
532536
if (j < n_dims) {
533-
ok = ok && gr.read(ne[j]);
537+
ok = ok && gr.read(info.t.ne[j]);
534538
}
535539

536540
// check that all ne are non-negative
537-
if (ne[j] < 0) {
541+
if (info.t.ne[j] < 0) {
538542
GGML_LOG_ERROR("%s: tensor '%s' dimension %" PRIu32 " has invalid number of elements: %" PRIi64 " < 0\n",
539-
__func__, info.t.name, j, ne[j]);
540-
ok = false;
541-
break;
542-
}
543-
}
544-
545-
if (!ok) {
546-
break;
547-
}
548-
549-
if (on_tensor_shape_read) {
550-
gguf_tensor_shape shape;
551-
ok = on_tensor_shape_read(ne.data(), n_dims, &shape);
552-
if (!ok) {
553-
GGML_LOG_ERROR("%s: tensor '%s' on_tensor_shape_read return false \n",
554-
__func__, info.t.name);
555-
break;
556-
}
557-
for (uint32_t j = 0; j < GGML_MAX_DIMS; ++j) {
558-
info.t.ne[j] = shape.ne[j];
559-
}
560-
} else {
561-
if (n_dims > GGML_MAX_DIMS) {
562-
GGML_LOG_ERROR("%s: tensor '%s' has invalid number of dimensions: %" PRIu32 " > %" PRIu32 "\n",
563-
__func__, info.t.name, n_dims, GGML_MAX_DIMS);
543+
__func__, info.t.name, j, info.t.ne[j]);
564544
ok = false;
565545
break;
566546
}
567-
for (uint32_t j = 0; j < GGML_MAX_DIMS; ++j) {
568-
if (j < n_dims) {
569-
info.t.ne[j] = ne[j];
570-
} else {
571-
info.t.ne[j] = 1;
572-
}
573-
}
574547
}
575548

576549
// check that the total number of elements is representable
@@ -757,27 +730,19 @@ static struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_i
757730
return ctx;
758731
}
759732

760-
struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_params params) {
761-
return gguf_init_from_file_impl(file, params, nullptr);
762-
}
763-
764-
struct gguf_context * gguf_init_from_file_ext(const char * fname, struct gguf_init_params params, tensor_shape_read_cb_t on_tensor_shape_read) {
733+
struct gguf_context * gguf_init_from_file(const char * fname, struct gguf_init_params params) {
765734
FILE * file = ggml_fopen(fname, "rb");
766735

767736
if (!file) {
768737
GGML_LOG_ERROR("%s: failed to open GGUF file '%s'\n", __func__, fname);
769738
return nullptr;
770739
}
771740

772-
struct gguf_context * result = gguf_init_from_file_impl(file, params, on_tensor_shape_read);
741+
struct gguf_context * result = gguf_init_from_file_impl(file, params);
773742
fclose(file);
774743
return result;
775744
}
776745

777-
struct gguf_context * gguf_init_from_file(const char * fname, struct gguf_init_params params) {
778-
return gguf_init_from_file_ext(fname, params, NULL);;
779-
}
780-
781746
void gguf_free(struct gguf_context * ctx) {
782747
if (ctx == nullptr) {
783748
return;

0 commit comments

Comments
 (0)