code: def _apply_to_tensors_only(
      module, functional, backward_function, outputs
  ):
      if isinstance(outputs, (tuple, list)):
          touched_outputs = []
          for output in outputs:
              touched_output = _apply_to_tensors_only(
                  module, functional, backward_function, output
              )
              touched_outputs.append(touched_output)
          return outputs.__class__(touched_outputs)
      elif isinstance(outputs, dict):
          # apply inplace to avoid recreating dict inherited objects
          for key in outputs.keys():
              outputs[key] = _apply_to_tensors_only(
                  module, functional, backward_function, outputs[key]
              )
          return outputs
  
      elif type(outputs) is torch.Tensor:
          return functional.apply(module, backward_function, outputs)
      else:
          if not is_builtin_type(outputs):
              global warned
              if not warned and dist.get_rank() == 0:
                  logger.warning(
                      f"A module has unknown inputs or outputs type ({type(outputs)}) and the tensors embedded in it cannot be detected. "
                      "The ZeRO-3 hooks designed to trigger before or after backward pass of the module relies on knowing the input and "
                      "output tensors and therefore may not get triggered properly."
                  )
                  warned = True
          return outputs
  
imports: import sys
  import torch
  from torch.cuda import Stream
  from collections import OrderedDict
  from deepspeed.runtime.utils import see_memory_usage
  from deepspeed.runtime.zero.offload_config import OffloadDeviceEnum
  from deepspeed.runtime.zero.partition_parameters import _init_external_params
  from deepspeed.runtime.zero.partition_parameters import *
  from deepspeed.runtime.zero.partitioned_param_coordinator import PartitionedParameterCoordinator, iter_params
  from deepspeed import comm
label_desc: Use image node_id 2 for calling a global function with example usage: _apply_to_tensors_only(module, functional, backward_function, outputs) and returns: outputs, outputs, functional, outputs