Skip to content

add support for not loading weights #1424

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

Merged
merged 3 commits into from
Oct 26, 2021
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
8 changes: 7 additions & 1 deletion torchtext/models/roberta/bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ class RobertaModelBundle:
_head: Optional[Module] = None
transform: Optional[Callable] = None

def get_model(self, head: Optional[Module] = None, *, dl_kwargs=None) -> RobertaModel:
def get_model(self, head: Optional[Module] = None, load_weights=True, *, dl_kwargs=None) -> RobertaModel:

if load_weights:
assert self._path is not None, "load_weights cannot be True. The pre-trained model weights are not available for the current object"

if head is not None:
input_head = head
Expand All @@ -67,6 +70,9 @@ def get_model(self, head: Optional[Module] = None, *, dl_kwargs=None) -> Roberta

model = _get_model(self._params, input_head)

if not load_weights:
return model

dl_kwargs = {} if dl_kwargs is None else dl_kwargs
state_dict = load_state_dict_from_url(self._path, **dl_kwargs)
if input_head is not None:
Expand Down