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

[API] Add passthrough kwargs for torch.load #13

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Changes from 2 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
10 changes: 8 additions & 2 deletions wandb_preempt/checkpointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,18 @@ def save_checkpoint(self, extra_info: Dict) -> None:
save(data, tmp_savepath)
rename(tmp_savepath, savepath)

def load_latest_checkpoint(self) -> Tuple[int, Dict]:
def load_latest_checkpoint(
self, weights_only: bool = True, **kwargs
) -> Tuple[int, Dict]:
"""Load the latest checkpoint and set random number generator states.

Updates the model, optimizer, lr scheduler, and gradient scaler states
passed at initialization.

Args:
weights_only: Whether to load only the model weights. Default: `True`.
f-dangel marked this conversation as resolved.
Show resolved Hide resolved
**kwargs: Additional keyword arguments to pass to the `torch.load` function.

Returns:
The epoch number at which training should resume, and the extra information
that was passed by the user as a dictionary to the :meth:`step` function.
Expand All @@ -193,7 +199,7 @@ def load_latest_checkpoint(self) -> Tuple[int, Dict]:

self.maybe_print(f"Loading checkpoint {loadpath}.")

data = load(loadpath)
data = load(loadpath, weights_only=weights_only, **kwargs)
self.maybe_print("Loading model.")
self.model.load_state_dict(data["model"])
self.maybe_print("Loading optimizer.")
Expand Down