class_docstr: This class provides interface functions for users to get the parallel context,
  such as the global rank, the local rank, the world size, etc. of each device.
  
  Note:
      The parallel_mode used in this class should be concluded in ``ParallelMode``.
      More details about ``ParallelMode`` could be found in
      `parallel_mode <https://github.com/hpcaitech/ColossalAI/blob/main/colossalai/context/parallel_mode.py>`_.
docstr: Sets seeds for all random libraries.
  
  Args:
      seed (int): seed for random states
docstr_tok: ["Sets","seeds","for","all","random","libraries",".","Args",":","seed","(","int",")",":","seed","for","random","states"]
code: def set_seed(self, seed: int):
      """Sets seeds for all random libraries.
  
      Args:
          seed (int): seed for random states
      """
      random.seed(seed)
      np.random.seed(seed)
      torch.manual_seed(seed)
  
      global_rank = self.get_global_rank()
  
      if torch.cuda.is_available():
          # create random seed for different parallel modes
          # data parallel seed are kept the same
          parallel_seed = seed
          add_seed(ParallelMode.DATA, parallel_seed)
  
          # model parallel seeds are different across ranks
          pipeline_offset = self._local_ranks.get(
              ParallelMode.PIPELINE, 0
          )
  
          # add seed for data parallel and tensor parallel only
          if self.is_initialized(ParallelMode.TENSOR):
              tp_rank = self.get_local_rank(ParallelMode.TENSOR)
              # 100 is only to increase the diff in seeds between pipeline stages
              tp_rank_with_offset = tp_rank + pipeline_offset * 1024
              tp_seed = seed + tp_rank_with_offset
              add_seed(ParallelMode.TENSOR, tp_seed)
  
          set_mode(ParallelMode.DATA)
          seeds = get_seeds()
          seed_str = ", ".join([f"{k}: {v}" for k, v in seeds.items()])
  
          if self._verbose:
              self.logger.info(
                  f"initialized seed on rank {global_rank}, "
                  f"numpy: {seed}, python random: {seed}, {seed_str},"
                  f"the default parallel seed is {ParallelMode.DATA}."
              )
      else:
          if self._verbose:
              self.logger.info(
                  f"initialized seed on rank {global_rank}, "
                  f"numpy: {seed}, python random: {seed}, pytorch: {seed}",
                  ranks=[0],
              )
              self.logger.info(
                  "WARNING: CUDA is not available, thus CUDA RNG cannot be used to track CUDA random number states",
                  ranks=[0],
              )
  
imports: import random
  import socket
  from collections import Counter
  from typing import Union
  import numpy
  import torch
  import torch.distributed
  from colossalai.context.config import Config
  from colossalai.context.singleton_meta import SingletonMeta
  from colossalai.legacy.constants import ALLOWED_MODES, INITIALIZER_MAPPING
  from colossalai.legacy.global_variables import tensor_parallel_env
  from colossalai.legacy.registry import DIST_GROUP_INITIALIZER
  from colossalai.logging import get_dist_logger
  from .parallel_mode import ParallelMode
  from .random import add_seed, get_seeds, set_mode
label_desc: Use image node_id 35 for calling the ParallelContext obj's underlying member method code with example usage: obj.set_seed(seed) without return types