Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model: Warn users if diffusion-model tensors names are already prefixed #435

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (!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");
}
}

// 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 (!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");
}
}

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 (!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");
}
}
if (pos != std::string::npos) {
std::string dir = name.substr(0, pos);
void* pkl_data = NULL;
Expand Down
Loading