From 90e9178d18f45c8e2d8eeb5adab2465ae8753a48 Mon Sep 17 00:00:00 2001 From: bssrdf Date: Mon, 1 Apr 2024 23:58:29 -0400 Subject: [PATCH] fix: apply pmid lora only once for multiple txt2img calls (#208) Co-authored-by: bssrdf --- lora.hpp | 1 + stable-diffusion.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lora.hpp b/lora.hpp index 06b37bb..15a4dcd 100644 --- a/lora.hpp +++ b/lora.hpp @@ -11,6 +11,7 @@ struct LoraModel : public GGMLModule { std::string file_path; ModelLoader model_loader; bool load_failed = false; + bool applied = false; LoraModel(ggml_backend_t backend, ggml_type wtype, diff --git a/stable-diffusion.cpp b/stable-diffusion.cpp index 9d10086..5ee2d56 100644 --- a/stable-diffusion.cpp +++ b/stable-diffusion.cpp @@ -1607,10 +1607,11 @@ sd_image_t* txt2img(sd_ctx_t* sd_ctx, int64_t t1 = ggml_time_ms(); LOG_INFO("apply_loras completed, taking %.2fs", (t1 - t0) * 1.0f / 1000); - if (sd_ctx->sd->stacked_id) { + if (sd_ctx->sd->stacked_id && !sd_ctx->sd->pmid_lora->applied) { t0 = ggml_time_ms(); sd_ctx->sd->pmid_lora->apply(sd_ctx->sd->tensors, sd_ctx->sd->n_threads); t1 = ggml_time_ms(); + sd_ctx->sd->pmid_lora->applied = true; LOG_INFO("pmid_lora apply completed, taking %.2fs", (t1 - t0) * 1.0f / 1000); if (sd_ctx->sd->free_params_immediately) { sd_ctx->sd->pmid_lora->free_params_buffer();