-
-
Notifications
You must be signed in to change notification settings - Fork 650
Add filename components in Checkpoint #2498
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
Add filename components in Checkpoint #2498
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, just a nit about refactored function name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @sdesrozis !
with tempfile.TemporaryDirectory() as tmpdirname: | ||
handler = ModelCheckpoint(tmpdirname, 'myprefix', n_saved=None, create_dir=True) | ||
|
||
model = torch.nn.Linear(3, 3) | ||
optimizer = torch.optim.SGD(model.parameters(), lr=1e-3) | ||
|
||
to_save = {"weights": model, "optimizer": optimizer} | ||
|
||
trainer.add_event_handler(Events.EPOCH_COMPLETED(every=2), handler, to_save) | ||
trainer.run(torch.randn(10, 1), 5) | ||
|
||
to_load = to_save | ||
checkpoint_fp = Path(tmpdirname) / 'myprefix_checkpoint_40.pt' | ||
checkpoint = torch.load(checkpoint_fp) | ||
Checkpoint.load_objects(to_load=to_load, checkpoint=checkpoint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sdesrozis this example is not working:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [2], in <cell line: 10>()
21 to_load = to_save
22 # load checkpoint myprefix_checkpoint_40.pt
---> 23 checkpoint.load_objects(to_load=to_load, global_step=40)
TypeError: load_objects() missing 1 required positional argument: 'checkpoint'
import torch | ||
|
||
from ignite.engine import Engine, Events | ||
from ignite.handlers import ModelCheckpoint, Checkpoint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also remove unused Checkpoint
Fixes #2480
Description:
Check list: