From 6ba15428ebc09c9e95951c643d10659ae32d7b9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20du=20Hamel?= Date: Tue, 8 Oct 2024 01:31:23 +0200 Subject: [PATCH 1/3] Model: Warn user if wrong model type option is used --- model.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/model.cpp b/model.cpp index dba8187d..e950e1c5 100644 --- a/model.cpp +++ b/model.cpp @@ -915,11 +915,20 @@ bool ModelLoader::init_from_gguf_file(const std::string& file_path, const std::s size_t total_size = 0; size_t data_offset = gguf_get_data_offset(ctx_gguf_); + for (int i = 0; i < n_tensors; i++) { std::string name = gguf_get_tensor_name(ctx_gguf_, i); struct ggml_tensor* dummy = ggml_get_tensor(ctx_meta_, name.c_str()); size_t offset = data_offset + gguf_get_tensor_offset(ctx_gguf_, i); + if(i==0 && starts_with(name,prefix)){ + LOG_WARN("Tensors have built-in %s prefix.\n", prefix); + if(prefix == "model.diffusion_model."){ + // the user probably used `--diffusion-model` instead of `-m` + LOG_WARN("Try using `-m`or `--model` instead of `--diffusion-model`\n"); + } + } + // LOG_DEBUG("%s", name.c_str()); TensorStorage tensor_storage(prefix + name, dummy->type, dummy->ne, ggml_n_dims(dummy), file_index, offset); @@ -1000,6 +1009,7 @@ bool ModelLoader::init_from_safetensors_file(const std::string& file_path, const nlohmann::json header_ = nlohmann::json::parse(header_buf.data()); + int i =0; for (auto& item : header_.items()) { std::string name = item.key(); nlohmann::json tensor_info = item.value(); @@ -1050,6 +1060,14 @@ bool ModelLoader::init_from_safetensors_file(const std::string& file_path, const n_dims = 1; } + if(i++==0 && starts_with(name,prefix)){ + LOG_WARN("Tensors have built-in %s prefix.\n", prefix); + if(prefix == "model.diffusion_model."){ + // the user probably used `--diffusion-model` instead of `-m` + LOG_WARN("Try using `-m`or `--model` instead of `--diffusion-model`\n"); + } + } + TensorStorage tensor_storage(prefix + name, type, ne, n_dims, file_index, ST_HEADER_SIZE_LEN + header_size_ + begin); tensor_storage.reverse_ne(); @@ -1433,6 +1451,13 @@ bool ModelLoader::init_from_ckpt_file(const std::string& file_path, const std::s { std::string name = zip_entry_name(zip); size_t pos = name.find("data.pkl"); + if(i==0 && starts_with(name,prefix)){ + LOG_WARN("Tensors have built-in %s prefix.\n", prefix); + if(prefix == "model.diffusion_model."){ + // the user probably used `--diffusion-model` instead of `-m` + LOG_WARN("Try using `-m`or `--model` instead of `--diffusion-model`\n"); + } + } if (pos != std::string::npos) { std::string dir = name.substr(0, pos); printf("ZIP %d, name = %s, dir = %s \n", i, name.c_str(), dir.c_str()); From ddb40b5550e8e6c0b6d03579bc6639aa3981c817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20du=20Hamel?= Date: Tue, 8 Oct 2024 01:36:03 +0200 Subject: [PATCH 2/3] Fix printf --- model.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/model.cpp b/model.cpp index e950e1c5..0485c4f6 100644 --- a/model.cpp +++ b/model.cpp @@ -922,7 +922,7 @@ bool ModelLoader::init_from_gguf_file(const std::string& file_path, const std::s size_t offset = data_offset + gguf_get_tensor_offset(ctx_gguf_, i); if(i==0 && starts_with(name,prefix)){ - LOG_WARN("Tensors have built-in %s prefix.\n", prefix); + LOG_WARN("Tensors have built-in %s prefix.\n", prefix.c_str()); if(prefix == "model.diffusion_model."){ // the user probably used `--diffusion-model` instead of `-m` LOG_WARN("Try using `-m`or `--model` instead of `--diffusion-model`\n"); @@ -1061,7 +1061,7 @@ bool ModelLoader::init_from_safetensors_file(const std::string& file_path, const } if(i++==0 && starts_with(name,prefix)){ - LOG_WARN("Tensors have built-in %s prefix.\n", prefix); + LOG_WARN("Tensors have built-in %s prefix.\n", prefix.c_str()); if(prefix == "model.diffusion_model."){ // the user probably used `--diffusion-model` instead of `-m` LOG_WARN("Try using `-m`or `--model` instead of `--diffusion-model`\n"); @@ -1452,7 +1452,7 @@ bool ModelLoader::init_from_ckpt_file(const std::string& file_path, const std::s std::string name = zip_entry_name(zip); size_t pos = name.find("data.pkl"); if(i==0 && starts_with(name,prefix)){ - LOG_WARN("Tensors have built-in %s prefix.\n", prefix); + LOG_WARN("Tensors have built-in %s prefix.\n", prefix.c_str()); if(prefix == "model.diffusion_model."){ // the user probably used `--diffusion-model` instead of `-m` LOG_WARN("Try using `-m`or `--model` instead of `--diffusion-model`\n"); From ec5f18f9b79b46e24b8a236da56f1afa2b98d666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20du=20Hamel?= Date: Tue, 8 Oct 2024 01:47:09 +0200 Subject: [PATCH 3/3] do not warn for empty prefix --- model.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/model.cpp b/model.cpp index 0485c4f6..2b2195ff 100644 --- a/model.cpp +++ b/model.cpp @@ -921,9 +921,9 @@ bool ModelLoader::init_from_gguf_file(const std::string& file_path, const std::s struct ggml_tensor* dummy = ggml_get_tensor(ctx_meta_, name.c_str()); size_t offset = data_offset + gguf_get_tensor_offset(ctx_gguf_, i); - if(i==0 && starts_with(name,prefix)){ - LOG_WARN("Tensors have built-in %s prefix.\n", prefix.c_str()); - if(prefix == "model.diffusion_model."){ + if (!prefix.empty() && i == 0 && starts_with(name, prefix)) { + LOG_WARN("Tensors have built-in \"%s\" prefix.\n", prefix.c_str()); + if (prefix == "model.diffusion_model.") { // the user probably used `--diffusion-model` instead of `-m` LOG_WARN("Try using `-m`or `--model` instead of `--diffusion-model`\n"); } @@ -1009,7 +1009,7 @@ bool ModelLoader::init_from_safetensors_file(const std::string& file_path, const nlohmann::json header_ = nlohmann::json::parse(header_buf.data()); - int i =0; + int i = 0; for (auto& item : header_.items()) { std::string name = item.key(); nlohmann::json tensor_info = item.value(); @@ -1060,9 +1060,9 @@ bool ModelLoader::init_from_safetensors_file(const std::string& file_path, const n_dims = 1; } - if(i++==0 && starts_with(name,prefix)){ - LOG_WARN("Tensors have built-in %s prefix.\n", prefix.c_str()); - if(prefix == "model.diffusion_model."){ + if (!prefix.empty() && i++ == 0 && starts_with(name, prefix)) { + LOG_WARN("Tensors have built-in \"%s\" prefix.\n", prefix.c_str()); + if (prefix == "model.diffusion_model.") { // the user probably used `--diffusion-model` instead of `-m` LOG_WARN("Try using `-m`or `--model` instead of `--diffusion-model`\n"); } @@ -1451,9 +1451,9 @@ bool ModelLoader::init_from_ckpt_file(const std::string& file_path, const std::s { std::string name = zip_entry_name(zip); size_t pos = name.find("data.pkl"); - if(i==0 && starts_with(name,prefix)){ - LOG_WARN("Tensors have built-in %s prefix.\n", prefix.c_str()); - if(prefix == "model.diffusion_model."){ + if (!prefix.empty() && i == 0 && starts_with(name, prefix)) { + LOG_WARN("Tensors have built-in \"%s\" prefix.\n", prefix.c_str()); + if (prefix == "model.diffusion_model.") { // the user probably used `--diffusion-model` instead of `-m` LOG_WARN("Try using `-m`or `--model` instead of `--diffusion-model`\n"); }