code: def all_gather_object(object_list, obj):
      """
  
      Example::
          >>> # Note: Process group initialization omitted on each rank.
          >>> # Assumes world_size of 3.
          >>> gather_objects = ["foo", 12, {1: 2}] # any picklable object
          >>> output = [None for _ in gather_objects]
          >>> all_gather_object(output, gather_objects[dist.get_rank()])
          >>> output
          ['foo', 12, {1: 2}]
  
      :param object_list:
      :param obj:
      :param group:
      :return:
      """
      if int(os.environ.get(FASTNLP_NO_SYNC, "0")) == 2:
          return [obj]
  
      current_device = get_oneflow_device(oneflow.cuda.current_device())
  
      input_tensor, local_size = _object_to_tensor(
          obj, device=current_device
      )
  
      # Gather all local sizes. This is so that we can find the max size, and index
      # until the correct size when deserializing the tensors.
      group_size = dist_env.get_world_size()
      object_sizes_tensor = oneflow.zeros(
          group_size, dtype=oneflow.long, device=current_device
      )
      object_size_list = [
          object_sizes_tensor[i].unsqueeze(dim=0)
          for i in range(group_size)
      ]
      # Allgather tensor sizes
      comm.all_gather(object_size_list, local_size)
      max_object_size = int(max(object_size_list).item())  # type: ignore[type-var]
      # Resize tensor to max size across all ranks.
      input_tensor = input_tensor.reshape(max_object_size)
      coalesced_output_tensor = oneflow.empty(
          max_object_size * group_size,
          dtype=oneflow.uint8,
          device=current_device,
      )
      # Output tensors are nonoverlapping views of coalesced_output_tensor
      output_tensors = [
          coalesced_output_tensor[
              max_object_size * i : max_object_size * (i + 1)
          ]
          for i in range(group_size)
      ]
      comm.all_gather(output_tensors, input_tensor)
      # Deserialize outputs back to object.
      for i, tensor in enumerate(output_tensors):
          tensor = tensor.type(oneflow.uint8)
          if tensor.device != oneflow.device("cpu"):
              tensor = tensor.cpu()
          tensor_size = object_size_list[i]
          object_list[i] = _tensor_to_object(tensor, tensor_size)
      return object_list
  
file_path: fastNLP/fastNLP/core/drivers/oneflow_driver/dist_utils.py
imports: import io
  import pickle
  import os
  from typing import Any, List
  from fastNLP.core.utils import apply_to_collection, get_oneflow_device
  from fastNLP.envs.imports import _NEED_IMPORT_ONEFLOW
  from fastNLP.envs.env import FASTNLP_NO_SYNC
label_desc: Use image node_id 9 for calling a global function with example usage: all_gather_object(object_list, obj) and returns: object_list, list