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>
This commit is contained in:
Xuan Son Nguyen 2024-04-28 17:36:18 +02:00 committed by GitHub
parent ce023f6f2f
commit 7bb36ccf91
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 1 deletions

View file

@ -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",