{"record":{"id":"4197b7c0e23e7abd","repo":"Lightning-AI/pytorch-lightning","slug":"trainer-was-configured-with-enable-checkpointing","errorCode":null,"errorMessage":"Trainer was configured with `enable_checkpointing=False` but found `ModelCheckpoint` in callbacks list.","messagePattern":"Trainer was configured with `enable_checkpointing=False` but found `ModelCheckpoint` in callbacks list\\.","errorType":"validation","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/trainer/connectors/callback_connector.py","lineNumber":94,"sourceCode":"        self._configure_timer_callback(max_time)\n\n        # init progress bar\n        self._configure_progress_bar(enable_progress_bar)\n\n        # configure the ModelSummary callback\n        self._configure_model_summary_callback(enable_model_summary)\n\n        self.trainer.callbacks.extend(_load_external_callbacks(\"lightning.pytorch.callbacks_factory\"))\n        _validate_callbacks_list(self.trainer.callbacks)\n\n        # push all model checkpoint callbacks to the end\n        # it is important that these are the last callbacks to run\n        self.trainer.callbacks = self._reorder_callbacks(self.trainer.callbacks)\n\n    def _configure_checkpoint_callbacks(self, enable_checkpointing: bool) -> None:\n        if self.trainer.checkpoint_callbacks:\n            if not enable_checkpointing:\n                raise MisconfigurationException(\n                    \"Trainer was configured with `enable_checkpointing=False`\"\n                    \" but found `ModelCheckpoint` in callbacks list.\"\n                )\n        elif enable_checkpointing:\n            if RequirementCache(\"litmodels >=0.1.7\") and self.trainer._model_registry:\n                trainer_source = inspect.getmodule(self.trainer)\n                if trainer_source is None or not isinstance(trainer_source.__package__, str):\n                    raise RuntimeError(\"Unable to determine the source of the trainer.\")\n                # this need to imported based on the actual package lightning/pytorch_lightning\n                if \"pytorch_lightning\" in trainer_source.__package__:\n                    from litmodels.integrations.checkpoints import PytorchLightningModelCheckpoint as LitModelCheckpoint\n                else:\n                    from litmodels.integrations.checkpoints import LightningModelCheckpoint as LitModelCheckpoint\n\n                model_checkpoint = LitModelCheckpoint(model_registry=self.trainer._model_registry)\n            else:\n                # Defer the litmodels tip until loggers are set up (in _attach_model_callbacks)\n                self._pending_litmodels_tip = True","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/trainer/connectors/callback_connector.py#L76-L112","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\ntrainer = Trainer(enable_checkpointing=False, callbacks=[ModelCheckpoint(dirpath=\"ckpts\")])\n# after\ntrainer = Trainer(enable_checkpointing=False, callbacks=[])\n# or keep checkpointing on:\ntrainer = Trainer(callbacks=[ModelCheckpoint(dirpath=\"ckpts\", monitor=\"val_loss\")])","handlingStrategy":"validation","validationCode":"from lightning.pytorch.callbacks import ModelCheckpoint\n\ndef build_callbacks(enable_checkpointing: bool, extra):\n    cbs = list(extra)\n    if not enable_checkpointing:\n        cbs = [c for c in cbs if not isinstance(c, ModelCheckpoint)]\n    return cbs\n\ntrainer = Trainer(enable_checkpointing=False, callbacks=build_callbacks(False, my_callbacks))","typeGuard":"def checkpointing_is_consistent(enable_checkpointing: bool, callbacks) -> bool:\n    from lightning.pytorch.callbacks import ModelCheckpoint\n    has_ckpt_cb = any(isinstance(c, ModelCheckpoint) for c in callbacks)\n    return not (has_ckpt_cb and not enable_checkpointing)","tryCatchPattern":null,"preventionTips":["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"],"tags":["lightning","trainer-init","checkpointing","callbacks","config-conflict"],"backgroundTag":"conflicting-trainer-options","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}