Repository: Lightning-AI/pytorch-lightning

Issue:
Epoch counting is one-off in multiple instances
🐛 Bug

Two issues occur:

1. The final epoch does not save a checkpoint during training.
2. Resuming from a checkpoint N will start the epochs at N+2.

### Expected behavior

1. Final checkpoint should save a .ckpt file, as usual.
2. Should resume from epoch N+1.

### Environment

```
* CUDA:
	- GPU:
		- Tesla V100-DGXS-16GB
		- Tesla V100-DGXS-16GB
		- Tesla V100-DGXS-16GB
		- Tesla V100-DGXS-16GB
	- available:         True
	- version:           10.1
* Packages:
	- numpy:             1.18.1
	- pyTorch_debug:     False
	- pyTorch_version:   1.6.0
	- pytorch-lightning: 0.9.0rc12
	- tensorboard:       2.2.1
	- tqdm:              4.46.1
* System:
	- OS:                Linux
	- architecture:
		- 64bit
		-
	- processor:         x86_64
	- python:            3.7.7
	- version:           #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020
```



Discussion:
@AAnoosheh Honestly I do not understand how the PR you linked relates to the bug your report. Did you mean to link another issue? 

> The final epoch does not save a checkpoint during training.

I don't experience this. The epoch number is 0-indexed, and by default it only saves best checkpoints. Could one of these reasons be why you may think this is a bug?

How can I reproduce the second issue?
Sorry I should have clarified I use the following to save every epoch:

`pl.callbacks.ModelCheckpoint(save_top_k=-1, verbose=True)`

The second is done via `Trainer(resume_from_checkpoint=some_ckpt_file)`

I assume some change was made to move epochs to 0-index, when previously they were 1-indexed, and there's a mismatch now.

EDIT:
I also have no idea how a PR was linked in my comment. Those numbers came out of nowhere from the auto-generated issue template.
@AAnoosheh so when you run ```pl.callbacks.ModelCheckpoint(save_top_k=-1, verbose=True)``` all the checkpoints are saved, however we do not save the last one as 'last.ckpt'. Also, the checkpoints are numbered from 0, so if you run for 4 epochs, the last checkpoint saved will be 'epoch=3.ckpt' and when you resume, it resumes from the expected 5th epoch. 

Updating tests and code for this

Resolving patch:
diff --git a/pytorch_lightning/callbacks/progress.py b/pytorch_lightning/callbacks/progress.py
--- a/pytorch_lightning/callbacks/progress.py
+++ b/pytorch_lightning/callbacks/progress.py
@@ -99,7 +99,7 @@ def total_val_batches(self) -> int:
         """
         total_val_batches = 0
         if not self.trainer.disable_validation:
-            is_val_epoch = (self.trainer.current_epoch + 1) % self.trainer.check_val_every_n_epoch == 0
+            is_val_epoch = (self.trainer.current_epoch) % self.trainer.check_val_every_n_epoch == 0
             total_val_batches = sum(self.trainer.num_val_batches) if is_val_epoch else 0
         return total_val_batches
 
@@ -316,7 +316,7 @@ def on_epoch_start(self, trainer, pl_module):
         total_batches = total_train_batches + total_val_batches
         if not self.main_progress_bar.disable:
             self.main_progress_bar.reset(convert_inf(total_batches))
-        self.main_progress_bar.set_description(f'Epoch {trainer.current_epoch + 1}')
+        self.main_progress_bar.set_description(f'Epoch {trainer.current_epoch}')
 
     def on_train_batch_end(self, trainer, pl_module, batch, batch_idx, dataloader_idx):
         super().on_train_batch_end(trainer, pl_module, batch, batch_idx, dataloader_idx)


Test patch: