code: def gather_global_ids(global_ids: List[torch.Tensor], group):
      world_size = dist.get_world_size()
      rank = dist.get_rank()
  
      concat_global_ids = torch.cat(global_ids)
  
      concat_numel = torch.tensor(
          concat_global_ids.numel(), dtype=torch.int64
      )
      concat_numel_list = [
          torch.tensor(0, dtype=torch.int64) for _ in range(world_size)
      ]
      dist.all_gather(
          concat_numel_list, concat_numel, group=group, async_op=False
      )
  
      max_numel = max(concat_numel_list)
      concat_global_ids.resize_(max_numel)
  
      if rank == 0:
          concat_global_ids_list = [
              torch.empty_like(concat_global_ids)
              for _ in range(world_size)
          ]
          dist.gather(
              concat_global_ids,
              concat_global_ids_list,
              0,
              group,
              async_op=False,
          )
          return [
              concat_global_ids_list[i][: concat_numel_list[i]]
              for i in range(world_size)
          ], concat_numel_list
      else:
          dist.gather(concat_global_ids, None, 0, group, async_op=False)
          return None, concat_numel_list
  
imports: from typing import List, Optional
  import torch
  import torch.distributed
label_desc: Use image node_id 1 for calling a global function with example usage: gather_global_ids(global_ids, group) and returns: unknown,  concat_numel_list, None,  concat_numel_list