mirror of
https://github.com/huggingface/peft.git
synced 2025-10-20 15:33:48 +08:00
FIX Small fixes to warning, like missing spaces (#2788)
- The warning message was missing spaces between sentences. - Added ' around strings for clarity - For one warning, which extended another warning, put it at the start instead of the end, because the other warning can be quite long, leading to users missing the addition For more context on this warning, see #2254
This commit is contained in:
@ -101,7 +101,7 @@ def get_peft_model(
|
||||
prefix = PEFT_TYPE_TO_PREFIX_MAPPING.get(peft_config.peft_type)
|
||||
if prefix and adapter_name in prefix:
|
||||
warnings.warn(
|
||||
f"Adapter name {adapter_name} should not be contained in the prefix {prefix}."
|
||||
f"Adapter name '{adapter_name}' should not be contained in the prefix '{prefix}'. "
|
||||
"This may lead to reinitialization of the adapter weights during loading."
|
||||
)
|
||||
|
||||
|
@ -578,10 +578,10 @@ class PeftModel(PushToHubMixin, torch.nn.Module):
|
||||
|
||||
prefix = PEFT_TYPE_TO_PREFIX_MAPPING.get(config.peft_type)
|
||||
if prefix and adapter_name in prefix:
|
||||
warn_message += (
|
||||
f"Adapter name {adapter_name} should not be contained in the prefix {prefix}."
|
||||
"This could be the potential reason for missing adapter keys."
|
||||
)
|
||||
warn_message = (
|
||||
f"Adapter name '{adapter_name}' should not be contained in the prefix '{prefix}'. "
|
||||
"This could be the potential reason for missing adapter keys. "
|
||||
) + warn_message
|
||||
|
||||
warnings.warn(warn_message)
|
||||
|
||||
@ -999,7 +999,7 @@ class PeftModel(PushToHubMixin, torch.nn.Module):
|
||||
prefix = PEFT_TYPE_TO_PREFIX_MAPPING.get(peft_config.peft_type)
|
||||
if prefix and adapter_name in prefix:
|
||||
warnings.warn(
|
||||
f"Adapter name {adapter_name} should not be contained in the prefix {prefix}."
|
||||
f"Adapter name '{adapter_name}' should not be contained in the prefix '{prefix}'. "
|
||||
"This may lead to reinitialization of the adapter weights during loading."
|
||||
)
|
||||
|
||||
|
@ -2267,7 +2267,7 @@ class TestNamingConflictWarning:
|
||||
# No warning should be raised when there is no naming conflict during get_peft_model.
|
||||
non_conflict_adapter = "adapter"
|
||||
_ = get_peft_model(self.base_model, self.peft_config, adapter_name=non_conflict_adapter)
|
||||
expected_msg = f"Adapter name {non_conflict_adapter} should not be contained in the prefix {self.prefix}."
|
||||
expected_msg = f"Adapter name '{non_conflict_adapter}' should not be contained in the prefix '{self.prefix}'."
|
||||
assert not any(expected_msg in str(w.message) for w in recwarn.list)
|
||||
|
||||
def test_no_warning_without_naming_conflict_add_adapter(self, recwarn):
|
||||
@ -2277,7 +2277,7 @@ class TestNamingConflictWarning:
|
||||
model = get_peft_model(self.base_model, self.peft_config, adapter_name=non_conflict_adapter)
|
||||
_ = model.add_adapter(other_non_conflict_adapter, self.peft_config)
|
||||
expected_msg = (
|
||||
f"Adapter name {other_non_conflict_adapter} should not be contained in the prefix {self.prefix}."
|
||||
f"Adapter name '{other_non_conflict_adapter}' should not be contained in the prefix '{self.prefix}'."
|
||||
)
|
||||
assert not any(expected_msg in str(w.message) for w in recwarn.list)
|
||||
|
||||
@ -2286,14 +2286,16 @@ class TestNamingConflictWarning:
|
||||
non_conflict_adapter = "adapter"
|
||||
model = get_peft_model(self.base_model, self.peft_config, adapter_name=non_conflict_adapter)
|
||||
_ = self._save_and_reload_model(model, non_conflict_adapter, tmp_path)
|
||||
expected_msg = f"Adapter name {non_conflict_adapter} should not be contained in the prefix {self.prefix}."
|
||||
expected_msg = f"Adapter name '{non_conflict_adapter}' should not be contained in the prefix '{self.prefix}'."
|
||||
assert not any(expected_msg in str(w.message) for w in recwarn.list)
|
||||
|
||||
def test_warning_naming_conflict_get_peft_model(self, recwarn):
|
||||
# Warning is raised when the adapter name conflicts with the prefix in get_peft_model.
|
||||
conflicting_adapter_name = self.prefix[:-1]
|
||||
_ = get_peft_model(self.base_model, self.peft_config, adapter_name=conflicting_adapter_name)
|
||||
expected_msg = f"Adapter name {conflicting_adapter_name} should not be contained in the prefix {self.prefix}."
|
||||
expected_msg = (
|
||||
f"Adapter name '{conflicting_adapter_name}' should not be contained in the prefix '{self.prefix}'."
|
||||
)
|
||||
assert any(expected_msg in str(w.message) for w in recwarn.list)
|
||||
|
||||
def test_warning_naming_conflict_add_adapter(self, recwarn):
|
||||
@ -2302,7 +2304,7 @@ class TestNamingConflictWarning:
|
||||
non_conflict_adapter = "adapter"
|
||||
model = get_peft_model(self.base_model, self.peft_config, adapter_name=non_conflict_adapter)
|
||||
_ = model.add_adapter(conflicting_adapter, self.peft_config)
|
||||
expected_msg = f"Adapter name {conflicting_adapter} should not be contained in the prefix {self.prefix}."
|
||||
expected_msg = f"Adapter name '{conflicting_adapter}' should not be contained in the prefix '{self.prefix}'."
|
||||
assert any(expected_msg in str(w.message) for w in recwarn.list)
|
||||
|
||||
def test_warning_naming_conflict_save_and_load(self, recwarn, tmp_path):
|
||||
@ -2310,7 +2312,7 @@ class TestNamingConflictWarning:
|
||||
conflicting_adapter = self.prefix[:-1]
|
||||
model = get_peft_model(self.base_model, self.peft_config, adapter_name=conflicting_adapter)
|
||||
_ = self._save_and_reload_model(model, conflicting_adapter, tmp_path)
|
||||
expected_msg = f"Adapter name {conflicting_adapter} should not be contained in the prefix {self.prefix}."
|
||||
expected_msg = f"Adapter name '{conflicting_adapter}' should not be contained in the prefix '{self.prefix}'."
|
||||
assert any(expected_msg in str(w.message) for w in recwarn.list)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user