Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated checkpoint_callback flag in Trainer #13027

Merged
merged 7 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Removed

- Removed the deprecated `checkpoint_callback` argument from the `Trainer` constructor ([#13027](https://github.com/PyTorchLightning/pytorch-lightning/pull/13027))


- Removed the deprecated `TestTubeLogger` ([#12859](https://github.com/PyTorchLightning/pytorch-lightning/pull/12859))


Expand Down
6 changes: 0 additions & 6 deletions docs/source/common/trainer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,6 @@ Example::
# run val loop every 10 training epochs
trainer = Trainer(check_val_every_n_epoch=10)

checkpoint_callback
^^^^^^^^^^^^^^^^^^^

.. warning:: `checkpoint_callback` has been deprecated in v1.5 and will be removed in v1.7.
To disable checkpointing, pass ``enable_checkpointing = False`` to the Trainer instead.


default_root_dir
^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion legacy/simple_classif_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ def main_train(dir_path, max_epochs: int = 20):
default_root_dir=dir_path,
gpus=int(torch.cuda.is_available()),
precision=(16 if torch.cuda.is_available() else 32),
checkpoint_callback=True,
callbacks=[stopping],
min_epochs=3,
max_epochs=max_epochs,
Expand Down
13 changes: 2 additions & 11 deletions pytorch_lightning/trainer/connectors/callback_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def __init__(self, trainer):
def on_trainer_init(
self,
callbacks: Optional[Union[List[Callback], Callback]],
checkpoint_callback: Optional[bool],
enable_checkpointing: bool,
enable_progress_bar: bool,
process_position: int,
Expand Down Expand Up @@ -71,7 +70,7 @@ def on_trainer_init(

# configure checkpoint callback
# pass through the required args to figure out defaults
self._configure_checkpoint_callbacks(checkpoint_callback, enable_checkpointing)
self._configure_checkpoint_callbacks(enable_checkpointing)

# configure the timer callback.
# responsible to stop the training when max_time is reached.
Expand Down Expand Up @@ -133,15 +132,7 @@ def _configure_accumulated_gradients(
self.trainer.accumulate_grad_batches = grad_accum_callback.get_accumulate_grad_batches(0)
self.trainer.accumulation_scheduler = grad_accum_callback

def _configure_checkpoint_callbacks(self, checkpoint_callback: Optional[bool], enable_checkpointing: bool) -> None:
if checkpoint_callback is not None:
rank_zero_deprecation(
f"Setting `Trainer(checkpoint_callback={checkpoint_callback})` is deprecated in v1.5 and will "
f"be removed in v1.7. Please consider using `Trainer(enable_checkpointing={checkpoint_callback})`."
)
# if both are set then checkpoint only if both are True
enable_checkpointing = checkpoint_callback and enable_checkpointing

def _configure_checkpoint_callbacks(self, enable_checkpointing: bool) -> None:
if self.trainer.checkpoint_callbacks:
if not enable_checkpointing:
raise MisconfigurationException(
Expand Down
9 changes: 0 additions & 9 deletions pytorch_lightning/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class Trainer(
def __init__(
self,
logger: Union[Logger, Iterable[Logger], bool] = True,
checkpoint_callback: Optional[bool] = None,
enable_checkpointing: bool = True,
callbacks: Optional[Union[List[Callback], Callback]] = None,
default_root_dir: Optional[str] = None,
Expand Down Expand Up @@ -234,13 +233,6 @@ def __init__(
callbacks: Add a callback or list of callbacks.
Default: ``None``.

checkpoint_callback: If ``True``, enable checkpointing.
Default: ``None``.

.. deprecated:: v1.5
``checkpoint_callback`` has been deprecated in v1.5 and will be removed in v1.7.
Please consider using ``enable_checkpointing`` instead.

enable_checkpointing: If ``True``, enable checkpointing.
It will configure a default ModelCheckpoint callback if there is no user-defined ModelCheckpoint in
:paramref:`~pytorch_lightning.trainer.trainer.Trainer.callbacks`.
Expand Down Expand Up @@ -514,7 +506,6 @@ def __init__(
# Declare attributes to be set in _callback_connector on_trainer_init
self._callback_connector.on_trainer_init(
callbacks,
checkpoint_callback,
enable_checkpointing,
enable_progress_bar,
process_position,
Expand Down
5 changes: 0 additions & 5 deletions tests/deprecated_api/test_remove_1-7.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,6 @@ def test_v1_7_0_deprecate_lightning_distributed(tmpdir):
_ = LightningDistributed()


def test_v1_7_0_checkpoint_callback_trainer_constructor(tmpdir):
with pytest.deprecated_call(match=r"Setting `Trainer\(checkpoint_callback=True\)` is deprecated in v1.5"):
_ = Trainer(checkpoint_callback=True)


def test_v1_7_0_deprecate_on_post_move_to_device(tmpdir):
class TestModel(BoringModel):
def on_post_move_to_device(self):
Expand Down