docstr: Get swap loss. The swap loss is used to avoid the situation that
  the same index is swapped twice and the same group is swapped for multiple times.
docstr_tok: ["Get","swap","loss",".","The","swap","loss","is","used","to","avoid","the","situation","that","the","same","index","is","swapped","twice","and","the","same","group","is","swapped","for","multiple","times","."]
code: def _get_swap_loss(
      group_swap_factor: float,
      swap_list: List,
      group_i: int,
      index_i: int,
      group_j: int,
      index_j: int,
  ) -> float:
      """
      Get swap loss. The swap loss is used to avoid the situation that
      the same index is swapped twice and the same group is swapped for multiple times.
      """
      swap_loss = 0
      for swap in swap_list:
          for group_id, index_id in zip(
              [group_i, group_j], [index_i, index_j]
          ):
              # the group has been swapped
              if group_id in [swap[0], swap[2]]:
                  # the index has been swapped
                  # we want to avoid the situation that the same index is swapped twice
                  if index_id in [swap[1], swap[3]]:
                      swap_loss += 1e5
                  # the index has not been swapped
                  # this is acceptable but as less as possible
                  else:
                      swap_loss += group_swap_factor
      return swap_loss
  
imports: from copy import deepcopy
  from typing import List, Optional, Tuple
  import torch
  import torch.distributed
  from torch import Tensor, nn
  from torch.distributed import ProcessGroup
  from colossalai.cluster import ProcessGroupMesh
  from colossalai.moe.experts import MLPExperts
  from colossalai.moe.manager import MOE_MANAGER
  from colossalai.zero.low_level import LowLevelZeroOptimizer
label_desc: Use image node_id 7 for calling the LoadBalancer obj's underlying member method code with example usage: obj._get_swap_loss(group_swap_factor, swap_list, group_i, index_i, group_j, index_j) and returns: swap_loss