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 typing import Any, Callable, Dict, List, Tuple, Union, cast
  import torch
  from torch import Tensor, device
  from torch.nn import Module
  from captum.attr._utils.batching import _reduce_list, _sort_key_list
  from captum.attr._utils.common import _run_forward, _verify_select_column
  from captum.attr._utils.typing import Literal, TargetType, TensorOrTupleOfTensorsGeneric
label_desc: Use image node_id 9 for calling a global function with example usage: _gather_distributed_tensors(saved_layer, device_ids, key_list) and returns: _reduce_list