code: def _infer_topo(
      rank_list: List[int],
      transpose: bool,
      construct_adjacency_matrix: bool,
  ):
      degree = len(rank_list)
      all_degree_list = bf.allgather(
          torch.tensor([degree], dtype=torch.int32)
      ).numpy()
      all_rank_list = bf.allgather(
          torch.tensor(rank_list, dtype=torch.int32)
      ).numpy()
      adjacency_dict = dict()
      displacement = 0
      for i, degree in enumerate(all_degree_list):
          adjacency_dict[i] = sorted(
              all_rank_list[displacement : displacement + degree]
          )
          displacement += degree
  
      inv_adjacency_dict = collections.defaultdict(list)
      for k, adj in adjacency_dict.items():
          for v in adj:
              inv_adjacency_dict[v].append(k)
      return_list = inv_adjacency_dict.get(bf.rank())
      if return_list is None:
          return_list = []
  
      if not construct_adjacency_matrix:
          return return_list
  
      # construct_adjacency_matrix
      W = np.eye(bf.size())
      for k, adj in adjacency_dict.items():
          W[k, adj] = 1
      if transpose:
          W = W.T
  
      return return_list, W / W.sum(axis=1)
  
file_path: bluefog/bluefog/torch/topology_util.py
imports: from typing import Any, List, Optional, Tuple, Union
  import collections
  import numpy
  import torch
  import bluefog.torch
label_desc: Use image node_id 4 for calling a global function with example usage: _infer_topo(rank_list, transpose, construct_adjacency_matrix) and returns: return_list,  unknown, return_list