code: def test_throughput_monitor_fit_gradient_accumulation(tmp_path):
      logger_mock = Mock()
      logger_mock.save_dir = tmp_path
      monitor = ThroughputMonitor(
          length_fn=lambda x: 3 * 2,
          batch_size_fn=lambda x: 3,
          window_size=4,
          separator="|",
      )
      model = BoringModel()
      model.flops_per_batch = 10
  
      trainer = Trainer(
          devices=1,
          logger=logger_mock,
          callbacks=monitor,
          limit_train_batches=5,
          limit_val_batches=0,
          max_epochs=2,
          log_every_n_steps=3,
          accumulate_grad_batches=2,
          num_sanity_val_steps=2,
          enable_checkpointing=False,
          enable_model_summary=False,
          enable_progress_bar=False,
      )
      with pytest.raises(ValueError, match="not divisible"):
          trainer.fit(model)
  
      trainer = Trainer(
          devices=1,
          logger=logger_mock,
          callbacks=monitor,
          limit_train_batches=5,
          limit_val_batches=0,
          max_epochs=2,
          log_every_n_steps=1,
          accumulate_grad_batches=2,
          num_sanity_val_steps=2,
          enable_checkpointing=False,
          enable_model_summary=False,
          enable_progress_bar=False,
      )
      timings = [0.0] + [0.5 + i for i in range(1, 11)]
      with mock.patch(
          "lightning.pytorch.callbacks.throughput_monitor.get_available_flops",
          return_value=100,
      ), mock.patch("time.perf_counter", side_effect=timings):
          trainer.fit(model)
  
      expected = {
          "train|device|batches_per_sec": 1.0,
          "train|device|samples_per_sec": 3.0,
          "train|device|items_per_sec": 6.0,
          "train|device|flops_per_sec": 10.0,
          "train|device|mfu": 0.1,
      }
      assert logger_mock.log_metrics.mock_calls == [
          call(
              metrics={
                  "train|time": 2.5,
                  "train|batches": 2,
                  "train|samples": 6,
                  "train|lengths": 12,
                  "epoch": 0,
              },
              step=0,
          ),
          call(
              metrics={
                  **expected,
                  "train|time": 4.5,
                  "train|batches": 4,
                  "train|samples": 12,
                  "train|lengths": 24,
                  "epoch": 0,
              },
              step=1,
          ),
          call(
              metrics={
                  **expected,
                  "train|time": 5.5,
                  "train|batches": 5,
                  "train|samples": 15,
                  "train|lengths": 30,
                  "epoch": 0,
              },
              step=2,
          ),
          call(
              metrics={
                  **expected,
                  "train|time": 7.5,
                  "train|batches": 7,
                  "train|samples": 21,
                  "train|lengths": 42,
                  "epoch": 1,
              },
              step=3,
          ),
          call(
              metrics={
                  **expected,
                  "train|time": 9.5,
                  "train|batches": 9,
                  "train|samples": 27,
                  "train|lengths": 54,
                  "epoch": 1,
              },
              step=4,
          ),
          call(
              metrics={
                  **expected,
                  "train|time": 10.5,
                  "train|batches": 10,
                  "train|samples": 30,
                  "train|lengths": 60,
                  "epoch": 1,
              },
              step=5,
          ),
      ]
  
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 5 for calling a global function with example usage: test_throughput_monitor_fit_gradient_accumulation(tmp_path) without return types