Skip to content

Commit

Permalink
Fix ModulesToSaveWrapper __getattr__ (#1238)
Browse files Browse the repository at this point in the history
* Update other.py

* Update other.py

* Update test_low_level_api.py
  • Loading branch information
zhangsheng377 authored Dec 13, 2023
1 parent 88e2e75 commit 0f1e909
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
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"))

0 comments on commit 0f1e909

Please sign in to comment.