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

return load_result when load_adapter #481

Merged
merged 1 commit into from
Jun 1, 2023
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
3 changes: 2 additions & 1 deletion src/peft/peft_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def load_adapter(self, model_id, adapter_name, is_trainable=False, **kwargs):
filename, map_location=torch.device("cuda" if torch.cuda.is_available() else "cpu")
)
# load the weights into the model
set_peft_model_state_dict(self, adapters_weights, adapter_name=adapter_name)
load_result = set_peft_model_state_dict(self, adapters_weights, adapter_name=adapter_name)
if (
(getattr(self, "hf_device_map", None) is not None)
and (len(set(self.hf_device_map.values()).intersection({"cpu", "disk"})) > 0)
Expand Down Expand Up @@ -424,6 +424,7 @@ def load_adapter(self, model_id, adapter_name, is_trainable=False, **kwargs):

# Set model in evaluation mode to deactivate Dropout modules by default
self.eval()
return load_result

def set_adapter(self, adapter_name):
"""
Expand Down
3 changes: 2 additions & 1 deletion src/peft/utils/save_and_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ def set_peft_model_state_dict(model, peft_model_state_dict, adapter_name="defaul
else:
raise NotImplementedError

model.load_state_dict(peft_model_state_dict, strict=False)
load_result = model.load_state_dict(peft_model_state_dict, strict=False)
if isinstance(config, PromptLearningConfig):
model.prompt_encoder[adapter_name].embedding.load_state_dict(
{"weight": peft_model_state_dict["prompt_embeddings"]}, strict=True
)
return load_result