Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 97f7294

Browse files
committedFeb 7, 2025
lora: unapply current loras properly
1 parent f0f8e57 commit 97f7294

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed
 

‎stable-diffusion.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -689,19 +689,20 @@ class StableDiffusionGGML {
689689
for (auto& kv : lora_state) {
690690
const std::string& lora_name = kv.first;
691691
float multiplier = kv.second;
692-
693-
if (curr_lora_state.find(lora_name) != curr_lora_state.end()) {
694-
float curr_multiplier = curr_lora_state[lora_name];
695-
float multiplier_diff = multiplier - curr_multiplier;
696-
if (multiplier_diff != 0.f) {
697-
lora_state_diff[lora_name] = multiplier_diff;
698-
}
699-
} else {
700-
lora_state_diff[lora_name] = multiplier;
701-
}
692+
lora_state_diff[lora_name] += multiplier;
693+
}
694+
for (auto& kv : curr_lora_state) {
695+
const std::string& lora_name = kv.first;
696+
float curr_multiplier = kv.second;
697+
lora_state_diff[lora_name] -= curr_multiplier;
698+
}
699+
700+
size_t rm = lora_state_diff.size() - lora_state.size();
701+
if (rm != 0) {
702+
LOG_INFO("Attempting to apply %lu LoRAs (removing %lu applied LoRAs)", lora_state.size(), rm);
703+
} else {
704+
LOG_INFO("Attempting to apply %lu LoRAs", lora_state.size());
702705
}
703-
704-
LOG_INFO("Attempting to apply %lu LoRAs", lora_state.size());
705706

706707
for (auto& kv : lora_state_diff) {
707708
apply_lora(kv.first, kv.second);

0 commit comments

Comments
 (0)
Please sign in to comment.