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: Returns a boolean value indicating whether the current device is the first one
  among its group for `parallel_mode`.
  
  Args:
      parallel_mode (:class:`colossalai.legacy.context.ParallelMode`): The chosen parallel mode.
  
  Raises:
      AssertionError: Raises an AssertionError if `parallel_mode` is not an instance
          of :class:`colossalai.legacy.context.ParallelMode`.
  
  Returns:
      bool: a boolean value indicating whether the current device is the first one
      among its group for `parallel_mode`.
docstr_tok: ["Returns","a","boolean","value","indicating","whether","the","current","device","is","the","first","one","among","its","group","for","`","parallel_mode","`",".","Args",":","parallel_mode","(",":","class",":","`","colossalai.legacy.context.ParallelMode","`",")",":","The","chosen","parallel","mode",".","Raises",":","AssertionError",":","Raises","an","AssertionError","if","`","parallel_mode","`","is","not","an","instance","of",":","class",":","`","colossalai.legacy.context.ParallelMode","`",".","Returns",":","bool",":","a","boolean","value","indicating","whether","the","current","device","is","the","first","one","among","its","group","for","`","parallel_mode","`","."]
code: def is_first_rank(self, parallel_mode: ParallelMode):
      """Returns a boolean value indicating whether the current device is the first one
      among its group for `parallel_mode`.
  
      Args:
          parallel_mode (:class:`colossalai.legacy.context.ParallelMode`): The chosen parallel mode.
  
      Raises:
          AssertionError: Raises an AssertionError if `parallel_mode` is not an instance
              of :class:`colossalai.legacy.context.ParallelMode`.
  
      Returns:
          bool: a boolean value indicating whether the current device is the first one
          among its group for `parallel_mode`.
      """
      rank = self.get_local_rank(parallel_mode)
      return rank == 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 15 for calling the ParallelContext obj's underlying member method code with example usage: obj.is_first_rank(parallel_mode) and returns: unknown