diff --git a/otherarch/sdcpp/sdtype_adapter.cpp b/otherarch/sdcpp/sdtype_adapter.cpp index 604808807..03e781835 100644 --- a/otherarch/sdcpp/sdtype_adapter.cpp +++ b/otherarch/sdcpp/sdtype_adapter.cpp @@ -251,8 +251,8 @@ bool sdtype_load_model(const sd_load_model_inputs inputs) { if(lorafilename!="" && inputs.lora_multiplier>0) { - printf("\nApplying LoRA now...\n"); - sd_ctx->sd->apply_lora_from_file(lorafilename,inputs.lora_multiplier); + printf("\nSet pending LoRA...\n"); + sd_ctx->sd->set_pending_lora(lorafilename,inputs.lora_multiplier); } return true; diff --git a/otherarch/sdcpp/stable-diffusion.cpp b/otherarch/sdcpp/stable-diffusion.cpp index c559a5869..5a70ed4fa 100644 --- a/otherarch/sdcpp/stable-diffusion.cpp +++ b/otherarch/sdcpp/stable-diffusion.cpp @@ -57,6 +57,9 @@ void calculate_alphas_cumprod(float* alphas_cumprod, /*=============================================== StableDiffusionGGML ================================================*/ +static std::string pending_apply_lora_fname = ""; +static float pending_apply_lora_power = 1.0f; + class StableDiffusionGGML { public: ggml_backend_t backend = NULL; // general backend @@ -87,6 +90,7 @@ public: // lora_name => multiplier std::unordered_map curr_lora_state; + std::shared_ptr denoiser = std::make_shared(); StableDiffusionGGML() = default; @@ -402,6 +406,11 @@ public: return result < -1; } + void set_pending_lora(const std::string& lora_path, float multiplier) { + pending_apply_lora_fname = lora_path; + pending_apply_lora_power = multiplier; + } + void apply_lora_from_file(const std::string& lora_path, float multiplier) { int64_t t0 = ggml_time_ms(); std::string st_file_path = lora_path; @@ -1394,6 +1403,12 @@ sd_image_t* txt2img(sd_ctx_t* sd_ctx, int64_t t0 = ggml_time_ms(); sd_ctx->sd->apply_loras(lora_f2m); + if(pending_apply_lora_fname!="" && pending_apply_lora_power>0) + { + printf("\nApplying LoRA now...\n"); + sd_ctx->sd->apply_lora_from_file(pending_apply_lora_fname,pending_apply_lora_power); + pending_apply_lora_fname = ""; + } int64_t t1 = ggml_time_ms(); LOG_INFO("apply_loras completed, taking %.2fs", (t1 - t0) * 1.0f / 1000); struct ggml_init_params params; @@ -1587,6 +1602,12 @@ sd_image_t* img2img(sd_ctx_t* sd_ctx, // load lora from file int64_t t0 = ggml_time_ms(); sd_ctx->sd->apply_loras(lora_f2m); + if(pending_apply_lora_fname!="" && pending_apply_lora_power>0) + { + printf("\nApplying LoRA now...\n"); + sd_ctx->sd->apply_lora_from_file(pending_apply_lora_fname,pending_apply_lora_power); + pending_apply_lora_fname = ""; + } int64_t t1 = ggml_time_ms(); LOG_INFO("apply_loras completed, taking %.2fs", (t1 - t0) * 1.0f / 1000);