Skip to content

Commit

Permalink
FIX Bug in prompt learning after disabling adapter (#1502)
Browse files Browse the repository at this point in the history
There was a big that after using the disable_adapter context, the
prepare method was not correctly restored, meaning that generations were
incorrect once the context was exited. This is now fixed.
  • Loading branch information
BenjaminBossan authored Feb 23, 2024
1 parent bc9426f commit 1b3b7b5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/peft/peft_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ def disable_adapter(self):
finally:
if self.peft_config[self.active_adapter].is_prompt_learning:
self.forward = old_forward
self.old_prepare_inputs_for_generation = old_prepare_inputs_for_generation
self.prepare_inputs_for_generation = old_prepare_inputs_for_generation
else:
self.base_model.enable_adapter_layers()

Expand Down
5 changes: 5 additions & 0 deletions tests/testing_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,11 @@ def get_output(model):
output_peft_disabled = get_output(peft_model)
assert torch.allclose(output_before, output_peft_disabled, atol=1e-6, rtol=1e-6)

# after leaving the disable_adapter context, the output should be the same as with enabled adapter again
# see #1501
output_peft_after_disabled = get_output(peft_model)
assert torch.allclose(output_peft, output_peft_after_disabled, atol=1e-6, rtol=1e-6)

# TODO: add tests to check if disabling adapters works after calling merge_adapter

def _test_adding_multiple_adapters_with_bias_raises(self, model_id, config_cls, config_kwargs):
Expand Down

0 comments on commit 1b3b7b5

Please sign in to comment.