code: def _parse_replica_sets(replica_sets, size):
      sets = []
  
      for replica_set in replica_sets:
          if isinstance(replica_set, int):
              assert replica_set >= 0
              assert replica_set < size
              sets.append({replica_set})
          else:
              # Must be iterable
              for i in replica_set:
                  assert i >= 0
                  assert i < size
              sets.append(set(replica_set))
  
      if size > sum(len(s) for s in sets):
          all_ranks = set(range(size))
          all_exp = set()
          for s in sets:
              all_exp |= s
          rest = all_ranks - all_exp
          if rest:
              sets.append(rest)
  
      # Must guarantee: no lack allowed
      assert size == sum(len(s) for s in sets)
  
      # Must guarantee: no two sets must have intersection.
      all_sum = set()
      for s in sets:
          all_sum |= s
      assert size == len(all_sum)
      return sets
  
file_path: chainer/chainermn/extensions/_multi_node_snapshot.py
imports: import io
  from chainer.serializers import load_npz
  from chainer.serializers import save_npz
  from chainer.training.extension import Extension
  from chainer.training.extensions._snapshot import _find_latest_snapshot
label_desc: Use image node_id 2 for calling a global function with example usage: _parse_replica_sets(replica_sets, size) and returns: sets