Skip to content

Commit ca5b196

Browse files
authored
feat: do not convert tensor names by default in convert mode (#1122)
1 parent 50ff966 commit ca5b196

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

examples/cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CLI Options:
99
--preview-interval <int> interval in denoising steps between consecutive updates of the image preview file (default is 1, meaning updating at
1010
every step)
1111
--canny apply canny preprocessor (edge detection)
12+
--convert-name convert tensor name (for convert mode)
1213
-v, --verbose print extra info
1314
--color colors the logging tags according to level
1415
--taesd-preview-only prevents usage of taesd for decoding the final image. (for use with --preview tae)

examples/cli/main.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct SDCliParams {
3232

3333
bool verbose = false;
3434
bool canny_preprocess = false;
35+
bool convert_name = false;
3536

3637
preview_t preview_method = PREVIEW_NONE;
3738
int preview_interval = 1;
@@ -69,6 +70,10 @@ struct SDCliParams {
6970
"--canny",
7071
"apply canny preprocessor (edge detection)",
7172
true, &canny_preprocess},
73+
{"",
74+
"--convert-name",
75+
"convert tensor name (for convert mode)",
76+
true, &canny_preprocess},
7277
{"-v",
7378
"--verbose",
7479
"print extra info",
@@ -174,6 +179,7 @@ struct SDCliParams {
174179
<< " verbose: " << (verbose ? "true" : "false") << ",\n"
175180
<< " color: " << (color ? "true" : "false") << ",\n"
176181
<< " canny_preprocess: " << (canny_preprocess ? "true" : "false") << ",\n"
182+
<< " convert_name: " << (convert_name ? "true" : "false") << ",\n"
177183
<< " preview_method: " << previews_str[preview_method] << ",\n"
178184
<< " preview_interval: " << preview_interval << ",\n"
179185
<< " preview_path: \"" << preview_path << "\",\n"
@@ -387,7 +393,8 @@ int main(int argc, const char* argv[]) {
387393
ctx_params.vae_path.c_str(),
388394
cli_params.output_path.c_str(),
389395
ctx_params.wtype,
390-
ctx_params.tensor_type_rules.c_str());
396+
ctx_params.tensor_type_rules.c_str(),
397+
cli_params.convert_name);
391398
if (!success) {
392399
LOG_ERROR("convert '%s'/'%s' to '%s' failed",
393400
ctx_params.model_path.c_str(),

model.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,7 +1783,12 @@ int64_t ModelLoader::get_params_mem_size(ggml_backend_t backend, ggml_type type)
17831783
return mem_size;
17841784
}
17851785

1786-
bool convert(const char* input_path, const char* vae_path, const char* output_path, sd_type_t output_type, const char* tensor_type_rules) {
1786+
bool convert(const char* input_path,
1787+
const char* vae_path,
1788+
const char* output_path,
1789+
sd_type_t output_type,
1790+
const char* tensor_type_rules,
1791+
bool convert_name) {
17871792
ModelLoader model_loader;
17881793

17891794
if (!model_loader.init_from_file(input_path)) {
@@ -1797,7 +1802,9 @@ bool convert(const char* input_path, const char* vae_path, const char* output_pa
17971802
return false;
17981803
}
17991804
}
1800-
model_loader.convert_tensors_name();
1805+
if (convert_name) {
1806+
model_loader.convert_tensors_name();
1807+
}
18011808
bool success = model_loader.save_to_gguf_file(output_path, (ggml_type)output_type, tensor_type_rules);
18021809
return success;
18031810
}

stable-diffusion.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ SD_API bool convert(const char* input_path,
365365
const char* vae_path,
366366
const char* output_path,
367367
enum sd_type_t output_type,
368-
const char* tensor_type_rules);
368+
const char* tensor_type_rules,
369+
bool convert_name);
369370

370371
SD_API bool preprocess_canny(sd_image_t image,
371372
float high_threshold,

0 commit comments

Comments
 (0)