class_docstr: Captures a hand-selected set of (global) variables in modules and provides a way to restore them.
  
  It facilitates and encapsulates the transfer of globals like PyTorch's deterministic flags or random generator state
  across process boundaries when launching processes with :func:`torch.multiprocessing.spawn`.
  
  Example:
  
      .. code-block:: python
  
          # in main process
          snapshot = _GlobalStateSnapshot.capture()
  
          # in worker process
          snapshot.restore()
docstr: Capture a few global states from torch, numpy, etc., that we want to restore in a spawned worker process.
docstr_tok: ["Capture","a","few","global","states","from","torch",",","numpy",",","etc.",",","that","we","want","to","restore","in","a","spawned","worker","process","."]
code: def capture(cls) -> "_GlobalStateSnapshot":
      """Capture a few global states from torch, numpy, etc., that we want to restore in a spawned worker process."""
      return cls(
          use_deterministic_algorithms=torch.are_deterministic_algorithms_enabled(),
          use_deterministic_algorithms_warn_only=torch.is_deterministic_algorithms_warn_only_enabled(),
          cudnn_benchmark=torch.backends.cudnn.benchmark,
          rng_states=_collect_rng_states(),
      )
  
imports: import logging
  import os
  import queue
  import tempfile
  from contextlib import suppress
  from dataclasses import dataclass
  from typing import Any, Callable, Dict, List, Literal, NamedTuple, Optional, Union
  import numpy
  import torch
  import torch.backends.cudnn
  import torch.multiprocessing
  from lightning_utilities.core.apply_func import apply_to_collection
  from torch import Tensor
  from typing_extensions import override
  import lightning.pytorch
  from lightning.fabric.strategies.launchers.multiprocessing import _check_bad_cuda_fork, _check_missing_main_guard, _disable_module_memory_sharing
  from lightning.fabric.utilities import move_data_to_device
  from lightning.fabric.utilities.distributed import _set_num_threads_if_needed
  from lightning.fabric.utilities.seed import _collect_rng_states, _set_rng_states
  from lightning.fabric.utilities.types import _PATH
  from lightning.pytorch.accelerators import CPUAccelerator
  from lightning.pytorch.strategies.launchers.launcher import _Launcher
  from lightning.pytorch.trainer.connectors.signal_connector import _SIGNUM
  from lightning.pytorch.trainer.states import TrainerFn, TrainerState
  from lightning.pytorch.utilities.rank_zero import rank_zero_debug
label_desc: Use image node_id 1 for calling the _GlobalStateSnapshot obj's underlying member method code with example usage: obj.capture(cls) and returns: cls