code: def torch_seed(seed: Optional[int]):
      """Context manager which seeds the PyTorch PRNG with the specified seed and
      restores the state afterward. Setting seed to None is equivalent to running
      the code without the context manager."""
      if seed is None:
          yield
          return
      state = torch.get_rng_state()
      torch.manual_seed(seed)
      try:
          yield
      finally:
          torch.set_rng_state(state)
  
imports: import collections.abc
  import contextlib
  import json
  import logging
  import os
  import time
  from functools import partial
  from typing import Any, Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  import torch.nn
  from classy_vision.generic.distributed_util import broadcast_object, is_primary
  from fvcore.common.file_io import PathManager
label_desc: Use image node_id 23 for calling a global function with example usage: torch_seed(seed) without return types