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 ModulesToSaveWrapper __getattr__ #1238

Merged
merged 3 commits into from
Dec 13, 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
6 changes: 6 additions & 0 deletions src/peft/utils/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ def active_adapter(self) -> str:
# use a property to ensure that active_adapter is not set directly, instead use the set_adapter method
return self._active_adapter

@property
def weight(self):
if self.active_adapter not in self.modules_to_save:
return self.original_module.weight
return self.modules_to_save[self.active_adapter].weight

def update(self, adapter_name):
self.modules_to_save.update(torch.nn.ModuleDict({adapter_name: copy.deepcopy(self.original_module)}))

Expand Down
2 changes: 2 additions & 0 deletions tests/test_low_level_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ def test_modules_to_save(self):
state_dict = get_peft_model_state_dict(self.model)

self.assertTrue("embedding.weight" in state_dict.keys())

self.assertTrue(hasattr(self.model.embedding, "weight"))
Loading