code: def test_throughput_monitor_fit_with_validation(tmp_path):
      logger_mock = Mock()
      logger_mock.save_dir = tmp_path
      monitor = ThroughputMonitor(
          batch_size_fn=lambda x: 1, window_size=2
      )
      model = BoringModel()
      trainer = Trainer(
          devices=1,
          logger=logger_mock,
          callbacks=monitor,
          max_steps=2,
          # validation runs in between the 2 training steps
          val_check_interval=1,
          log_every_n_steps=1,
          limit_val_batches=1,
          num_sanity_val_steps=2,
          enable_checkpointing=False,
          enable_model_summary=False,
          enable_progress_bar=False,
      )
      timings = [
          0,
          7,
          11,
          13,
          19,
      ]  # train t0  # train t1  # val t0  # val t1  # train t1
      with mock.patch("time.perf_counter", side_effect=timings):
          trainer.fit(model)
  
      assert logger_mock.log_metrics.mock_calls == [
          call(
              metrics={
                  "train/time": 7,
                  "train/batches": 1,
                  "train/samples": 1,
                  "epoch": 0,
              },
              step=0,
          ),
          call(
              metrics={
                  "validate/time": 13 - 11,
                  "validate/batches": 1,
                  "validate/samples": 1,
              },
              step=1,
          ),
          call(
              metrics={
                  "train/time": 7 + (19 - 13),
                  "train/batches": 2,
                  "train/samples": 2,
                  "train/device/batches_per_sec": ANY,
                  "train/device/samples_per_sec": ANY,
                  "epoch": 0,
              },
              step=1,
          ),
      ]
  
file_path: pytorch-lightning/tests/tests_pytorch/callbacks/test_throughput_monitor.py
imports: from unittest import mock
  from unittest.mock import ANY, Mock, call
  import pytest
  import torch
  from lightning.fabric.utilities.throughput import measure_flops
  from lightning.pytorch import Trainer
  from lightning.pytorch.callbacks.throughput_monitor import ThroughputMonitor
  from lightning.pytorch.demos.boring_classes import BoringModel
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 3 for calling a global function with example usage: test_throughput_monitor_fit_with_validation(tmp_path) without return types