@@ -2271,14 +2271,15 @@ bool SDGenerationParams::from_json_str(
22712271 return true ;
22722272}
22732273
2274- void SDGenerationParams::extract_and_remove_lora (const std::string& lora_model_dir) {
2274+ bool SDGenerationParams::extract_and_remove_lora (const std::string& lora_model_dir) {
22752275 if (lora_model_dir.empty ()) {
2276- return ;
2276+ return true ;
22772277 }
22782278 static const std::regex re (R"( <lora:([^:>]+):([^>]+)>)" );
22792279 static const std::vector<std::string> valid_ext = {" .gguf" , " .safetensors" , " .pt" , " .ckpt" };
22802280 std::smatch m;
22812281
2282+ bool missing = false ;
22822283 std::string tmp = prompt;
22832284
22842285 while (std::regex_search (tmp, m, re)) {
@@ -2320,8 +2321,9 @@ void SDGenerationParams::extract_and_remove_lora(const std::string& lora_model_d
23202321 }
23212322 if (!found) {
23222323 LOG_WARN (" can not found lora %s" , final_path.lexically_normal ().string ().c_str ());
2323- tmp = m.suffix ().str ();
2324- prompt = std::regex_replace (prompt, re, " " , std::regex_constants::format_first_only);
2324+ tmp = m.suffix ().str ();
2325+ prompt = std::regex_replace (prompt, re, " " , std::regex_constants::format_first_only);
2326+ missing = true ;
23252327 continue ;
23262328 }
23272329 }
@@ -2337,6 +2339,8 @@ void SDGenerationParams::extract_and_remove_lora(const std::string& lora_model_d
23372339
23382340 tmp = m.suffix ().str ();
23392341 }
2342+
2343+ return !missing;
23402344}
23412345
23422346bool SDGenerationParams::width_and_height_are_set () const {
@@ -2458,7 +2462,7 @@ bool SDGenerationParams::initialize_cache_params() {
24582462 return true ;
24592463}
24602464
2461- bool SDGenerationParams::resolve (const std::string& lora_model_dir, const std::string& hires_upscalers_dir, bool strict) {
2465+ bool SDGenerationParams::resolve (const std::string& lora_model_dir, const std::string& hires_upscalers_dir, bool strict, bool validate_missing_loras ) {
24622466 vae_tiling_params.extra_tiling_args = extra_tiling_args.empty () ? nullptr : extra_tiling_args.c_str ();
24632467
24642468 if (high_noise_sample_params.sample_steps <= 0 ) {
@@ -2502,7 +2506,9 @@ bool SDGenerationParams::resolve(const std::string& lora_model_dir, const std::s
25022506
25032507 prompt_with_lora = prompt;
25042508 if (!lora_model_dir.empty ()) {
2505- extract_and_remove_lora (lora_model_dir);
2509+ if (!extract_and_remove_lora (lora_model_dir) && validate_missing_loras) {
2510+ return false ;
2511+ }
25062512 }
25072513 return true ;
25082514}
@@ -2630,7 +2636,7 @@ bool SDGenerationParams::resolve_and_validate(SDMode mode,
26302636 const std::string& lora_model_dir,
26312637 const std::string& hires_upscalers_dir,
26322638 bool strict) {
2633- if (!resolve (lora_model_dir, hires_upscalers_dir, strict)) {
2639+ if (!resolve (lora_model_dir, hires_upscalers_dir, strict, mode == CONVERT )) {
26342640 return false ;
26352641 }
26362642 if (!validate (mode)) {
0 commit comments