mirror of
https://github.com/wassname/peft.git
synced 2026-09-09 11:28:32 +08:00
Update peft_model.py
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user