Skip to content

Commit

Permalink
Improve invalid peft config error message
Browse files Browse the repository at this point in the history
  • Loading branch information
thedebugger committed Jan 26, 2025
1 parent 6e30991 commit b22b475
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/peft/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ def from_peft_type(cls, **kwargs):

filtered_kwargs, unexpected_kwargs = _check_and_remove_unused_kwargs(cls, kwargs)
if not MIN_EXPECTED_CONFIG_KEYS.issubset(set(filtered_kwargs.keys())):
raise TypeError(f"The config that is trying to be loaded is not a valid {cls.__name__} config.")
raise TypeError(f"The {cls.__name__} config that is trying to be loaded is missing required keys: "
f"{MIN_EXPECTED_CONFIG_KEYS}.")

warnings.warn(
f"Unexpected keyword arguments {sorted(unexpected_kwargs)} for class {cls.__name__}, these are "
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def test_from_pretrained_sanity_check(self, config_class, tmp_path):
with open(tmp_path / "adapter_config.json", "w") as f:
json.dump(non_peft_json, f)

msg = f"The config that is trying to be loaded is not a valid {config_class.__name__} config"
msg = f"The {config_class.__name__} config that is trying to be loaded is missing required keys: {{'peft_type'}}."
with pytest.raises(TypeError, match=msg):
config_class.from_pretrained(tmp_path)

Expand Down

0 comments on commit b22b475

Please sign in to comment.