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

Delete checkpoint_connector.has_trained #8292

Merged
merged 1 commit into from
Jul 7, 2021
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
1 change: 0 additions & 1 deletion pytorch_lightning/loops/epoch/training_epoch_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ def on_advance_end(self):

# update plateau LR scheduler after metrics are logged
self.update_lr_schedulers('step', update_plateau_schedulers=True)
self.trainer.checkpoint_connector.has_trained = True

self.total_batch_idx += 1

Expand Down
2 changes: 1 addition & 1 deletion pytorch_lightning/loops/fit_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def should_accumulate(self) -> bool:
def _check_checkpoint_callback(self, should_update: bool, is_last: bool = False):
"""Checks if checkpointing needs to be done"""
# TODO: bake this logic into the ModelCheckpoint callback
if should_update and self.trainer.checkpoint_connector.has_trained:
carmocca marked this conversation as resolved.
Show resolved Hide resolved
if should_update:
callbacks = self.trainer.checkpoint_callbacks

if is_last and any(cb.save_last and cb.verbose for cb in callbacks):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class CheckpointConnector:
def __init__(self, trainer, resume_from_checkpoint: Optional[Union[str, Path]] = None):
self.trainer = trainer
self.resume_checkpoint_path = resume_from_checkpoint
# used to validate checkpointing logic
self.has_trained = False
self._loaded_checkpoint = dict()

@property
Expand Down
2 changes: 0 additions & 2 deletions pytorch_lightning/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,8 +959,6 @@ def _run_train(self) -> None:

self._run_sanity_check(self.lightning_module)

self.checkpoint_connector.has_trained = False

# enable train mode
self.model.train()
torch.set_grad_enabled(True)
Expand Down
5 changes: 0 additions & 5 deletions tests/checkpointing/test_model_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,6 @@ def validation_epoch_end(self, *_):
...

def assert_trainer_init(trainer):
assert not trainer.checkpoint_connector.has_trained
assert trainer.global_step == 0
assert trainer.current_epoch == 0

Expand Down Expand Up @@ -1057,7 +1056,6 @@ def assert_checkpoint_log_dir(idx):

model = ExtendedBoringModel()
trainer.fit(model)
assert trainer.checkpoint_connector.has_trained
assert trainer.global_step == epochs * limit_train_batches
assert trainer.current_epoch == epochs - 1
assert_checkpoint_log_dir(0)
Expand All @@ -1081,19 +1079,16 @@ def assert_checkpoint_log_dir(idx):
model = ExtendedBoringModel()

trainer.test(model)
assert not trainer.checkpoint_connector.has_trained
# resume_from_checkpoint is resumed when calling `.fit`
assert trainer.global_step == 0
assert trainer.current_epoch == 0

trainer.fit(model)
assert not trainer.checkpoint_connector.has_trained
assert trainer.global_step == epochs * limit_train_batches
assert trainer.current_epoch == epochs
assert_checkpoint_log_dir(idx)

trainer.validate(model)
assert not trainer.checkpoint_connector.has_trained
assert trainer.global_step == epochs * limit_train_batches
assert trainer.current_epoch == epochs

Expand Down