Skip to content

Commit 9097ce5

Browse files
authored
fix: skip empty MultiLoraAdapter when no LoRAs target a model (#1469)
1 parent 3d6064b commit 9097ce5

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

src/stable-diffusion.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,8 +1104,13 @@ class StableDiffusionGGML {
11041104
cond_stage_lora_models.push_back(lora);
11051105
}
11061106
}
1107-
auto multi_lora_adapter = std::make_shared<MultiLoraAdapter>(cond_stage_lora_models);
1108-
cond_stage_model->set_weight_adapter(multi_lora_adapter);
1107+
// Only attach the adapter when there are LoRAs targeting the cond_stage model.
1108+
// An empty MultiLoraAdapter still routes every linear/conv through
1109+
// forward_with_lora() instead of the direct kernel path — slower for no benefit.
1110+
if (!cond_stage_lora_models.empty()) {
1111+
auto multi_lora_adapter = std::make_shared<MultiLoraAdapter>(cond_stage_lora_models);
1112+
cond_stage_model->set_weight_adapter(multi_lora_adapter);
1113+
}
11091114
}
11101115
if (diffusion_model) {
11111116
std::vector<std::shared_ptr<LoraModel>> lora_models;
@@ -1136,10 +1141,12 @@ class StableDiffusionGGML {
11361141
diffusion_lora_models.push_back(lora);
11371142
}
11381143
}
1139-
auto multi_lora_adapter = std::make_shared<MultiLoraAdapter>(diffusion_lora_models);
1140-
diffusion_model->set_weight_adapter(multi_lora_adapter);
1141-
if (high_noise_diffusion_model) {
1142-
high_noise_diffusion_model->set_weight_adapter(multi_lora_adapter);
1144+
if (!diffusion_lora_models.empty()) {
1145+
auto multi_lora_adapter = std::make_shared<MultiLoraAdapter>(diffusion_lora_models);
1146+
diffusion_model->set_weight_adapter(multi_lora_adapter);
1147+
if (high_noise_diffusion_model) {
1148+
high_noise_diffusion_model->set_weight_adapter(multi_lora_adapter);
1149+
}
11431150
}
11441151
}
11451152

@@ -1172,8 +1179,10 @@ class StableDiffusionGGML {
11721179
first_stage_lora_models.push_back(lora);
11731180
}
11741181
}
1175-
auto multi_lora_adapter = std::make_shared<MultiLoraAdapter>(first_stage_lora_models);
1176-
first_stage_model->set_weight_adapter(multi_lora_adapter);
1182+
if (!first_stage_lora_models.empty()) {
1183+
auto multi_lora_adapter = std::make_shared<MultiLoraAdapter>(first_stage_lora_models);
1184+
first_stage_model->set_weight_adapter(multi_lora_adapter);
1185+
}
11771186
}
11781187
}
11791188

0 commit comments

Comments
 (0)