Strange validation_step and global_step behavior after every epoch
🐛 Bug

The following was produced with the BoringModel provided. With val_check_interval=10, last validation_step of first epoch was at global_step=59 and first validation_step of second epoch was at global_step=73, and so on. It seems like it is always off by len(dataset) % val_check_interval every time after an epoch. I think it is because the counter resets per epoch. In this case, the length of dataset is 64 and val_check_interval is 10. After the last validation_step in the first epoch at global_step=59, the first epoch ended at global_step=63, the counter resets and so the first validation_step of second epoch is at global_step=73.
Also, a while back I submitted an issue also related to val_check_interval. I think it would be nice to be able to log training_step and validation_step at the same global_step. My suggestion is to simply trigger validation_step when global_step % val_check_interval == 0, so in training_step we can manually trigger logging (for example, logging images) with this simple global_step % val_check_interval == 0 condition. This would greatly help debug models and plot graphs that training and validation logs are aligned. Thanks in advance :)
validation_step at global_step =  0
override any method to prove your bug
validation_step at global_step =  9
validation_step at global_step =  19
validation_step at global_step =  29
validation_step at global_step =  39
validation_step at global_step =  49
validation_step at global_step =  59
override any method to prove your bug
validation_step at global_step =  73
validation_step at global_step =  83
validation_step at global_step =  93
validation_step at global_step =  103
validation_step at global_step =  113
validation_step at global_step =  123
override any method to prove your bug
validation_step at global_step =  137
validation_step at global_step =  147
validation_step at global_step =  157
validation_step at global_step =  167
validation_step at global_step =  177
validation_step at global_step =  187
override any method to prove your bug
validation_step at global_step =  201
validation_step at global_step =  211
validation_step at global_step =  221
validation_step at global_step =  231
validation_step at global_step =  241
validation_step at global_step =  251
override any method to prove your bug
validation_step at global_step =  265
validation_step at global_step =  275
validation_step at global_step =  285
validation_step at global_step =  295
validation_step at global_step =  305
validation_step at global_step =  315
Please reproduce using the BoringModel and post here

# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# --------------------------------------------
# --------------------------------------------
# --------------------------------------------
# USE THIS MODEL TO REPRODUCE A BUG YOU REPORT
# --------------------------------------------
# --------------------------------------------
# --------------------------------------------
import os
import torch
from torch.utils.data import Dataset
from pytorch_lightning import Trainer, LightningModule


class RandomDataset(Dataset):
    def __init__(self, size, length):
        self.len = length
        self.data = torch.randn(length, size)

    def __getitem__(self, index):
        return self.data[index]

    def __len__(self):
        return self.len


class BoringModel(LightningModule):

    def __init__(self):
        """
        Testing PL Module
        Use as follows:
        - subclass
        - modify the behavior for what you want
        class TestModel(BaseTestModel):
            def training_step(...):
                # do your own thing
        or:
        model = BaseTestModel()
        model.training_epoch_end = None
        """
        super().__init__()
        self.layer = torch.nn.Linear(32, 2)

    def forward(self, x):
        return self.layer(x)

    def loss(self, batch, prediction):
        # An arbitrary loss to have a loss that updates the model weights during `Trainer.fit` calls
        return torch.nn.functional.mse_loss(prediction, torch.ones_like(prediction))

    def step(self, x):
        x = self.layer(x)
        out = torch.nn.functional.mse_loss(x, torch.ones_like(x))
        return out

    def training_step(self, batch, batch_idx):
        output = self.layer(batch)
        loss = self.loss(batch, output)
        return {"loss": loss}

    def training_step_end(self, training_step_outputs):
        return training_step_outputs

    def training_epoch_end(self, outputs) -> None:
        torch.stack([x["loss"] for x in outputs]).mean()

    def validation_step(self, batch, batch_idx):
        output = self.layer(batch)
        loss = self.loss(batch, output)
        return {"x": loss}

    def validation_epoch_end(self, outputs) -> None:
        torch.stack([x['x'] for x in outputs]).mean()

    def test_step(self, batch, batch_idx):
        output = self.layer(batch)
        loss = self.loss(batch, output)
        return {"y": loss}

    def test_epoch_end(self, outputs) -> None:
        torch.stack([x["y"] for x in outputs]).mean()

    def configure_optimizers(self):
        optimizer = torch.optim.SGD(self.layer.parameters(), lr=0.1)
        lr_scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=1)
        return [optimizer], [lr_scheduler]


def run_test():
    class TestModel(BoringModel):

        def on_train_epoch_start(self) -> None:
            print('override any method to prove your bug')

        def validation_step(self, batch, batch_idx):
            output = self.layer(batch)
            loss = self.loss(batch, output)
            print("validation_step at global_step = ", self.global_step)
            return {"x": loss}

    # fake data
    train_data = torch.utils.data.DataLoader(RandomDataset(32, 64))
    val_data = torch.utils.data.DataLoader(RandomDataset(32, 64))
    test_data = torch.utils.data.DataLoader(RandomDataset(32, 64))

    # model
    model = TestModel()
    trainer = Trainer(
        default_root_dir=os.getcwd(),
        # limit_train_batches=1,
        limit_val_batches=1,
        val_check_interval=10,
        max_epochs=5,
        weights_summary=None,
    )
    trainer.fit(model, train_data, val_data)
    trainer.test(test_dataloaders=test_data)


if __name__ == '__main__':
    run_test()
To Reproduce

Expected behavior

validation_step at global_step =  0
override any method to prove your bug
validation_step at global_step =  9
validation_step at global_step =  19
validation_step at global_step =  29
validation_step at global_step =  39
validation_step at global_step =  49
validation_step at global_step =  59
override any method to prove your bug
validation_step at global_step =  69
validation_step at global_step =  79
validation_step at global_step =  89
validation_step at global_step =  99
validation_step at global_step =  109
validation_step at global_step =  119
...
Environment
Please copy and paste the output from our
environment collection script
(or fill out the checklist below manually).
You can get the script and run it with:
wget https://raw.githubusercontent.com/PyTorchLightning/pytorch-lightning/master/tests/collect_env_details.py
# For security purposes, please check the contents of collect_env_details.py before running it.
python collect_env_details.py


CUDA:
- GPU:
- Tesla T4
- available:         True
- version:           10.2
Packages:
- numpy:             1.19.1
- pyTorch_debug:     False
- pyTorch_version:   1.6.0
- pytorch-lightning: 1.0.1
- tqdm:              4.50.1
System:
- OS:                Linux
- architecture:
- 64bit
- ELF
- processor:         x86_64
- python:            3.8.5
- version:           #25~18.04.1-Ubuntu SMP Fri Sep 11 21:07:02 UTC 2020

Additional context