Skip to content

Commit 154eb77

Browse files
committed
Warn user if imatrix will get overwritten
1 parent 8e3468b commit 154eb77

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

examples/cli/main.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,16 @@ bool parse_options(int argc, const char** argv, ArgOptions& options) {
376376
return true;
377377
}
378378

379+
int file_exists(const char *path) {
380+
FILE *file;
381+
if ((file = fopen(path, "r"))) {
382+
fclose(file);
383+
return 1;
384+
}
385+
return 0;
386+
}
387+
388+
379389
void parse_args(int argc, const char** argv, SDParams& params) {
380390
ArgOptions options;
381391
options.string_options = {
@@ -663,6 +673,14 @@ void parse_args(int argc, const char** argv, SDParams& params) {
663673
if (!isfinite(params.img_cfg_scale)) {
664674
params.img_cfg_scale = params.cfg_scale;
665675
}
676+
677+
if (params.imatrix_out.size() > 0 && file_exists(params.imatrix_out.c_str())) {
678+
// imatrix file already exists
679+
if (std::find(params.imatrix_in.begin(), params.imatrix_in.end(), params.imatrix_out) == params.imatrix_in.end()) {
680+
printf("\n IMPORTANT: imatrix file %s already exists, but wasn't found in the imatrix inputs.\n", params.imatrix_out.c_str());
681+
printf("%s will get overwritten!\n", params.imatrix_out.c_str());
682+
}
683+
}
666684
}
667685

668686
static std::string sd_basename(const std::string& path) {

stable-diffusion.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ SD_API void free_upscaler_ctx(upscaler_ctx_t* upscaler_ctx);
243243

244244
SD_API sd_image_t upscale(upscaler_ctx_t* upscaler_ctx, sd_image_t input_image, uint32_t upscale_factor);
245245

246+
SD_API void setConvertImatrixCollector(void * collector);
246247
SD_API bool convert(const char* model_path, const char* clip_l_path, const char* clip_g_path, const char* t5xxl_path, const char* diffusion_model_path,
247248
const char* vae_path,
248249
const char* output_path,

0 commit comments

Comments
 (0)