8000 Add filename components in Checkpoint by sdesrozis · Pull Request #2498 · pytorch/ignite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 10 commits into from
Mar 9, 2022

Conversation

sdesrozis
Copy link
Contributor

Fixes #2480

Description:

Check list:

  • New tests are added (if a new feature is added)
  • New doc strings: description and/or example code are in RST format
  • Documentation is updated (if required)

@github-actions github-actions bot added the module: handlers Core Handlers module label Mar 3, 2022
@sdesrozis sdesrozis requested a review from vfdev-5 March 5, 2022 08:03
Copy link
Collaborator
@vfdev-5 vfdev-5 left a 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

Copy link
Collaborator
@vfdev-5 vfdev-5 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @sdesrozis !

@vfdev-5 vfdev-5 enabled auto-merge (squash) March 9, 2022 16:06
@vfdev-5 vfdev-5 merged commit 06018c6 into pytorch:master Mar 9, 2022
@vfdev-5 vfdev-5 deleted the checkpoint_load_from_filename branch March 9, 2022 17:22
Comment on lines +550 to +564
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)
Copy link
Collaborator

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: handlers Core Handlers module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pass filename components into Checkpoint.load_objects
2 participants
0