code: def fork_rng(seed=None, cuda=torch.cuda.is_available()):
      """Forks the `torch`, `numpy` and `random` random generators, so that when you return, the
      random generators are reset to the state that they were previously in.
  
      Example:
          with fork_rng(seed=123):  # Ensure determinism
              print('Random:', random.randint(1, 2**31))
              print('Numpy:', numpy.random.randint(1, 2**31))
              print('Torch:', int(torch.randint(1, 2**31, (1,))))
  
      Args:
          seed (int or None, optional): If defined this sets the seed values for the random
              generator fork. This is a convenience parameter.
          cuda (bool, optional): If `True` saves the `cuda` seed also. Getting and setting the random
              generator state can be quite slow if you have a lot of GPUs.
      """
      state = get_random_generator_state(cuda)
      if seed is not None:
          set_seed(seed, cuda)
      try:
          yield
      finally:
          set_random_generator_state(state)
  
file_path: pywick/pywick/cust_random.py
imports: from collections import namedtuple
  from contextlib import contextmanager
  import functools
  import random
  import numpy
  import torch
label_desc: Use image node_id 3 for calling a global function with example usage: fork_rng(seed, cuda) without return types