diff --git a/tests/backends/test_tpu_backend.py b/tests/backends/test_tpu_backend.py index cb8ffce38913a..63729f86ce862 100644 --- a/tests/backends/test_tpu_backend.py +++ b/tests/backends/test_tpu_backend.py @@ -39,7 +39,12 @@ def test_resume_training_on_cpu(tmpdir): assert weight_tensor.device == torch.device("cpu") # Verify that training is resumed on CPU - trainer = Trainer(resume_from_checkpoint=model_path, checkpoint_callback=True, max_epochs=1, default_root_dir=tmpdir) + trainer = Trainer( + resume_from_checkpoint=model_path, + checkpoint_callback=True, + max_epochs=1, + default_root_dir=tmpdir, + ) result = trainer.fit(model) assert result == 1 diff --git a/tests/callbacks/test_early_stopping.py b/tests/callbacks/test_early_stopping.py index b7711e8aae3fe..7cecefad03276 100644 --- a/tests/callbacks/test_early_stopping.py +++ b/tests/callbacks/test_early_stopping.py @@ -56,8 +56,7 @@ def test_resume_early_stopping_from_checkpoint(tmpdir): early_stop_callback = EarlyStoppingTestRestore() trainer = Trainer( default_root_dir=tmpdir, - checkpoint_callback=checkpoint_callback, - callbacks=[early_stop_callback], + callbacks=[early_stop_callback, checkpoint_callback], num_sanity_val_steps=0, max_epochs=4, ) diff --git a/tests/checkpointing/test_checkpoint_callback_frequency.py b/tests/checkpointing/test_checkpoint_callback_frequency.py index 0662cf7677431..857877f8239ba 100644 --- a/tests/checkpointing/test_checkpoint_callback_frequency.py +++ b/tests/checkpointing/test_checkpoint_callback_frequency.py @@ -129,7 +129,7 @@ def training_step(self, batch, batch_idx): model = TestModel() trainer = Trainer( - checkpoint_callback=callbacks.ModelCheckpoint(dirpath=tmpdir, monitor='my_loss', save_top_k=k), + callbacks=[callbacks.ModelCheckpoint(dirpath=tmpdir, monitor='my_loss', save_top_k=k)], default_root_dir=tmpdir, max_epochs=epochs, weights_summary=None, diff --git a/tests/checkpointing/test_model_checkpoint.py b/tests/checkpointing/test_model_checkpoint.py index 6d1d3edea5be9..31154eac1bf0d 100644 --- a/tests/checkpointing/test_model_checkpoint.py +++ b/tests/checkpointing/test_model_checkpoint.py @@ -897,7 +897,7 @@ def test_configure_model_checkpoint(tmpdir): assert trainer.checkpoint_callbacks == [callback1, callback2] with pytest.warns(DeprecationWarning, match='will no longer be supported in v1.3'): - trainer = Trainer(checkpoint_callback=callback1, callbacks=[], **kwargs) + trainer = Trainer(checkpoint_callback=callback1, **kwargs) assert [c for c in trainer.callbacks if isinstance(c, ModelCheckpoint)] == [callback1] assert trainer.checkpoint_callback == callback1 diff --git a/tests/core/test_datamodules.py b/tests/core/test_datamodules.py index c60553c9f8921..d286bbf3a9de6 100644 --- a/tests/core/test_datamodules.py +++ b/tests/core/test_datamodules.py @@ -243,7 +243,7 @@ def test_dm_checkpoint_save(tmpdir): default_root_dir=tmpdir, max_epochs=3, weights_summary=None, - checkpoint_callback=ModelCheckpoint(dirpath=tmpdir, monitor='early_stop_on') + callbacks=[ModelCheckpoint(dirpath=tmpdir, monitor='early_stop_on')], ) # fit model diff --git a/tests/models/data/horovod/train_default_model.py b/tests/models/data/horovod/train_default_model.py index b6900e322f0bb..f10753491d447 100644 --- a/tests/models/data/horovod/train_default_model.py +++ b/tests/models/data/horovod/train_default_model.py @@ -49,7 +49,7 @@ def run_test_from_config(trainer_options): reset_seed() ckpt_path = trainer_options['weights_save_path'] - trainer_options.update(checkpoint_callback=ModelCheckpoint(dirpath=ckpt_path)) + trainer_options.update(callbacks=[ModelCheckpoint(dirpath=ckpt_path)]) model = EvalModelTemplate() diff --git a/tests/models/test_amp.py b/tests/models/test_amp.py index 79238c92e712d..269a2069e4266 100644 --- a/tests/models/test_amp.py +++ b/tests/models/test_amp.py @@ -129,7 +129,7 @@ def test_amp_gpu_ddp_slurm_managed(tmpdir): gpus=[0], accelerator='ddp_spawn', precision=16, - checkpoint_callback=checkpoint, + callbacks=[checkpoint], logger=logger, ) trainer.is_slurm_managing_tasks = True diff --git a/tests/models/test_cpu.py b/tests/models/test_cpu.py index f8403e460d327..2848ab2e74f3c 100644 --- a/tests/models/test_cpu.py +++ b/tests/models/test_cpu.py @@ -43,7 +43,7 @@ def test_cpu_slurm_save_load(enable_pl_optimizer, tmpdir): logger=logger, limit_train_batches=0.2, limit_val_batches=0.2, - checkpoint_callback=ModelCheckpoint(dirpath=tmpdir), + callbacks=[ModelCheckpoint(dirpath=tmpdir)], enable_pl_optimizer=enable_pl_optimizer, ) result = trainer.fit(model) @@ -80,7 +80,7 @@ def test_cpu_slurm_save_load(enable_pl_optimizer, tmpdir): default_root_dir=tmpdir, max_epochs=1, logger=logger, - checkpoint_callback=ModelCheckpoint(dirpath=tmpdir), + callbacks=[ModelCheckpoint(dirpath=tmpdir)], enable_pl_optimizer=enable_pl_optimizer, ) model = EvalModelTemplate(**hparams) @@ -208,7 +208,7 @@ def test_running_test_after_fitting(tmpdir): limit_train_batches=0.4, limit_val_batches=0.2, limit_test_batches=0.2, - checkpoint_callback=checkpoint, + callbacks=[checkpoint], logger=logger, ) result = trainer.fit(model) @@ -239,7 +239,7 @@ def test_running_test_no_val(tmpdir): limit_train_batches=0.4, limit_val_batches=0.2, limit_test_batches=0.2, - checkpoint_callback=checkpoint, + callbacks=[checkpoint], logger=logger, ) result = trainer.fit(model) diff --git a/tests/models/test_restore.py b/tests/models/test_restore.py index e8703b9496f65..17821570bdfa7 100644 --- a/tests/models/test_restore.py +++ b/tests/models/test_restore.py @@ -159,7 +159,7 @@ def test_running_test_pretrained_model_distrib_dp(tmpdir): max_epochs=2, limit_train_batches=0.4, limit_val_batches=0.2, - checkpoint_callback=checkpoint, + callbacks=[checkpoint], logger=logger, gpus=[0, 1], accelerator='dp', @@ -209,7 +209,7 @@ def test_running_test_pretrained_model_distrib_ddp_spawn(tmpdir): max_epochs=2, limit_train_batches=0.4, limit_val_batches=0.2, - checkpoint_callback=checkpoint, + callbacks=[checkpoint], logger=logger, gpus=[0, 1], accelerator='ddp_spawn', @@ -257,7 +257,7 @@ def test_running_test_pretrained_model_cpu(tmpdir): max_epochs=3, limit_train_batches=0.4, limit_val_batches=0.2, - checkpoint_callback=checkpoint, + callbacks=[checkpoint], logger=logger, default_root_dir=tmpdir, ) @@ -288,7 +288,7 @@ def test_load_model_from_checkpoint(tmpdir, model_template): max_epochs=2, limit_train_batches=0.4, limit_val_batches=0.2, - checkpoint_callback=ModelCheckpoint(dirpath=tmpdir, monitor='early_stop_on', save_top_k=-1), + callbacks=[ModelCheckpoint(dirpath=tmpdir, monitor='early_stop_on', save_top_k=-1)], default_root_dir=tmpdir, ) @@ -404,8 +404,10 @@ def test_model_saving_loading(tmpdir): # fit model trainer = Trainer( - max_epochs=1, logger=logger, - checkpoint_callback=ModelCheckpoint(dirpath=tmpdir), default_root_dir=tmpdir, + max_epochs=1, + logger=logger, + callbacks=[ModelCheckpoint(dirpath=tmpdir)], + default_root_dir=tmpdir, ) result = trainer.fit(model) @@ -460,7 +462,7 @@ def test_strict_model_load_more_params(monkeypatch, tmpdir, tmpdir_server, url_c # fit model trainer = Trainer( default_root_dir=tmpdir, max_epochs=1, logger=logger, - checkpoint_callback=ModelCheckpoint(dirpath=tmpdir), + callbacks=[ModelCheckpoint(dirpath=tmpdir)], ) result = trainer.fit(model) @@ -500,7 +502,7 @@ def test_strict_model_load_less_params(monkeypatch, tmpdir, tmpdir_server, url_c # fit model trainer = Trainer( default_root_dir=tmpdir, max_epochs=1, logger=logger, - checkpoint_callback=ModelCheckpoint(dirpath=tmpdir), + callbacks=[ModelCheckpoint(dirpath=tmpdir)], ) result = trainer.fit(model) diff --git a/tests/trainer/logging_tests/test_eval_loop_logging_1_0.py b/tests/trainer/logging_tests/test_eval_loop_logging_1_0.py index 1a928913228f2..76baa9237955f 100644 --- a/tests/trainer/logging_tests/test_eval_loop_logging_1_0.py +++ b/tests/trainer/logging_tests/test_eval_loop_logging_1_0.py @@ -26,6 +26,7 @@ from torch.utils.data import DataLoader, Dataset from pytorch_lightning import Trainer, callbacks, seed_everything +from pytorch_lightning.callbacks import ModelCheckpoint from pytorch_lightning.core.lightning import LightningModule from pytorch_lightning.loggers import TensorBoardLogger from tests.base import BoringModel, RandomDataset, SimpleModule @@ -291,7 +292,7 @@ def validation_epoch_end(self, outputs) -> None: max_epochs=1, log_every_n_steps=1, weights_summary=None, - checkpoint_callback=callbacks.ModelCheckpoint(dirpath='val_loss') + callbacks=[ModelCheckpoint(dirpath='val_loss')], ) trainer.fit(model) @@ -358,7 +359,7 @@ def test_monitor_val_epoch_end(tmpdir): trainer = Trainer( max_epochs=epoch_min_loss_override + 2, logger=False, - checkpoint_callback=checkpoint_callback, + callbacks=[checkpoint_callback], ) trainer.fit(model) diff --git a/tests/trainer/logging_tests/test_train_loop_logging_1_0.py b/tests/trainer/logging_tests/test_train_loop_logging_1_0.py index c148748888af4..0c27d8909d760 100644 --- a/tests/trainer/logging_tests/test_train_loop_logging_1_0.py +++ b/tests/trainer/logging_tests/test_train_loop_logging_1_0.py @@ -27,6 +27,7 @@ import pytorch_lightning as pl from pytorch_lightning import Trainer, callbacks +from pytorch_lightning.callbacks import ModelCheckpoint from pytorch_lightning.core.lightning import LightningModule from tests.base.boring_model import BoringModel, RandomDictDataset, RandomDictStringDataset from tests.base.deterministic_model import DeterministicModel @@ -88,7 +89,7 @@ def backward(self, loss, optimizer, optimizer_idx): max_epochs=2, log_every_n_steps=1, weights_summary=None, - checkpoint_callback=callbacks.ModelCheckpoint(monitor='l_se') + callbacks=[ModelCheckpoint(monitor='l_se')], ) trainer.fit(model) diff --git a/tests/trainer/test_trainer.py b/tests/trainer/test_trainer.py index b7db30e398535..1bacbdb2d0440 100644 --- a/tests/trainer/test_trainer.py +++ b/tests/trainer/test_trainer.py @@ -55,7 +55,7 @@ def test_no_val_module(monkeypatch, tmpdir, tmpdir_server, url_ckpt): default_root_dir=tmpdir, max_epochs=1, logger=logger, - checkpoint_callback=ModelCheckpoint(dirpath=tmpdir), + callbacks=[ModelCheckpoint(dirpath=tmpdir)], ) # fit model result = trainer.fit(model) @@ -101,7 +101,7 @@ def test_no_val_end_module(monkeypatch, tmpdir, tmpdir_server, url_ckpt): default_root_dir=tmpdir, max_epochs=1, logger=logger, - checkpoint_callback=ModelCheckpoint(dirpath=tmpdir), + callbacks=[ModelCheckpoint(dirpath=tmpdir)], ) result = trainer.fit(model) @@ -145,7 +145,7 @@ def test_strict_model_load(monkeypatch, tmpdir, tmpdir_server, url_ckpt): default_root_dir=tmpdir, max_epochs=1, logger=logger, - checkpoint_callback=ModelCheckpoint(dirpath=tmpdir), + callbacks=[ModelCheckpoint(dirpath=tmpdir)], ) result = trainer.fit(model) @@ -462,7 +462,7 @@ def test_model_checkpoint_only_weights(tmpdir): trainer = Trainer( default_root_dir=tmpdir, max_epochs=1, - checkpoint_callback=ModelCheckpoint(dirpath=tmpdir, monitor='early_stop_on', save_weights_only=True), + callbacks=[ModelCheckpoint(dirpath=tmpdir, monitor='early_stop_on', save_weights_only=True)], ) # fit model result = trainer.fit(model) @@ -539,7 +539,7 @@ def increment_on_load_checkpoint(self, _): max_epochs=2, limit_train_batches=0.65, limit_val_batches=1, - checkpoint_callback=ModelCheckpoint(dirpath=tmpdir, monitor='early_stop_on', save_top_k=-1), + callbacks=[ModelCheckpoint(dirpath=tmpdir, monitor='early_stop_on', save_top_k=-1)], default_root_dir=tmpdir, val_check_interval=1.0, enable_pl_optimizer=enable_pl_optimizer, @@ -718,7 +718,7 @@ def test_test_checkpoint_path(tmpdir, ckpt_path, save_top_k): max_epochs=2, progress_bar_refresh_rate=0, default_root_dir=tmpdir, - checkpoint_callback=ModelCheckpoint(monitor="early_stop_on", save_top_k=save_top_k), + callbacks=[ModelCheckpoint(monitor="early_stop_on", save_top_k=save_top_k)], ) trainer.fit(model) if ckpt_path == "best":