Skip to content

Commit 2752ba5

Browse files
FIX: Small fixes to warning like missing spaces
- 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 huggingface#2254
1 parent 13fa0ae commit 2752ba5

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/peft/mapping_func.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def get_peft_model(
101101
prefix = PEFT_TYPE_TO_PREFIX_MAPPING.get(peft_config.peft_type)
102102
if prefix and adapter_name in prefix:
103103
warnings.warn(
104-
f"Adapter name {adapter_name} should not be contained in the prefix {prefix}."
104+
f"Adapter name '{adapter_name}' should not be contained in the prefix '{prefix}'. "
105105
"This may lead to reinitialization of the adapter weights during loading."
106106
)
107107

src/peft/peft_model.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,10 @@ def from_pretrained(
578578

579579
prefix = PEFT_TYPE_TO_PREFIX_MAPPING.get(config.peft_type)
580580
if prefix and adapter_name in prefix:
581-
warn_message += (
582-
f"Adapter name {adapter_name} should not be contained in the prefix {prefix}."
583-
"This could be the potential reason for missing adapter keys."
584-
)
581+
warn_message = (
582+
f"Adapter name '{adapter_name}' should not be contained in the prefix '{prefix}'. "
583+
"This could be the potential reason for missing adapter keys. "
584+
) + warn_message
585585

586586
warnings.warn(warn_message)
587587

@@ -999,7 +999,7 @@ def add_adapter(self, adapter_name: str, peft_config: PeftConfig, low_cpu_mem_us
999999
prefix = PEFT_TYPE_TO_PREFIX_MAPPING.get(peft_config.peft_type)
10001000
if prefix and adapter_name in prefix:
10011001
warnings.warn(
1002-
f"Adapter name {adapter_name} should not be contained in the prefix {prefix}."
1002+
f"Adapter name '{adapter_name}' should not be contained in the prefix '{prefix}'. "
10031003
"This may lead to reinitialization of the adapter weights during loading."
10041004
)
10051005

tests/test_initialization.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,7 +2246,7 @@ def test_no_warning_without_naming_conflict_get_peft_model(self, recwarn):
22462246
# No warning should be raised when there is no naming conflict during get_peft_model.
22472247
non_conflict_adapter = "adapter"
22482248
_ = get_peft_model(self.base_model, self.peft_config, adapter_name=non_conflict_adapter)
2249-
expected_msg = f"Adapter name {non_conflict_adapter} should not be contained in the prefix {self.prefix}."
2249+
expected_msg = f"Adapter name '{non_conflict_adapter}' should not be contained in the prefix '{self.prefix}'."
22502250
assert not any(expected_msg in str(w.message) for w in recwarn.list)
22512251

22522252
def test_no_warning_without_naming_conflict_add_adapter(self, recwarn):
@@ -2256,7 +2256,7 @@ def test_no_warning_without_naming_conflict_add_adapter(self, recwarn):
22562256
model = get_peft_model(self.base_model, self.peft_config, adapter_name=non_conflict_adapter)
22572257
_ = model.add_adapter(other_non_conflict_adapter, self.peft_config)
22582258
expected_msg = (
2259-
f"Adapter name {other_non_conflict_adapter} should not be contained in the prefix {self.prefix}."
2259+
f"Adapter name '{other_non_conflict_adapter}' should not be contained in the prefix '{self.prefix}'."
22602260
)
22612261
assert not any(expected_msg in str(w.message) for w in recwarn.list)
22622262

@@ -2265,14 +2265,16 @@ def test_no_warning_without_naming_conflict_save_and_load(self, recwarn, tmp_pat
22652265
non_conflict_adapter = "adapter"
22662266
model = get_peft_model(self.base_model, self.peft_config, adapter_name=non_conflict_adapter)
22672267
_ = self._save_and_reload_model(model, non_conflict_adapter, tmp_path)
2268-
expected_msg = f"Adapter name {non_conflict_adapter} should not be contained in the prefix {self.prefix}."
2268+
expected_msg = f"Adapter name '{non_conflict_adapter}' should not be contained in the prefix '{self.prefix}'."
22692269
assert not any(expected_msg in str(w.message) for w in recwarn.list)
22702270

22712271
def test_warning_naming_conflict_get_peft_model(self, recwarn):
22722272
# Warning is raised when the adapter name conflicts with the prefix in get_peft_model.
22732273
conflicting_adapter_name = self.prefix[:-1]
22742274
_ = get_peft_model(self.base_model, self.peft_config, adapter_name=conflicting_adapter_name)
2275-
expected_msg = f"Adapter name {conflicting_adapter_name} should not be contained in the prefix {self.prefix}."
2275+
expected_msg = (
2276+
f"Adapter name '{conflicting_adapter_name}' should not be contained in the prefix '{self.prefix}'."
2277+
)
22762278
assert any(expected_msg in str(w.message) for w in recwarn.list)
22772279

22782280
def test_warning_naming_conflict_add_adapter(self, recwarn):
@@ -2281,15 +2283,15 @@ def test_warning_naming_conflict_add_adapter(self, recwarn):
22812283
non_conflict_adapter = "adapter"
22822284
model = get_peft_model(self.base_model, self.peft_config, adapter_name=non_conflict_adapter)
22832285
_ = model.add_adapter(conflicting_adapter, self.peft_config)
2284-
expected_msg = f"Adapter name {conflicting_adapter} should not be contained in the prefix {self.prefix}."
2286+
expected_msg = f"Adapter name '{conflicting_adapter}' should not be contained in the prefix '{self.prefix}'."
22852287
assert any(expected_msg in str(w.message) for w in recwarn.list)
22862288

22872289
def test_warning_naming_conflict_save_and_load(self, recwarn, tmp_path):
22882290
# Warning is raised when saving and loading the model with a naming conflict.
22892291
conflicting_adapter = self.prefix[:-1]
22902292
model = get_peft_model(self.base_model, self.peft_config, adapter_name=conflicting_adapter)
22912293
_ = self._save_and_reload_model(model, conflicting_adapter, tmp_path)
2292-
expected_msg = f"Adapter name {conflicting_adapter} should not be contained in the prefix {self.prefix}."
2294+
expected_msg = f"Adapter name '{conflicting_adapter}' should not be contained in the prefix '{self.prefix}'."
22932295
assert any(expected_msg in str(w.message) for w in recwarn.list)
22942296

22952297

0 commit comments

Comments
 (0)