code: def _gather_distributed_tensors(
      saved_layer: Dict[device, Tuple[Tensor, ...]],
      device_ids: Union[None, List[int]] = None,
      key_list: Union[None, List[device]] = None,
  ) -> Tuple[Tensor, ...]:
      r"""
      A helper function to concatenate intermediate layer results stored on
      different devices in `saved_layer`. `saved_layer` is a dictionary that
      contains `device_id` as a key and intermediate layer results (either
      the input or the output of the layer) stored on the device corresponding to
      the key.
      `key_list` is a list of devices in appropriate ordering for concatenation
      and if not provided, keys are sorted based on device ids.
  
      If only one key exists (standard model), key list simply has one element.
      """
      if key_list is None:
          key_list = _sort_key_list(
              list(saved_layer.keys()), device_ids
          )
      return _reduce_list(
          [saved_layer[device_id] for device_id in key_list]
      )
  
imports: import threading
  import typing
  import warnings
  from collections import defaultdict
  from typing import Any, Callable, cast, Dict, List, Optional, Sequence, Tuple, Union
  import torch
  from captum._utils.common import _reduce_list, _run_forward, _sort_key_list, _verify_select_neuron
  from captum._utils.sample_gradient import SampleGradientWrapper
  from captum._utils.typing import Literal, ModuleOrModuleList, TargetType, TensorOrTupleOfTensorsGeneric
  from torch import device, Tensor
  from torch.nn import Module
label_desc: Use image node_id 11 for calling a global function with example usage: _gather_distributed_tensors(saved_layer, device_ids, key_list) and returns: _reduce_list