Skip to content

Commit

Permalink
Model: Warn user if wrong model type option is used
Browse files Browse the repository at this point in the history
  • Loading branch information
stduhpf committed Oct 7, 2024
1 parent 14206fd commit 0f71589
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,11 +820,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);
Expand Down Expand Up @@ -903,6 +912,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();
Expand Down Expand Up @@ -953,6 +963,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();

Expand Down Expand Up @@ -1332,6 +1350,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);
void* pkl_data = NULL;
Expand Down

0 comments on commit 0f71589

Please sign in to comment.