Skip to content

Commit

Permalink
Revier feedback: wording, better error message
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminBossan committed Jul 4, 2024
1 parent 160eda1 commit 06168c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/peft/tuners/vera/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def update_layer(
vera_B_param = list(self.vera_B.values())[0]

error_tmpl = (
"{} has a size of {} but {} is or greater required; this probably happened because an additional VeRA "
"{} has a size of {} but {} or greater is required; this probably happened because an additional VeRA "
"adapter was added after the first one with incompatible shapes."
)
# check input size
Expand All @@ -112,6 +112,11 @@ def update_layer(
if vera_B_param.shape[0] < self.out_features:
raise ValueError(error_tmpl.format("vera_B", vera_B_param.shape[0], self.out_features))
# check r
error_tmpl = (
"{} has a size of {} but {} or greater is required; this probably happened because an additional VeRA "
"adapter with a lower rank was added after the first one; loading the adapters "
"in reverse order may solve this."
)
if vera_A_param.shape[0] < self.r[adapter_name]:
raise ValueError(error_tmpl.format("vera_A", vera_A_param.shape[0], self.r[adapter_name]))
if vera_B_param.shape[1] < self.r[adapter_name]:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def test_vera_add_second_adapter_with_incompatible_input_shape(self):

model = get_peft_model(self.get_model(), config0)
# not full message but enough to identify the error
msg = "vera_A has a size of 10 but 20 is or greater required"
msg = "vera_A has a size of 10 but 20 or greater is required"
with pytest.raises(ValueError, match=msg):
model.add_adapter("other", config1)

Expand All @@ -651,7 +651,7 @@ def test_vera_add_second_adapter_with_higher_rank(self):

model = get_peft_model(self.get_model(), config0)
# not full message but enough to identify the error
msg = "vera_A has a size of 123 but 456 is or greater required"
msg = "vera_A has a size of 123 but 456 or greater is required"
with pytest.raises(ValueError, match=msg):
model.add_adapter("other", config1)

Expand Down

0 comments on commit 06168c9

Please sign in to comment.