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 Bug in prompt learning after disabling adapter #1502

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
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
Loading