Lightning-AI/pytorch-lightning · error · MisconfigurationException
Trainer was configured with `enable_checkpointing=False` but
Error message
Trainer was configured with `enable_checkpointing=False` but found `ModelCheckpoint` in callbacks list.
What it means
Raised during Trainer initialization when enable_checkpointing=False is set but a ModelCheckpoint callback is present in the callbacks list. These are contradictory instructions, and Lightning treats the conflict as a user error instead of silently dropping the callback or overriding the flag.
Source
Thrown at src/lightning/pytorch/trainer/connectors/callback_connector.py:94
self._configure_timer_callback(max_time)
# init progress bar
self._configure_progress_bar(enable_progress_bar)
# configure the ModelSummary callback
self._configure_model_summary_callback(enable_model_summary)
self.trainer.callbacks.extend(_load_external_callbacks("lightning.pytorch.callbacks_factory"))
_validate_callbacks_list(self.trainer.callbacks)
# push all model checkpoint callbacks to the end
# it is important that these are the last callbacks to run
self.trainer.callbacks = self._reorder_callbacks(self.trainer.callbacks)
def _configure_checkpoint_callbacks(self, enable_checkpointing: bool) -> None:
if self.trainer.checkpoint_callbacks:
if not enable_checkpointing:
raise MisconfigurationException(
"Trainer was configured with `enable_checkpointing=False`"
" but found `ModelCheckpoint` in callbacks list."
)
elif enable_checkpointing:
if RequirementCache("litmodels >=0.1.7") and self.trainer._model_registry:
trainer_source = inspect.getmodule(self.trainer)
if trainer_source is None or not isinstance(trainer_source.__package__, str):
raise RuntimeError("Unable to determine the source of the trainer.")
# this need to imported based on the actual package lightning/pytorch_lightning
if "pytorch_lightning" in trainer_source.__package__:
from litmodels.integrations.checkpoints import PytorchLightningModelCheckpoint as LitModelCheckpoint
else:
from litmodels.integrations.checkpoints import LightningModelCheckpoint as LitModelCheckpoint
model_checkpoint = LitModelCheckpoint(model_registry=self.trainer._model_registry)
else:
# Defer the litmodels tip until loggers are set up (in _attach_model_callbacks)
self._pending_litmodels_tip = TrueView on GitHub (pinned to 9fed5c27d2)
Solutions
- Remove the ModelCheckpoint callback from callbacks when using enable_checkpointing=False
- Set enable_checkpointing=True (or omit it, default True) and configure ModelCheckpoint(...) with the desired dirpath/filename/monitor
- Filter the callback list programmatically before constructing the Trainer
Example fix
# before trainer = Trainer(enable_checkpointing=False, callbacks=[ModelCheckpoint(dirpath="ckpts")]) # after trainer = Trainer(enable_checkpointing=False, callbacks=[]) # or keep checkpointing on: trainer = Trainer(callbacks=[ModelCheckpoint(dirpath="ckpts", monitor="val_loss")])
Defensive patterns
Strategy: validation
Validate before calling
from lightning.pytorch.callbacks import ModelCheckpoint
def build_callbacks(enable_checkpointing: bool, extra):
cbs = list(extra)
if not enable_checkpointing:
cbs = [c for c in cbs if not isinstance(c, ModelCheckpoint)]
return cbs
trainer = Trainer(enable_checkpointing=False, callbacks=build_callbacks(False, my_callbacks)) Type guard
def checkpointing_is_consistent(enable_checkpointing: bool, callbacks) -> bool:
from lightning.pytorch.callbacks import ModelCheckpoint
has_ckpt_cb = any(isinstance(c, ModelCheckpoint) for c in callbacks)
return not (has_ckpt_cb and not enable_checkpointing) Prevention
- Single-source trainer construction via a factory that derives flags and callbacks together
- Never hand-build callback lists containing ModelCheckpoint when a disable flag is set
- Unit-test your trainer factory for flag/callback consistency
When it happens
Trigger: Calling Trainer(enable_checkpointing=False, callbacks=[ModelCheckpoint(...)]) or callbacks=[..., ModelCheckpoint()] while the flag disables default checkpointing; commonly happens when a shared callback list from another trainer is reused.
Common situations: Disabling checkpointing for a quick debug run while forgetting a ModelCheckpoint added earlier; copy-pasting trainer configs that include both the flag and the callback; libraries that inject ModelCheckpoint into the callbacks list.
Related errors
- Trainer was configured with `enable_progress_bar=False` but
- Found more than one stateful callback of type `{type(callbac
- You added multiple progress bar callbacks to the Trainer, bu
- Filter should be a dictionary, given {filter!r}
- The filter keys {filter.keys() - state} are not present in t
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/4197b7c0e23e7abd.
Report an issue: GitHub.