Skip to content

Commit d4cd553

Browse files
committed
test(adalora): validate ValueError when loading second trainable adapter
1 parent 1a81613 commit d4cd553

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

tests/test_custom_models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5953,6 +5953,11 @@ def test_loading_model_requires_grad_set_correctly(self, config_cls, is_trainabl
59535953
assert all(not p.requires_grad for p in model.parameters())
59545954

59555955
# load one more adapter; this adapter is not automatically activated
5956+
if config_cls is AdaLoraConfig and is_trainable:
5957+
# AdaLoRA structurally rejects a second trainable adapter; validate the error path.
5958+
with pytest.raises(ValueError, match="AdaLoraModel supports only 1 trainable adapter"):
5959+
model.load_adapter(tmp_path, adapter_name="other", is_trainable=is_trainable)
5960+
return
59565961
model.load_adapter(tmp_path, adapter_name="other", is_trainable=is_trainable)
59575962
if is_trainable:
59585963
for name, param in model.named_parameters():
@@ -6001,6 +6006,11 @@ def test_loading_model_with_modules_to_save_requires_grad_set_correctly(self, co
60016006
assert all(not p.requires_grad for p in model.parameters())
60026007

60036008
# load one more adapter
6009+
if config_cls is AdaLoraConfig and is_trainable:
6010+
# AdaLoRA structurally rejects a second trainable adapter; validate the error path.
6011+
with pytest.raises(ValueError, match="AdaLoraModel supports only 1 trainable adapter"):
6012+
model.load_adapter(tmp_path, adapter_name="other", is_trainable=is_trainable)
6013+
return
60046014
model.load_adapter(tmp_path, adapter_name="other", is_trainable=is_trainable)
60056015
if is_trainable:
60066016
for name, param in model.named_parameters():

0 commit comments

Comments
 (0)