code: def _get_expert_parallel_ranks(
      world_size, model_parallel_size_, expert_parallel_size_
  ):
      """Generate expert parallel and expert data parallel group ranks list.
  
          Example - E + M + D parallel
          world_size = 16
          model_degree = 2
          expert_degree = 4 # number of experts in same group
          mp_group = [0, 1], [2,3], [4,5] ...
          data_parallel_group =[0,2,4,6,8,10, 12,14],                 [1,3,5,7,9,11,13,15]
          expert_parallel_group = [0,2,4,6], [8,10,12,14]             [1,3,5,7], [9,11,13,15]
          expert_data_parallel_group = [0,8],[2,10],[4,12],[6,14],    [1,9],[3,11],[5,13],[7,15]
  
      Args:
          world_size (int): Distributed world size.
          model_parallel_size_ (int): Model parallel group size.
          expert_parallel_size_ (int): Expert parallel group size.
  
      Returns:
          Expert parallel group ranks and Expert data parallel group ranks list.
      """
      _ensure_divisibility(world_size, model_parallel_size_)
      dp_world_size = world_size // model_parallel_size_
      _ensure_divisibility(dp_world_size, expert_parallel_size_)
  
      # Generate data parallel groups
      data_parallel_groups = []
      dp_group_size = model_parallel_size_
      for i in range(dp_group_size):
          data_parallel_groups.append(
              list(range(i, world_size, dp_group_size))
          )
  
      expert_parallel_groups = []
      expert_data_parallel_groups = []
      for dp_ranks in data_parallel_groups:
          # partition of expert parallel groups, e.g. [0,2,4,6], [8,10,12,14]
          part_ep_groups = []
          for i in range(0, dp_world_size, expert_parallel_size_):
              part_ep_groups.append(
                  dp_ranks[i : i + expert_parallel_size_]
              )
          expert_parallel_groups.extend(part_ep_groups)
  
          # zip part_ep_groups get expert data parallel ranks, e.g [0,8],[2,10],[4,12],[6,14]
          for expert_dp_ranks in zip(*part_ep_groups):
              expert_data_parallel_groups.append(list(expert_dp_ranks))
  
      return expert_parallel_groups, expert_data_parallel_groups
  
imports: from deepspeed import comm
  from deepspeed.utils import log_dist
  from deepspeed.utils.exceptions import DeprecatedException
label_desc: Use image node_id 5 for calling a global function with example usage: _get_expert_parallel_ranks(world_size, model_parallel_size_, expert_parallel_size_) and returns: expert_parallel_groups,  expert_data_parallel_groups