class_docstr: A logical view of a physical cluster. For example, we could view a physical cluster
  with 16 devices as a device mesh with shape (2, 2, 4) or (4, 4).
  
  Arguments:
      physical_mesh_id (torch.Tensor): physical view of the devices in global rank.
      logical_mesh_id (torch.Tensor): logical view of the devices in global rank.
      mesh_shape (torch.Size, optional): shape of logical view.
      mesh_alpha (List[float], optional): coefficients used for computing
          communication cost (default: None)
      mesh_beta (List[float], optional): coefficients used for computing
          communication cost (default: None)
      init_process_group (bool, optional): initialize logical process group
          during initializing the DeviceMesh instance if the init_process_group set to True.
          Otherwise, users need to call create_process_groups_for_logical_mesh manually to init logical process group.
          (default: False)
      device (str): the device for the process groups used by the DeviceMesh instance. (default: 'cuda')
docstr: This method is used to initialize the logical process groups which will be used in communications
  among logical device mesh.
  Note: if init_process_group set to False, you have to call this method manually. Otherwise,
  the communication related function, such as ShapeConsistencyManager.apply will raise errors.
docstr_tok: ["This","method","is","used","to","initialize","the","logical","process","groups","which","will","be","used","in","communications","among","logical","device","mesh",".","Note",":","if","init_process_group","set","to","False",",","you","have","to","call","this","method","manually",".","Otherwise",",","the","communication","related","function",",","such","as","ShapeConsistencyManager.apply","will","raise","errors","."]
code: def init_logical_process_group(self):
      """
      This method is used to initialize the logical process groups which will be used in communications
      among logical device mesh.
      Note: if init_process_group set to False, you have to call this method manually. Otherwise,
      the communication related function, such as ShapeConsistencyManager.apply will raise errors.
      """
      # sanity check
      assert (
          dist.is_initialized
      ), "The torch.distributed should be initialized before calling init_logical_process_group"
      assert (
          not self._is_initialized
      ), "The logical process group has been initialized, do not call init_logical_process_group twice"
  
      # update the global rank of the current process
      self._global_rank_of_current_process = dist.get_rank()
      duplicate_check_list = []
  
      # flatten the global ranks to 1D list
      global_rank_flatten_list = self._physical_mesh_id.view(
          -1
      ).tolist()
  
      for global_rank in global_rank_flatten_list:
          # find the other ranks which are in the same process group as global_rank
          ranks_in_same_group_by_axis = (
              self._collate_global_ranks_in_same_process_group(
                  global_rank
              )
          )
  
          for (
              axis,
              ranks_in_same_group,
          ) in ranks_in_same_group_by_axis.items():
              # skip duplicated process group creation
              if ranks_in_same_group in duplicate_check_list:
                  continue
  
              # create the process group
              pg_handler = dist.new_group(
                  ranks=ranks_in_same_group, backend=self._dist_backend
              )
  
              # keep this process group in the process_groups_dict
              for rank in ranks_in_same_group:
                  if rank not in self._process_group_dict:
                      self._process_group_dict[rank] = dict()
                  self._process_group_dict[rank][axis] = pg_handler
  
      # update the init flag
      # we only allow init for once
      self._is_initialized = True
  
imports: import operator
  from dataclasses import dataclass
  from functools import reduce
  from typing import Dict, List, Union
  import torch
  import torch.distributed
  from torch.distributed import ProcessGroup
label_desc: Use image node_id 12 for calling the DeviceMesh obj's underlying member method code with example usage: obj.init_logical_process_group() without return types