Average loss calculated by pl is different from manual average loss
🐛 Bug
Validation loss reported by pytorch-lightning on progress bar is different from manually averaged validation loss.
I'm not sure if it's a bug or an intended behavior, but I cannot understand why two values are different.
To Reproduce
Steps to reproduce the behavior:

Run the below code
Observe printed average val loss


1 epoch:
val loss on progress bar: 0.962
manually averaged val loss: 1.2909
2 epoch:
val loss on progress bar: 0.946
manually averaged val loss: 1.2527
Code sample
import os

import torch
from torch.nn import functional as F
from torch.utils.data import DataLoader
from torchvision.datasets import MNIST
from torchvision import transforms
import pytorch_lightning as pl


class MNISTModel(pl.LightningModule):
    def __init__(self):
        super(MNISTModel, self).__init__()
        # not the best model...
        self.l1 = torch.nn.Linear(28 * 28, 10)
        self.val_losses = []

    def forward(self, x):
        # called with self(x)
        return torch.relu(self.l1(x.view(x.size(0), -1)))

    def training_step(self, batch, batch_nb):
        # REQUIRED
        x, y = batch
        y_hat = self(x)
        loss = F.cross_entropy(y_hat, y)
        tensorboard_logs = {"train_loss": loss}
        return {"loss": loss, "log": tensorboard_logs}

    def validation_step(self, batch, batch_nb):
        # OPTIONAL
        x, y = batch
        y_hat = self(x)
        val_loss = F.cross_entropy(y_hat, y)
        self.val_losses.append(val_loss.item())
        return {
            "loss": val_loss,
            "progress_bar": {"val_loss": val_loss},
            "log": {"val_loss": val_loss},
        }

    def on_validation_epoch_end(self):
        print("average val loss", sum(self.val_losses) / len(self.val_losses))
        self.val_losses = []

    def configure_optimizers(self):
        # REQUIRED
        # can return multiple optimizers and learning_rate schedulers
        # (LBFGS it is automatically supported, no need for closure function)
        return torch.optim.Adam(self.parameters(), lr=0.02)

    def train_dataloader(self):
        # REQUIRED
        return DataLoader(
            MNIST(os.getcwd(), train=True, download=True, transform=transforms.ToTensor()),
            batch_size=32,
        )

    def val_dataloader(self):
        # OPTIONAL
        return DataLoader(
            MNIST(os.getcwd(), train=True, download=True, transform=transforms.ToTensor()),
            batch_size=32,
        )


mnist_model = MNISTModel()

# most basic trainer, uses good defaults (1 gpu)
trainer = pl.Trainer(gpus=1)
trainer.fit(mnist_model)
Expected behavior
val losses manually calculated should match the one reported by progress bar of pytorch-lightning
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


PyTorch Version: 1.6
OS (e.g., Linux): Base Docker image: nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04
How you installed PyTorch (conda, pip, source): pip
Build command you used (if compiling from source): None
Python version: 3.8
CUDA/cuDNN version: CUDA 10.2, cudnn 7
GPU models and configuration: Titan RTX
Any other relevant information:

Additional context