Skip to content
Open
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
18 changes: 6 additions & 12 deletions rankers/modelling/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,12 @@ def save_pretrained(self, model_dir, **kwargs):
self.model.save_pretrained(model_dir)
self.tokenizer.save_pretrained(model_dir)

def load_state_dict(self, model_dir):
"""Load model state dictionary from a directory.

Args:
model_dir (str): Directory containing the saved model.

Returns:
dict: Result of loading the state dictionary.
"""
return self.model.load_state_dict(
self.architecture_class.from_pretrained(model_dir).state_dict()
)
def load_state_dict(self, state_dict, strict=False, **kwargs):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming here gets a bit weird,

if isinstance(state_dict, str):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make it clearer that we are saying this is a valid path

loaded = self.architecture_class.from_pretrained(state_dict).state_dict()
return self.model.load_state_dict(loaded, strict=strict)

return self.model.load_state_dict(state_dict, strict=strict)

def to_pyterrier(self, batch_size=None):
"""Convert the ranker to a PyTerrier transformer.
Expand Down
Loading