-
-
Notifications
You must be signed in to change notification settings - Fork 667
Description
🐛 Bug description
When using Checkpoint with a callable object as save_handler, calling reload_objects causes AttributeError. To reproduce:
def test_checkpoint_simple_recovery():
from pickle import dump
class SaveHandler:
def __call__(self, checkpoint, filename):
with open(filename, 'wb') as f:
dump(checkpoint, f)
to_save = {'model': DummyModel()}
h = Checkpoint(to_save, SaveHandler())
engine = Engine(lambda e, b: None)
engine.state = State(epoch=0, iteration=1)
h(engine)
to_load = {"model": DummyModel()}
h.reload_objects(to_load, global_step=1)result:
> path = self.save_handler.dirname / checkpoint_fp
E AttributeError: 'SaveHandler' object has no attribute 'dirname'
It attempts to access dirname of the handler while dirname is only the attribute of the DiskSaver not even BaseSaveHandler.
Also in the Checkpoint docstring, it states String, method or callable class (by callable class it means callable object?) for save_handler type but in type checks we allow a callable function:
if not (
isinstance(save_handler, str)
or isinstance(save_handler, Path)
or callable(save_handler)
or isinstance(save_handler, BaseSaveHandler)
):
raise TypeError(
"Argument `save_handler` should be a string or Path object or callable or inherit from BaseSaveHandler"
)Checklist
-
ignite/handlers/checkpoint.py
• In the
reload_objectsmethod of theCheckpointclass, before the linepath = self.save_handler.dirname / checkpoint_fp, add a condition to check ifself.save_handleris an instance ofDiskSaver.
• Ifself.save_handleris an instance ofDiskSaver, keep the existing logic to get thepath.
• Ifself.save_handleris not an instance ofDiskSaver, handle the checkpoint reloading for the callable object. This might involve calling thesave_handlerwith the appropriate arguments to reload the checkpoint.