code: def test_eval_logging_auto_reduce(tmpdir):
      class TestModel(BoringModel):
          val_losses = []
          manual_epoch_end_mean = None
  
          def validation_step(self, batch, batch_idx):
              loss = self.step(batch)
              self.val_losses.append(loss)
              self.log(
                  "val_loss",
                  loss,
                  on_epoch=True,
                  on_step=True,
                  prog_bar=True,
              )
              return {"x": loss}
  
          def on_validation_epoch_end(self) -> None:
              self.manual_epoch_end_mean = torch.stack(
                  self.val_losses
              ).mean()
  
      model = TestModel()
      trainer = Trainer(
          default_root_dir=tmpdir,
          limit_train_batches=3,
          limit_val_batches=3,
          max_epochs=1,
          log_every_n_steps=1,
          enable_model_summary=False,
          num_sanity_val_steps=0,
      )
      trainer.fit(model)
  
      # make sure all the metrics are available for callbacks
      assert set(trainer.callback_metrics) == {
          "val_loss",
          "val_loss_epoch",
      }
  
      # make sure values are correct
      assert torch.allclose(
          trainer.logged_metrics["val_loss_epoch"],
          model.manual_epoch_end_mean,
      )
      assert torch.allclose(
          trainer.callback_metrics["val_loss_epoch"],
          model.manual_epoch_end_mean,
      )
      assert torch.allclose(
          trainer.callback_metrics["val_loss"],
          model.manual_epoch_end_mean,
      )
      assert (
          trainer.logged_metrics["val_loss_step"]
          == model.val_losses[-1]
      )
  
imports: import collections
  import itertools
  import os
  from contextlib import redirect_stdout
  from io import StringIO
  from unittest import mock
  from unittest.mock import ANY, call
  import numpy
  import pytest
  import torch
  from lightning.fabric.utilities.imports import _PYTHON_GREATER_EQUAL_3_8_0
  from lightning.pytorch import Trainer, callbacks
  from lightning.pytorch.callbacks.progress.rich_progress import _RICH_AVAILABLE
  from lightning.pytorch.demos.boring_classes import BoringModel, RandomDataset
  from lightning.pytorch.loggers import TensorBoardLogger
  from lightning.pytorch.loops import _EvaluationLoop
  from lightning.pytorch.trainer.states import RunningStage
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from torch import Tensor
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 5 for calling a global function with example usage: test_eval_logging_auto_reduce(tmpdir) and returns: dict