Skip to content

Commit 05f25f3

Browse files
authored
update usage of deprecated checkpoint_callback (#5006)
* drop usage of deprecated checkpoint_callback * fix * fix
1 parent ce91795 commit 05f25f3

12 files changed

+37
-29
lines changed

tests/backends/test_tpu_backend.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ def test_resume_training_on_cpu(tmpdir):
3939
assert weight_tensor.device == torch.device("cpu")
4040

4141
# Verify that training is resumed on CPU
42-
trainer = Trainer(resume_from_checkpoint=model_path, checkpoint_callback=True, max_epochs=1, default_root_dir=tmpdir)
42+
trainer = Trainer(
43+
resume_from_checkpoint=model_path,
44+
checkpoint_callback=True,
45+
max_epochs=1,
46+
default_root_dir=tmpdir,
47+
)
4348
result = trainer.fit(model)
4449

4550
assert result == 1

tests/callbacks/test_early_stopping.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ def test_resume_early_stopping_from_checkpoint(tmpdir):
5656
early_stop_callback = EarlyStoppingTestRestore()
5757
trainer = Trainer(
5858
default_root_dir=tmpdir,
59-
checkpoint_callback=checkpoint_callback,
60-
callbacks=[early_stop_callback],
59+
callbacks=[early_stop_callback, checkpoint_callback],
6160
num_sanity_val_steps=0,
6261
max_epochs=4,
6362
)

tests/checkpointing/test_checkpoint_callback_frequency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def training_step(self, batch, batch_idx):
129129

130130
model = TestModel()
131131
trainer = Trainer(
132-
checkpoint_callback=callbacks.ModelCheckpoint(dirpath=tmpdir, monitor='my_loss', save_top_k=k),
132+
callbacks=[callbacks.ModelCheckpoint(dirpath=tmpdir, monitor='my_loss', save_top_k=k)],
133133
default_root_dir=tmpdir,
134134
max_epochs=epochs,
135135
weights_summary=None,

tests/checkpointing/test_model_checkpoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ def test_configure_model_checkpoint(tmpdir):
897897
assert trainer.checkpoint_callbacks == [callback1, callback2]
898898

899899
with pytest.warns(DeprecationWarning, match='will no longer be supported in v1.3'):
900-
trainer = Trainer(checkpoint_callback=callback1, callbacks=[], **kwargs)
900+
trainer = Trainer(checkpoint_callback=callback1, **kwargs)
901901
assert [c for c in trainer.callbacks if isinstance(c, ModelCheckpoint)] == [callback1]
902902
assert trainer.checkpoint_callback == callback1
903903

tests/core/test_datamodules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def test_dm_checkpoint_save(tmpdir):
243243
default_root_dir=tmpdir,
244244
max_epochs=3,
245245
weights_summary=None,
246-
checkpoint_callback=ModelCheckpoint(dirpath=tmpdir, monitor='early_stop_on')
246+
callbacks=[ModelCheckpoint(dirpath=tmpdir, monitor='early_stop_on')],
247247
)
248248

249249
# fit model

tests/models/data/horovod/train_default_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def run_test_from_config(trainer_options):
4949
reset_seed()
5050

5151
ckpt_path = trainer_options['weights_save_path']
52-
trainer_options.update(checkpoint_callback=ModelCheckpoint(dirpath=ckpt_path))
52+
trainer_options.update(callbacks=[ModelCheckpoint(dirpath=ckpt_path)])
5353

5454
model = EvalModelTemplate()
5555

tests/models/test_amp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def test_amp_gpu_ddp_slurm_managed(tmpdir):
129129
gpus=[0],
130130
accelerator='ddp_spawn',
131131
precision=16,
132-
checkpoint_callback=checkpoint,
132+
callbacks=[checkpoint],
133133
logger=logger,
134134
)
135135
trainer.is_slurm_managing_tasks = True

tests/models/test_cpu.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_cpu_slurm_save_load(enable_pl_optimizer, tmpdir):
4343
logger=logger,
4444
limit_train_batches=0.2,
4545
limit_val_batches=0.2,
46-
checkpoint_callback=ModelCheckpoint(dirpath=tmpdir),
46+
callbacks=[ModelCheckpoint(dirpath=tmpdir)],
4747
enable_pl_optimizer=enable_pl_optimizer,
4848
)
4949
result = trainer.fit(model)
@@ -80,7 +80,7 @@ def test_cpu_slurm_save_load(enable_pl_optimizer, tmpdir):
8080
default_root_dir=tmpdir,
8181
max_epochs=1,
8282
logger=logger,
83-
checkpoint_callback=ModelCheckpoint(dirpath=tmpdir),
83+
callbacks=[ModelCheckpoint(dirpath=tmpdir)],
8484
enable_pl_optimizer=enable_pl_optimizer,
8585
)
8686
model = EvalModelTemplate(**hparams)
@@ -208,7 +208,7 @@ def test_running_test_after_fitting(tmpdir):
208208
limit_train_batches=0.4,
209209
limit_val_batches=0.2,
210210
limit_test_batches=0.2,
211-
checkpoint_callback=checkpoint,
211+
callbacks=[checkpoint],
212212
logger=logger,
213213
)
214214
result = trainer.fit(model)
@@ -239,7 +239,7 @@ def test_running_test_no_val(tmpdir):
239239
limit_train_batches=0.4,
240240
limit_val_batches=0.2,
241241
limit_test_batches=0.2,
242-
checkpoint_callback=checkpoint,
242+
callbacks=[checkpoint],
243243
logger=logger,
244244
)
245245
result = trainer.fit(model)

