summaryrefslogtreecommitdiff
path: root/llama.cpp
diff options
context:
space:
mode:
authorXuan Son Nguyen <thichthat@gmail.com>2024-04-28 17:36:18 +0200
committerGitHub <noreply@github.com>2024-04-28 17:36:18 +0200
commit7bb36ccf91b8a2e92b182dd75624f1fd7cb205ac (patch)
treeab92b14895245a23730553dc06af68e75995c69c /llama.cpp
parentce023f6f2ff34fbe840e32e65d443d2fed7393de (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 'llama.cpp')
-rw-r--r--llama.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llama.cpp b/llama.cpp
index 49f2b559..3c64622d 100644
--- a/llama.cpp
+++ b/llama.cpp
@@ -3120,9 +3120,17 @@ struct llama_model_loader {
fver = (enum llama_fver) gguf_get_version(meta);
+ std::set<std::string> tensor_names;
for (auto & w : weights) {
n_elements += ggml_nelements(w.tensor);
n_bytes += ggml_nbytes(w.tensor);
+ // make sure there is no duplicated tensor names
+ const std::string name(w.tensor->name);
+ auto found = tensor_names.find(name);
+ if (found != tensor_names.end()) {
+ throw std::runtime_error(format("invalid model: tensor '%s' is duplicated", w.tensor->name));
+ }
+ tensor_names.insert(name);
}
LLAMA_LOG_INFO("%s: loaded meta data with %d key-value pairs and %d tensors from %s (version %s)\n",