code: def test_gather_all_performance_sync_shape(self):
      max_shape_size = 10
      shape = [128, 6, DistributedHelper.rank + 1] + (
          [3] * DistributedHelper.rank
      )
  
      device = DistributedHelper.make_device()
  
      def shape_all_gather():
          ts = torch.zeros((max_shape_size,), dtype=torch.int64)
          for i in range(len(shape)):
              ts[i] = shape[i]
  
          ts = ts.to(device)
          all_tensors_shape = [
              torch.empty_like(ts)
              for _ in range(DistributedHelper.world_size)
          ]
          torch.distributed.all_gather(all_tensors_shape, ts)
          all_tensors_shape = [t.cpu() for t in all_tensors_shape]
  
          for i, t in enumerate(all_tensors_shape):
              for x in range(len(t)):
                  if t[x] == 0:
                      if x == 0:
                          # Tensor with 0-length shape
                          all_tensors_shape[i] = t[: x + 1]
                      else:
                          all_tensors_shape[i] = t[:x]
                      break
  
      def shape_all_gather_objects():
          out_list = [None for _ in range(DistributedHelper.world_size)]
          torch.distributed.all_gather_object(out_list, shape)
  
      from tqdm import tqdm
  
      n_times = 1000
      shape_all_gather()
      start_time = time.time()
      for _ in tqdm(range(n_times)):
          shape_all_gather()
      end_time = time.time()
      print(
          "Time taken by PyTorch all_gather",
          end_time - start_time,
          "avg",
          (end_time - start_time) / n_times,
      )
  
      start_time = time.time()
      shape_all_gather_objects()
  
      for _ in tqdm(range(n_times)):
          shape_all_gather_objects()
      end_time = time.time()
      print(
          "Time taken by PyTorch all_gather_object",
          end_time - start_time,
          "avg",
          (end_time - start_time) / n_times,
      )
  
imports: import os
  import random
  import shutil
  import tempfile
  import time
  import unittest
  import numpy
  import torch
  import torch.distributed
  from torch.nn import Module
  from torch.nn.parallel import DistributedDataParallel
  from avalanche.benchmarks.scenarios.deprecated.generators import dataset_benchmark
  from avalanche.benchmarks.utils.classification_dataset import _make_taskaware_tensor_classification_dataset
  from avalanche.distributed import DistributedHelper
  from avalanche.distributed.distributed_helper import RollingSeedContext, BroadcastSeedContext
  from avalanche.models import SimpleMLP, as_multitask
  from avalanche.models.utils import avalanche_model_adaptation
  from avalanche.training.determinism.rng_manager import RNGManager
  from tests.distributed.distributed_test_utils import check_skip_distributed_slow_test, check_skip_distributed_test, suppress_dst_tests_output, common_dst_tests_setup
label_desc: Use image node_id 9 for calling the DistributedHelperTests obj's underlying member method code with example usage: obj.test_gather_all_performance_sync_shape() without return types