mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2025-09-11 17:44:38 +00:00
try to fix loras
This commit is contained in:
parent
ebbb969526
commit
e1e6833a7a
2 changed files with 23 additions and 2 deletions
|
@ -251,8 +251,8 @@ bool sdtype_load_model(const sd_load_model_inputs inputs) {
|
||||||
|
|
||||||
if(lorafilename!="" && inputs.lora_multiplier>0)
|
if(lorafilename!="" && inputs.lora_multiplier>0)
|
||||||
{
|
{
|
||||||
printf("\nApplying LoRA now...\n");
|
printf("\nSet pending LoRA...\n");
|
||||||
sd_ctx->sd->apply_lora_from_file(lorafilename,inputs.lora_multiplier);
|
sd_ctx->sd->set_pending_lora(lorafilename,inputs.lora_multiplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -57,6 +57,9 @@ void calculate_alphas_cumprod(float* alphas_cumprod,
|
||||||
|
|
||||||
/*=============================================== StableDiffusionGGML ================================================*/
|
/*=============================================== StableDiffusionGGML ================================================*/
|
||||||
|
|
||||||
|
static std::string pending_apply_lora_fname = "";
|
||||||
|
static float pending_apply_lora_power = 1.0f;
|
||||||
|
|
||||||
class StableDiffusionGGML {
|
class StableDiffusionGGML {
|
||||||
public:
|
public:
|
||||||
ggml_backend_t backend = NULL; // general backend
|
ggml_backend_t backend = NULL; // general backend
|
||||||
|
@ -87,6 +90,7 @@ public:
|
||||||
// lora_name => multiplier
|
// lora_name => multiplier
|
||||||
std::unordered_map<std::string, float> curr_lora_state;
|
std::unordered_map<std::string, float> curr_lora_state;
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<Denoiser> denoiser = std::make_shared<CompVisDenoiser>();
|
std::shared_ptr<Denoiser> denoiser = std::make_shared<CompVisDenoiser>();
|
||||||
|
|
||||||
StableDiffusionGGML() = default;
|
StableDiffusionGGML() = default;
|
||||||
|
@ -402,6 +406,11 @@ public:
|
||||||
return result < -1;
|
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) {
|
void apply_lora_from_file(const std::string& lora_path, float multiplier) {
|
||||||
int64_t t0 = ggml_time_ms();
|
int64_t t0 = ggml_time_ms();
|
||||||
std::string st_file_path = lora_path;
|
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();
|
int64_t t0 = ggml_time_ms();
|
||||||
sd_ctx->sd->apply_loras(lora_f2m);
|
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();
|
int64_t t1 = ggml_time_ms();
|
||||||
LOG_INFO("apply_loras completed, taking %.2fs", (t1 - t0) * 1.0f / 1000);
|
LOG_INFO("apply_loras completed, taking %.2fs", (t1 - t0) * 1.0f / 1000);
|
||||||
struct ggml_init_params params;
|
struct ggml_init_params params;
|
||||||
|
@ -1587,6 +1602,12 @@ sd_image_t* img2img(sd_ctx_t* sd_ctx,
|
||||||
// load lora from file
|
// load lora from file
|
||||||
int64_t t0 = ggml_time_ms();
|
int64_t t0 = ggml_time_ms();
|
||||||
sd_ctx->sd->apply_loras(lora_f2m);
|
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();
|
int64_t t1 = ggml_time_ms();
|
||||||
LOG_INFO("apply_loras completed, taking %.2fs", (t1 - t0) * 1.0f / 1000);
|
LOG_INFO("apply_loras completed, taking %.2fs", (t1 - t0) * 1.0f / 1000);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue