code: def test_global_state_snapshot():
      """Test the capture() and restore() methods for the global state snapshot."""
      torch.use_deterministic_algorithms(True)
      torch.backends.cudnn.benchmark = False
      torch.manual_seed(123)
  
      # capture the state of globals
      snapshot = _GlobalStateSnapshot.capture()
  
      # simulate there is a process boundary and flags get reset here
      torch.use_deterministic_algorithms(False)
      torch.backends.cudnn.benchmark = True
      torch.manual_seed(321)
  
      # restore the state of globals
      snapshot.restore()
      assert torch.are_deterministic_algorithms_enabled()
      assert not torch.backends.cudnn.benchmark
      assert torch.initial_seed() == 123
  
imports: import os
  from multiprocessing import Process
  from unittest import mock
  from unittest.mock import ANY, Mock, call, patch
  import pytest
  import torch
  from lightning.fabric.plugins import ClusterEnvironment
  from lightning.pytorch import Trainer
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.strategies import DDPStrategy
  from lightning.pytorch.strategies.launchers.multiprocessing import _GlobalStateSnapshot, _MultiProcessingLauncher
  from lightning.pytorch.trainer.states import TrainerFn
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 4 for calling a global function with example usage: test_global_state_snapshot() without return types