Skip to content

Commit ac09cd1

Browse files
committed
Move checkpoint event example to Checkpoint docstring and document SAVED_CHECKPOINT attribute
1 parent ae0c038 commit ac09cd1

File tree

2 files changed

+24
-31
lines changed

2 files changed

+24
-31
lines changed

docs/source/handlers.rst

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,6 @@ Complete list of generic handlers
3535
state_param_scheduler.StateParamScheduler
3636

3737

38-
Checkpoint Events
39-
-----------------
40-
41-
42-
The Checkpoint handler provides a ``SAVED_CHECKPOINT`` event that fires after successful checkpoint saves.
43-
This allows users to attach custom handlers that react to checkpoint operations without manual event registration.
44-
45-
**Usage:**
46-
47-
.. code-block:: python
48-
49-
from ignite.handlers import Checkpoint
50-
from ignite.engine import Engine, Events
51-
52-
# Setup checkpoint handler
53-
checkpoint_handler = Checkpoint(
54-
{'model': model, 'optimizer': optimizer},
55-
save_dir,
56-
n_saved=2
57-
)
58-
59-
# Attach handler to checkpoint event (no manual registration needed)
60-
@trainer.on(Checkpoint.SAVED_CHECKPOINT)
61-
def on_checkpoint_saved(engine):
62-
print(f"Checkpoint saved at epoch {engine.state.epoch}")
63-
# Add custom logic: notifications, logging, etc.
64-
65-
trainer.add_event_handler(Events.EPOCH_COMPLETED, checkpoint_handler)
66-
67-
6838
Loggers
6939
--------
7040

ignite/handlers/checkpoint.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,29 @@ class Checkpoint(Serializable):
275275
to_save, save_handler=DiskSaver('/tmp/models', create_dir=True, **kwargs), n_saved=2
276276
)
277277
278+
Respond to checkpoint events:
279+
280+
.. code-block:: python
281+
282+
from ignite.handlers import Checkpoint
283+
from ignite.engine import Engine, Events
284+
285+
checkpoint_handler = Checkpoint(
286+
{'model': model, 'optimizer': optimizer},
287+
save_dir,
288+
n_saved=2
289+
)
290+
291+
@trainer.on(Checkpoint.SAVED_CHECKPOINT)
292+
def on_checkpoint_saved(engine):
293+
print(f"Checkpoint saved at epoch {engine.state.epoch}")
294+
295+
trainer.add_event_handler(Events.EPOCH_COMPLETED, checkpoint_handler)
296+
297+
Attributes:
298+
SAVED_CHECKPOINT: Alias of ``SAVED_CHECKPOINT`` from
299+
:class:`~ignite.handlers.checkpoint.CheckpointEvents`.
300+
278301
.. versionchanged:: 0.4.3
279302
280303
- Checkpoint can save model with same filename.
@@ -286,7 +309,7 @@ class Checkpoint(Serializable):
286309
- `save_handler` automatically saves to disk if path to directory is provided.
287310
- `save_on_rank` saves objects on this rank in a distributed configuration.
288311
289-
..
312+
..
290313
"""
291314

292315
SAVED_CHECKPOINT = CheckpointEvents.SAVED_CHECKPOINT

0 commit comments

Comments
 (0)