tests/models/test_restore.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def test_running_test_pretrained_model_distrib_dp(tmpdir):
159159
max_epochs=2,
160160
limit_train_batches=0.4,
161161
limit_val_batches=0.2,
162-
checkpoint_callback=checkpoint,
162+
callbacks=[checkpoint],
163163
logger=logger,
164164
gpus=[0, 1],
165165
accelerator='dp',
@@ -209,7 +209,7 @@ def test_running_test_pretrained_model_distrib_ddp_spawn(tmpdir):
209209
max_epochs=2,
210210
limit_train_batches=0.4,
211211
limit_val_batches=0.2,
212-
checkpoint_callback=checkpoint,
212+
callbacks=[checkpoint],
213213
logger=logger,
214214
gpus=[0, 1],
215215
accelerator='ddp_spawn',
@@ -257,7 +257,7 @@ def test_running_test_pretrained_model_cpu(tmpdir):
257257
max_epochs=3,
258258
limit_train_batches=0.4,
259259
limit_val_batches=0.2,
260-
checkpoint_callback=checkpoint,
260+
callbacks=[checkpoint],
261261
logger=logger,
262262
default_root_dir=tmpdir,
263263
)
@@ -288,7 +288,7 @@ def test_load_model_from_checkpoint(tmpdir, model_template):
288288
max_epochs=2,
289289
limit_train_batches=0.4,
290290
limit_val_batches=0.2,
291-
checkpoint_callback=ModelCheckpoint(dirpath=tmpdir, monitor='early_stop_on', save_top_k=-1),
291+
callbacks=[ModelCheckpoint(dirpath=tmpdir, monitor='early_stop_on', save_top_k=-1)],
292292
default_root_dir=tmpdir,
293293
)
294294

@@ -404,8 +404,10 @@ def test_model_saving_loading(tmpdir):
404404

405405
# fit model
406406
trainer = Trainer(
407-
max_epochs=1, logger=logger,
408-
checkpoint_callback=ModelCheckpoint(dirpath=tmpdir), default_root_dir=tmpdir,
407+
max_epochs=1,
408+
logger=logger,
409+
callbacks=[ModelCheckpoint(dirpath=tmpdir)],
410+
default_root_dir=tmpdir,
409411
)
410412
result = trainer.fit(model)
411413

@@ -460,7 +462,7 @@ def test_strict_model_load_more_params(monkeypatch, tmpdir, tmpdir_server, url_c
460462
# fit model
461463
trainer = Trainer(
462464
default_root_dir=tmpdir, max_epochs=1, logger=logger,
463-
checkpoint_callback=ModelCheckpoint(dirpath=tmpdir),
465+
callbacks=[ModelCheckpoint(dirpath=tmpdir)],
464466
)
465467
result = trainer.fit(model)
466468

@@ -500,7 +502,7 @@ def test_strict_model_load_less_params(monkeypatch, tmpdir, tmpdir_server, url_c
500502
# fit model
501503
trainer = Trainer(
502504
default_root_dir=tmpdir, max_epochs=1, logger=logger,
503-
checkpoint_callback=ModelCheckpoint(dirpath=tmpdir),
505+
callbacks=[ModelCheckpoint(dirpath=tmpdir)],
504506
)
505507
result = trainer.fit(model)
506508

tests/trainer/logging_tests/test_eval_loop_logging_1_0.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from torch.utils.data import DataLoader, Dataset
2727

2828
from pytorch_lightning import Trainer, callbacks, seed_everything
29+
from pytorch_lightning.callbacks import ModelCheckpoint
2930
from pytorch_lightning.core.lightning import LightningModule
3031
from pytorch_lightning.loggers import TensorBoardLogger
3132
from tests.base import BoringModel, RandomDataset, SimpleModule
@@ -291,7 +292,7 @@ def validation_epoch_end(self, outputs) -> None:
291292
max_epochs=1,
292293
log_every_n_steps=1,
293294
weights_summary=None,
294-
checkpoint_callback=callbacks.ModelCheckpoint(dirpath='val_loss')
295+
callbacks=[ModelCheckpoint(dirpath='val_loss')],
295296
)
296297
trainer.fit(model)
297298

@@ -358,7 +359,7 @@ def test_monitor_val_epoch_end(tmpdir):
358359
trainer = Trainer(
359360
max_epochs=epoch_min_loss_override + 2,
360361
logger=False,
361-
checkpoint_callback=checkpoint_callback,
362+
callbacks=[checkpoint_callback],
362363
)
363364
trainer.fit(model)
364365

0 commit comments

Comments
 (0)