code: def spike_detection_test(
      fabric, global_rank_spike, spike_value, should_raise
  ):
      loss_vals = [1 / i for i in range(1, 10)]
      if fabric.global_rank == global_rank_spike:
          if spike_value is None:
              loss_vals[4] = 3
          else:
              loss_vals[4] = spike_value
  
      for i in range(len(loss_vals)):
          context = (
              pytest.raises(TrainingSpikeException)
              if i == 4 and should_raise
              else contextlib.nullcontext()
          )
  
          with context:
              fabric.call(
                  "on_train_batch_end",
                  fabric=fabric,
                  loss=torch.tensor(loss_vals[i], device=fabric.device),
                  batch=None,
                  batch_idx=i,
              )
  
file_path: pytorch-lightning/tests/tests_fabric/utilities/test_spike.py
imports: import contextlib
  import sys
  import pytest
  import torch
  from lightning.fabric import Fabric
  from lightning.fabric.utilities.spike import _TORCHMETRICS_GREATER_EQUAL_1_0_0, SpikeDetection, TrainingSpikeException
label_desc: Use image node_id 1 for calling a global function with example usage: spike_detection_test(fabric, global_rank_spike, spike_value, should_raise) without return types