Skip to content

Commit

Permalink
Expose bias attribute on tuner layers (#1530)
Browse files Browse the repository at this point in the history
Expose bias attribute on tuner layers

See #1524

This is similar to how we already expose the weight attribute.
  • Loading branch information
BenjaminBossan authored Mar 5, 2024
1 parent 98f4db2 commit b58b13b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/peft/tuners/tuners_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,11 @@ def weight(self) -> torch.Tensor:
weight = base_layer.weight
return weight

@property
def bias(self) -> torch.Tensor:
base_layer = self.get_base_layer()
return base_layer.bias

def merge(self, safe_merge: bool = False, adapter_names: Optional[list[str]] = None) -> None:
raise NotImplementedError

Expand Down
7 changes: 7 additions & 0 deletions tests/test_custom_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,13 @@ def test_delete_inactive_adapter(self, test_name, model_id, config_cls, config_k
def test_adding_multiple_adapters_with_bias_raises(self, test_name, model_id, config_cls, config_kwargs):
self._test_adding_multiple_adapters_with_bias_raises(model_id, config_cls, config_kwargs)

def test_weight_bias_attributes(self):
model = MLP()
config = LoraConfig(target_modules=["lin0"])
model = get_peft_model(model, config)
assert hasattr(model.base_model.model.lin0, "weight")
assert hasattr(model.base_model.model.lin0, "bias")

def test_existing_model_card(self):
# ensure that if there is already a model card, it is not overwritten
model = MLP()
Expand Down

0 comments on commit b58b13b

Please sign in to comment.