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 loading IntervenableModel for its subclasses #49

Merged
merged 1 commit into from
Apr 11, 2024
Merged
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
13 changes: 13 additions & 0 deletions pyreft/reft_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ class ReftModel(pv.IntervenableModel):
def __init__(self, config, model, **kwargs):
super().__init__(config, model, **kwargs)

@staticmethod
def _convert_to_reft_model(intervenable_model):
reft_model = ReftModel(intervenable_model.config, intervenable_model.model)
# Copy any other necessary attributes
for attr in vars(intervenable_model):
setattr(reft_model, attr, getattr(intervenable_model, attr))
return reft_model

@staticmethod
def load(*args, **kwargs):
model = pv.IntervenableModel.load(*args, **kwargs)
return ReftModel._convert_to_reft_model(model)

def print_trainable_parameters(self):
"""
Print trainable parameters.
Expand Down