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 itertools
  import os
  from dataclasses import dataclass
  from multiprocessing.queues import SimpleQueue
  from textwrap import dedent
  from typing import TYPE_CHECKING, Any, Callable, Dict, Literal, Optional
  import torch
  import torch.backends.cudnn
  import torch.multiprocessing
  from lightning_utilities import apply_to_collection
  from torch.nn import Module
  from typing_extensions import override
  from lightning.fabric.accelerators.cpu import CPUAccelerator
  from lightning.fabric.strategies.launchers.launcher import _Launcher
  from lightning.fabric.utilities.apply_func import move_data_to_device
  from lightning.fabric.utilities.distributed import _set_num_threads_if_needed
  from lightning.fabric.utilities.imports import _IS_INTERACTIVE
  from lightning.fabric.utilities.seed import _collect_rng_states, _set_rng_states
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