Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Reinstate PEFT_TYPE_TO_MODEL_MAPPING variable with deprecation #2328

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/peft/peft_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3022,3 +3022,19 @@ def check_irrgular(vals: list[bool | Literal["irregular"]]) -> bool | Literal["i
devices=devices,
)
return adapter_model_status


def __getattr__(name):
if name == "PEFT_TYPE_TO_MODEL_MAPPING":
# This is for backwards compatibility: In #2282, PEFT_TYPE_TO_MODEL_MAPPING was removed as it was redundant with
# PEFT_TYPE_TO_TUNER_MAPPING. However, third party code could still use this mapping, e.g.:
# https://github.com/AutoGPTQ/AutoGPTQ/blob/6689349625de973b9ee3016c28c11f32acf7f02c/auto_gptq/utils/peft_utils.py#L8
# TODO: Remove after 2026-01
msg = (
"PEFT_TYPE_TO_MODEL_MAPPING is deprecated, please use `from peft import PEFT_TYPE_TO_TUNER_MAPPING` instead. "
"The deprecated variable will be removed in 2026."
)
warnings.warn(msg, category=DeprecationWarning)
return PEFT_TYPE_TO_TUNER_MAPPING

raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
22 changes: 22 additions & 0 deletions tests/test_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2961,3 +2961,25 @@ def test_hotswap_extra_key_raises(self, tmp_path):
msg = f"Hot swapping the adapter did not succeed. Unexpected keys: {new_key}"
with pytest.raises(RuntimeError, match=msg):
hotswap_adapter(model, tmp_path / "adapter1", adapter_name="default")


def test_import_peft_type_to_model_mapping_deprecation_warning(recwarn):
# This is for backwards compatibility: In #2282, PEFT_TYPE_TO_MODEL_MAPPING was removed as it was redundant with
# PEFT_TYPE_TO_TUNER_MAPPING. However, third party code could still use this mapping, e.g.:
# https://github.com/AutoGPTQ/AutoGPTQ/blob/6689349625de973b9ee3016c28c11f32acf7f02c/auto_gptq/utils/peft_utils.py#L8
# TODO: Remove after 2026-01

# first check that there is no warning under normal circumstances
from peft.peft_model import PeftModel # noqa

expected = (
"PEFT_TYPE_TO_MODEL_MAPPING is deprecated, please use `from peft import PEFT_TYPE_TO_TUNER_MAPPING` instead"
)
warnings = (w.message.args[0] for w in recwarn.list)
assert not any(w.startswith(expected) for w in warnings)

from peft.peft_model import PEFT_TYPE_TO_MODEL_MAPPING # noqa

# check that there is a warning with this message after importing the variable
warnings = (w.message.args[0] for w in recwarn.list)
assert any(w.startswith(expected) for w in warnings)
Loading