Skip to content

Commit b12f7b2

Browse files
FIX Test to ignore warning for enable_lora_hotswap
Low priority. I noticed that the test should be for the option check_compiled="ignore" but it was using check_compiled="warn". This has been fixed, now the correct argument is passed. However, the fact that the test passed means that it was incorrect to begin with. The way that logs are collected does not collect the logger.warning call here (not sure why). To amend this, I'm now using assertNoLogs. With this change, the test correctly fails when the wrong argument is passed. Note that assertNoLogs requires Python 3.10+ (3.9 is EOL since yesterday).
1 parent b429796 commit b12f7b2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tests/models/test_modeling_common.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,14 +2373,15 @@ def test_enable_lora_hotswap_called_after_adapter_added_warning(self):
23732373

23742374
def test_enable_lora_hotswap_called_after_adapter_added_ignore(self):
23752375
# check possibility to ignore the error/warning
2376+
from diffusers.loaders.peft import logger
2377+
23762378
lora_config = self.get_lora_config(8, 8, target_modules=["to_q"])
23772379
init_dict, inputs_dict = self.prepare_init_args_and_inputs_for_common()
23782380
model = self.model_class(**init_dict).to(torch_device)
23792381
model.add_adapter(lora_config)
2380-
with warnings.catch_warnings(record=True) as w:
2381-
warnings.simplefilter("always") # Capture all warnings
2382-
model.enable_lora_hotswap(target_rank=32, check_compiled="warn")
2383-
self.assertEqual(len(w), 0, f"Expected no warnings, but got: {[str(warn.message) for warn in w]}")
2382+
# note: assertNoLogs requires Python 3.10+
2383+
with self.assertNoLogs(logger, level="WARNING"):
2384+
model.enable_lora_hotswap(target_rank=32, check_compiled="ignore")
23842385

23852386
def test_enable_lora_hotswap_wrong_check_compiled_argument_raises(self):
23862387
# check that wrong argument value raises an error

0 commit comments

Comments
 (0)