Customize checkpointing behavior (intermediate) — PyTorch Lightning 2.4.0 documentation
To save checkpoints based on a (when/which/what/where) condition (for example when the validation_loss is lower) modify the ModelCheckpoint properties. When using iterative training which doesn’t have an epoch, you can checkpoint at every N training steps by specifying every_n_train_steps=N. You can also control the interval of epochs between checkpoints using every_n_epochs, to avoid slowdowns. You can checkpoint at a regular time interval using the train_time_interval argument independent of the steps or epochs. In case you are monitoring a training metric, we’d suggest using save_on_train_epoch_end=True to ensure the required metric is being accumulated correctly for creating a checkpoint. You can save the last checkpoint when training ends using save_last argument. You can save top-K and last-K checkpoints by configuring the monitor and save_top_k argument. NOTE It is recommended that you pass formatting options to filename to include the monitored metric like shown in the example
Customize checkpointing behavior (intermediate) ¶ Audience: Users looking to customize the checkpointing behavior Modify checkpointing behavior ¶ For fine-grained control over checkpointing behavior, use the ModelCheckpoint object from lightning.pytorch.callbacks import ModelCheckpoint checkpoint_callback = ModelCheckpoint ( dirpath = "my/path/" , save_top_k = 2 , monitor = "val_loss" ) trainer = Trainer ( callbacks = [ checkpoint_callback ]) trainer . fit ( model ) # Access best and last model checkpoint directly from the callback print ( checkpoint_callback . best_model_path ) print ( checkp
Explore this link on the map →related reading
- ModelCheckpoint - PyTorch Lightning 2.6.1 documentationlightning.ai
- Saving and loading checkpoints (basic) - PyTorch Lightning 2.6.1 documentationlightning.ai
- Trainer - PyTorch Lightning 2.6.1 documentationlightning.ai
- LightningModule - PyTorch Lightning 2.6.1 documentationlightning.ai
- Get Started with Distributed Training using PyTorch Lightning — Ray 2.56.0docs.ray.io
- Current and New Activation Checkpointing Techniques in PyTorch – PyTorchpytorch.org
- ⚡ Migrating from PTL - Composerdocs.mosaicml.com
- Optimization - PyTorch Lightning 2.6.1 documentationlightning.ai
- Composer2.pdfcursor.com
- 👨👩👧👦 Distributed Training - Composerdocs.mosaicml.com
- Efficient LLM Finetuning with Unsloth | Modal Docsmodal.com
- ⏯️ Autoresume Training - Composerdocs.mosaicml.com