diff options
author | Xuan Son Nguyen <thichthat@gmail.com> | 2024-04-28 17:36:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-28 17:36:18 +0200 |
commit | 7bb36ccf91b8a2e92b182dd75624f1fd7cb205ac (patch) | |
tree | ab92b14895245a23730553dc06af68e75995c69c /ggml.c | |
parent | ce023f6f2ff34fbe840e32e65d443d2fed7393de (diff) |
gguf : enforce that tensor names are unique (#6905)
* not allow adding duplicated tensor name
* no duplicated tensor while reading gguf
* typo
* throw exception inside llama_model_loader
Co-authored-by: slaren <slarengh@gmail.com>
---------
Co-authored-by: slaren <slarengh@gmail.com>
Diffstat (limited to 'ggml.c')
-rw-r--r-- | ggml.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -20819,6 +20819,14 @@ struct gguf_context * gguf_init_from_file(const char * fname, struct gguf_init_p // TODO: return an error instead of crashing with GGML_ASSERT gguf_tensor_info_sanitize(info); + // make sure there is no duplicated tensor names + for (uint64_t j = 0; j < i; ++j) { + if (strcmp(info->name.data, ctx->infos[j].name.data) == 0) { + fprintf(stderr, "%s: duplicated tensor name %s\n", __func__, info->name.data); + ok = false; + } + } + if (!ok) { fprintf(stderr, "%s: failed to read tensor info\n", __func__); fclose(file); @@ -21355,6 +21363,10 @@ void gguf_set_kv(struct gguf_context * ctx, struct gguf_context * src) { void gguf_add_tensor( struct gguf_context * ctx, const struct ggml_tensor * tensor) { + if (gguf_find_tensor(ctx, tensor->name) != -1) { + GGML_ASSERT(false && "duplicated tensor name"); + } + const int idx = ctx->header.n_tensors; ctx->infos = realloc(ctx->infos, (idx + 1)*sizeof(struct gguf_tensor_info)); |