Update peft_model.py

This commit is contained in:
Sourab Mangrulkar
2023-04-08 11:45:32 +05:30
parent 7b7038273a
commit ff282c2a8f
+6 -1
View File
@@ -132,7 +132,7 @@ class PeftModel(PushToHubMixin, torch.nn.Module):
peft_config.inference_mode = inference_mode
@classmethod
def from_pretrained(cls, model, model_id, adapter_name="default", **kwargs):
def from_pretrained(cls, model, model_id, adapter_name="default", is_trainable=False, **kwargs):
r"""
Instantiate a [`LoraModel`] from a pretrained Lora configuration and weights.
@@ -159,6 +159,11 @@ class PeftModel(PushToHubMixin, torch.nn.Module):
) > 0:
remove_hook_from_submodules(model)
if isinstance(config, PromptLearningConfig) and is_trainable:
raise ValueError("Cannot set a prompt learning adapter to trainable when loading pretrained adapter.")
else:
config.inference_mode = not is_trainable
if config.task_type not in MODEL_TYPE_TO_PEFT_MODEL_MAPPING.keys():
model = cls(model, config, adapter_name)
else: