Skip to content

Commit 1c864a1

Browse files
committed
raise warning instead of error.
1 parent 33bc47a commit 1c864a1

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/diffusers/loaders/lora_base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,10 +532,12 @@ def set_adapters(
532532

533533
invalid_components = sorted(components_passed - lora_components)
534534
if invalid_components:
535-
raise ValueError(
535+
logger.warning(
536536
f"The following components in `adapter_weights` are not part of the pipeline: {invalid_components}. "
537-
f"Available components that are LoRA-compatible: {self._lora_loadable_modules}"
537+
f"Available components that are LoRA-compatible: {self._lora_loadable_modules}. So, weights belonging "
538+
"to the invalid components will be removed and ignored."
538539
)
540+
adapter_weights = {k: v for k, v in adapter_weights.items() if k not in invalid_components}
539541

540542
adapter_names = [adapter_names] if isinstance(adapter_names, str) else adapter_names
541543
adapter_weights = copy.deepcopy(adapter_weights)

tests/lora/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,12 +1148,14 @@ def test_multiple_wrong_adapter_name_raises_error(self):
11481148
)
11491149

11501150
scale_with_wrong_components = {"foo": 0.0, "bar": 0.0, "tik": 0.0}
1151-
with self.assertRaises(ValueError) as err_context:
1151+
logger = logging.get_logger("diffusers.loaders.lora_base")
1152+
logger.setLevel(30)
1153+
with CaptureLogger(logger) as cap_logger:
11521154
pipe.set_adapters("adapter-1", adapter_weights=scale_with_wrong_components)
11531155

11541156
wrong_components = sorted(set(scale_with_wrong_components.keys()))
1155-
msg = f"The following components in `adapter_weights` are not part of the pipeline: {wrong_components}"
1156-
self.assertTrue(msg in str(err_context.exception))
1157+
msg = f"The following components in `adapter_weights` are not part of the pipeline: {wrong_components}. "
1158+
self.assertTrue(msg in str(cap_logger.out))
11571159

11581160
# test this works.
11591161
pipe.set_adapters("adapter-1")

0 commit comments

Comments
 (0)