code: def test_throughput():
      # required args only
      throughput = Throughput()
      throughput.update(time=2.0, batches=1, samples=2)
      assert throughput.compute() == {
          "time": 2.0,
          "batches": 1,
          "samples": 2,
      }
  
      # different lengths and samples
      with pytest.raises(RuntimeError, match="same number of samples"):
          throughput.update(time=2.1, batches=2, samples=3, lengths=4)
  
      # lengths and samples
      throughput = Throughput(window_size=2)
      throughput.update(time=2, batches=1, samples=2, lengths=4)
      throughput.update(time=2.5, batches=2, samples=4, lengths=8)
      assert throughput.compute() == {
          "time": 2.5,
          "batches": 2,
          "samples": 4,
          "lengths": 8,
          "device/batches_per_sec": 2.0,
          "device/samples_per_sec": 4.0,
          "device/items_per_sec": 8.0,
      }
  
      with pytest.raises(
          ValueError, match="Expected the value to increase"
      ):
          throughput.update(time=2.5, batches=3, samples=2, lengths=4)
  
      # flops
      throughput = Throughput(available_flops=50, window_size=2)
      throughput.update(
          time=1, batches=1, samples=2, flops=10, lengths=10
      )
      throughput.update(
          time=2, batches=2, samples=4, flops=10, lengths=20
      )
      assert throughput.compute() == {
          "time": 2,
          "batches": 2,
          "samples": 4,
          "lengths": 20,
          "device/batches_per_sec": 1.0,
          "device/flops_per_sec": 10.0,
          "device/items_per_sec": 10.0,
          "device/mfu": 0.2,
          "device/samples_per_sec": 2.0,
      }
  
      # flops without available
      throughput.available_flops = None
      throughput.reset()
      throughput.update(
          time=1, batches=1, samples=2, flops=10, lengths=10
      )
      throughput.update(
          time=2, batches=2, samples=4, flops=10, lengths=20
      )
      assert throughput.compute() == {
          "time": 2,
          "batches": 2,
          "samples": 4,
          "lengths": 20,
          "device/batches_per_sec": 1.0,
          "device/flops_per_sec": 10.0,
          "device/items_per_sec": 10.0,
          "device/samples_per_sec": 2.0,
      }
  
      throughput = Throughput(window_size=2)
      with pytest.raises(
          ValueError,
          match=r"samples.*to be greater or equal than batches",
      ):
          throughput.update(time=0, batches=2, samples=1)
      throughput = Throughput(window_size=2)
      with pytest.raises(
          ValueError,
          match=r"lengths.*to be greater or equal than samples",
      ):
          throughput.update(time=0, batches=2, samples=2, lengths=1)
  
file_path: pytorch-lightning/tests/tests_fabric/utilities/test_throughput.py
imports: from unittest import mock
  from unittest.mock import Mock, call
  import pytest
  import torch
  from lightning.fabric import Fabric
  from lightning.fabric.plugins import Precision
  from lightning.fabric.utilities.throughput import Throughput, ThroughputMonitor, _MonotonicWindow, get_available_flops, measure_flops
  from tests_fabric.helpers.runif import RunIf
  from tests_fabric.test_fabric import BoringModel
label_desc: Use image node_id 4 for calling a global function with example usage: test_throughput() without return types