Skip to content

Commit f23b803

Browse files
authored
fix:: unapply current loras properly (leejet#590)
1 parent 1be2491 commit f23b803

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

stable-diffusion.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -673,19 +673,20 @@ class StableDiffusionGGML {
673673
for (auto& kv : lora_state) {
674674
const std::string& lora_name = kv.first;
675675
float multiplier = kv.second;
676-
677-
if (curr_lora_state.find(lora_name) != curr_lora_state.end()) {
678-
float curr_multiplier = curr_lora_state[lora_name];
679-
float multiplier_diff = multiplier - curr_multiplier;
680-
if (multiplier_diff != 0.f) {
681-
lora_state_diff[lora_name] = multiplier_diff;
682-
}
683-
} else {
684-
lora_state_diff[lora_name] = multiplier;
685-
}
676+
lora_state_diff[lora_name] += multiplier;
677+
}
678+
for (auto& kv : curr_lora_state) {
679+
const std::string& lora_name = kv.first;
680+
float curr_multiplier = kv.second;
681+
lora_state_diff[lora_name] -= curr_multiplier;
682+
}
683+
684+
size_t rm = lora_state_diff.size() - lora_state.size();
685+
if (rm != 0) {
686+
LOG_INFO("Attempting to apply %lu LoRAs (removing %lu applied LoRAs)", lora_state.size(), rm);
687+
} else {
688+
LOG_INFO("Attempting to apply %lu LoRAs", lora_state.size());
686689
}
687-
688-
LOG_INFO("Attempting to apply %lu LoRAs", lora_state.size());
689690

690691
for (auto& kv : lora_state_diff) {
691692
apply_lora(kv.first, kv.second);

0 commit comments

Comments
 (0)