From fdc466e447a35ffe0f6e822fd9f7c8e262fa24e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20du=20Hamel?= Date: Thu, 28 Nov 2024 12:56:37 +0100 Subject: [PATCH 1/4] cli: allow any wtype --- examples/cli/main.cpp | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/examples/cli/main.cpp b/examples/cli/main.cpp index 59b325504..d401cfb67 100644 --- a/examples/cli/main.cpp +++ b/examples/cli/main.cpp @@ -346,30 +346,25 @@ void parse_args(int argc, const char** argv, SDParams& params) { invalid_arg = true; break; } - std::string type = argv[i]; - if (type == "f32") { - params.wtype = SD_TYPE_F32; - } else if (type == "f16") { - params.wtype = SD_TYPE_F16; - } else if (type == "q4_0") { - params.wtype = SD_TYPE_Q4_0; - } else if (type == "q4_1") { - params.wtype = SD_TYPE_Q4_1; - } else if (type == "q5_0") { - params.wtype = SD_TYPE_Q5_0; - } else if (type == "q5_1") { - params.wtype = SD_TYPE_Q5_1; - } else if (type == "q8_0") { - params.wtype = SD_TYPE_Q8_0; - } else if (type == "q2_k") { - params.wtype = SD_TYPE_Q2_K; - } else if (type == "q3_k") { - params.wtype = SD_TYPE_Q3_K; - } else if (type == "q4_k") { - params.wtype = SD_TYPE_Q4_K; - } else { - fprintf(stderr, "error: invalid weight format %s, must be one of [f32, f16, q4_0, q4_1, q5_0, q5_1, q8_0, q2_k, q3_k, q4_k]\n", - type.c_str()); + std::string type = argv[i]; + bool found = false; + std::string valid_types = ""; + for (size_t i = 0; i < SD_TYPE_COUNT; i++) { + auto trait = ggml_get_type_traits((ggml_type)i); + std::string name(trait->type_name); + if (i) + valid_types += ", "; + valid_types += name; + if (type == name) { + params.wtype = (enum sd_type_t)i; + found = true; + break; + } + } + if (!found) { + fprintf(stderr, "error: invalid weight format %s, must be one of [%s]\n", + type.c_str(), + valid_types.c_str()); exit(1); } } else if (arg == "--lora-model-dir") { From d1392d64f4a9985ed57b6126f7d9282388045e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20du=20Hamel?= Date: Thu, 28 Nov 2024 15:08:12 +0100 Subject: [PATCH 2/4] cli: ignore deprecated types --- examples/cli/main.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/cli/main.cpp b/examples/cli/main.cpp index d401cfb67..4e06bd15d 100644 --- a/examples/cli/main.cpp +++ b/examples/cli/main.cpp @@ -196,7 +196,7 @@ void print_usage(int argc, const char* argv[]) { printf(" --normalize-input normalize PHOTOMAKER input id images\n"); printf(" --upscale-model [ESRGAN_PATH] path to esrgan model. Upscale images after generate, just RealESRGAN_x4plus_anime_6B supported by now\n"); printf(" --upscale-repeats Run the ESRGAN upscaler this many times (default 1)\n"); - printf(" --type [TYPE] weight type (f32, f16, q4_0, q4_1, q5_0, q5_1, q8_0, q2_k, q3_k, q4_k)\n"); + printf(" --type [TYPE] weight type (examples: f32, f16, q4_0, q4_1, q5_0, q5_1, q8_0, q2_k, q3_k, q4_k)\n"); printf(" If not specified, the default is the type of the weight file\n"); printf(" --lora-model-dir [DIR] lora model directory\n"); printf(" -i, --init-img [IMAGE] path to the input image, required by img2img\n"); @@ -352,13 +352,15 @@ void parse_args(int argc, const char** argv, SDParams& params) { for (size_t i = 0; i < SD_TYPE_COUNT; i++) { auto trait = ggml_get_type_traits((ggml_type)i); std::string name(trait->type_name); - if (i) - valid_types += ", "; - valid_types += name; - if (type == name) { - params.wtype = (enum sd_type_t)i; - found = true; - break; + if (trait->type_size) { + if (i) + valid_types += ", "; + valid_types += name; + if (type == name) { + params.wtype = (enum sd_type_t)i; + found = true; + break; + } } } if (!found) { From f52e9c5e29a4ddeaee42cebcc071984aaae2e8da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20du=20Hamel?= Date: Thu, 28 Nov 2024 15:30:54 +0100 Subject: [PATCH 3/4] cli: capitalize "K" in K quants names --- examples/cli/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/cli/main.cpp b/examples/cli/main.cpp index 4e06bd15d..49394b93d 100644 --- a/examples/cli/main.cpp +++ b/examples/cli/main.cpp @@ -196,7 +196,7 @@ void print_usage(int argc, const char* argv[]) { printf(" --normalize-input normalize PHOTOMAKER input id images\n"); printf(" --upscale-model [ESRGAN_PATH] path to esrgan model. Upscale images after generate, just RealESRGAN_x4plus_anime_6B supported by now\n"); printf(" --upscale-repeats Run the ESRGAN upscaler this many times (default 1)\n"); - printf(" --type [TYPE] weight type (examples: f32, f16, q4_0, q4_1, q5_0, q5_1, q8_0, q2_k, q3_k, q4_k)\n"); + printf(" --type [TYPE] weight type (examples: f32, f16, q4_0, q4_1, q5_0, q5_1, q8_0, q2_K, q3_K, q4_K)\n"); printf(" If not specified, the default is the type of the weight file\n"); printf(" --lora-model-dir [DIR] lora model directory\n"); printf(" -i, --init-img [IMAGE] path to the input image, required by img2img\n"); From d24116a50dc8a7d541eb673093e9a8f7ce3b6093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20du=20Hamel?= Date: Thu, 28 Nov 2024 17:07:31 +0100 Subject: [PATCH 4/4] cli: ignore internal (invalid) types --- examples/cli/main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/cli/main.cpp b/examples/cli/main.cpp index 49394b93d..9552a2d31 100644 --- a/examples/cli/main.cpp +++ b/examples/cli/main.cpp @@ -352,11 +352,14 @@ void parse_args(int argc, const char** argv, SDParams& params) { for (size_t i = 0; i < SD_TYPE_COUNT; i++) { auto trait = ggml_get_type_traits((ggml_type)i); std::string name(trait->type_name); - if (trait->type_size) { + if (name == "f32" || trait->to_float && trait->type_size) { if (i) valid_types += ", "; valid_types += name; if (type == name) { + if (ggml_quantize_requires_imatrix((ggml_type)i)) { + printf("\033[35;1m[WARNING]\033[0m: type %s requires imatrix to work properly. A dummy imatrix will be used, expect poor quality.\n", trait->type_name); + } params.wtype = (enum sd_type_t)i; found = true; break;