code: def _collect_rng_states(include_cuda: bool = True) -> Dict[str, Any]:
      r"""Collect the global random state of :mod:`torch`, :mod:`torch.cuda`, :mod:`numpy` and Python."""
      states = {
          "torch": torch.get_rng_state(),
          "numpy": np.random.get_state(),
          "python": python_get_rng_state(),
      }
      if include_cuda:
          states["torch.cuda"] = (
              torch.cuda.get_rng_state_all()
              if torch.cuda.is_available()
              else []
          )
      return states
  
file_path: pytorch-lightning/src/lightning/fabric/utilities/seed.py
imports: import logging
  import os
  import random
  from random import getstate
  from random import setstate
  from typing import Any, Dict, Optional
  import numpy
  import torch
  from lightning.fabric.utilities.rank_zero import _get_rank, rank_prefixed_message, rank_zero_only, rank_zero_warn
label_desc: Use image node_id 4 for calling a global function with example usage: _collect_rng_states(include_cuda) and returns: states