Skip to content

Commit 9148b98

Browse files
authoredNov 30, 2024··
feat: remove type restrictions (#489)
1 parent 7ce63e7 commit 9148b98

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed
 

‎examples/cli/main.cpp

+25-25
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void print_usage(int argc, const char* argv[]) {
196196
printf(" --normalize-input normalize PHOTOMAKER input id images\n");
197197
printf(" --upscale-model [ESRGAN_PATH] path to esrgan model. Upscale images after generate, just RealESRGAN_x4plus_anime_6B supported by now\n");
198198
printf(" --upscale-repeats Run the ESRGAN upscaler this many times (default 1)\n");
199-
printf(" --type [TYPE] weight type (f32, f16, q4_0, q4_1, q5_0, q5_1, q8_0, q2_k, q3_k, q4_k)\n");
199+
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");
200200
printf(" If not specified, the default is the type of the weight file\n");
201201
printf(" --lora-model-dir [DIR] lora model directory\n");
202202
printf(" -i, --init-img [IMAGE] path to the input image, required by img2img\n");
@@ -346,30 +346,30 @@ void parse_args(int argc, const char** argv, SDParams& params) {
346346
invalid_arg = true;
347347
break;
348348
}
349-
std::string type = argv[i];
350-
if (type == "f32") {
351-
params.wtype = SD_TYPE_F32;
352-
} else if (type == "f16") {
353-
params.wtype = SD_TYPE_F16;
354-
} else if (type == "q4_0") {
355-
params.wtype = SD_TYPE_Q4_0;
356-
} else if (type == "q4_1") {
357-
params.wtype = SD_TYPE_Q4_1;
358-
} else if (type == "q5_0") {
359-
params.wtype = SD_TYPE_Q5_0;
360-
} else if (type == "q5_1") {
361-
params.wtype = SD_TYPE_Q5_1;
362-
} else if (type == "q8_0") {
363-
params.wtype = SD_TYPE_Q8_0;
364-
} else if (type == "q2_k") {
365-
params.wtype = SD_TYPE_Q2_K;
366-
} else if (type == "q3_k") {
367-
params.wtype = SD_TYPE_Q3_K;
368-
} else if (type == "q4_k") {
369-
params.wtype = SD_TYPE_Q4_K;
370-
} else {
371-
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",
372-
type.c_str());
349+
std::string type = argv[i];
350+
bool found = false;
351+
std::string valid_types = "";
352+
for (size_t i = 0; i < SD_TYPE_COUNT; i++) {
353+
auto trait = ggml_get_type_traits((ggml_type)i);
354+
std::string name(trait->type_name);
355+
if (name == "f32" || trait->to_float && trait->type_size) {
356+
if (i)
357+
valid_types += ", ";
358+
valid_types += name;
359+
if (type == name) {
360+
if (ggml_quantize_requires_imatrix((ggml_type)i)) {
361+
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);
362+
}
363+
params.wtype = (enum sd_type_t)i;
364+
found = true;
365+
break;
366+
}
367+
}
368+
}
369+
if (!found) {
370+
fprintf(stderr, "error: invalid weight format %s, must be one of [%s]\n",
371+
type.c_str(),
372+
valid_types.c_str());
373373
exit(1);
374374
}
375375
} else if (arg == "--lora-model-dir") {

0 commit comments

Comments
 (0)
Please sign in to comment.