code: def _apply_forward_and_backward_to_tensors_only(
      module, forward_function, backward_function, outputs
  ):
      if type(outputs) is tuple:
          touched_outputs = []
          for output in outputs:
              touched_output = (
                  _apply_forward_and_backward_to_tensors_only(
                      module,
                      forward_function,
                      backward_function,
                      output,
                  )
              )
              touched_outputs.append(touched_output)
          return tuple(touched_outputs)
      elif type(outputs) is torch.Tensor:
          forward_function(outputs)
          if outputs.requires_grad:
              outputs.register_hook(backward_function)
          return outputs
      else:
          return outputs
  
imports: import sys
  import torch
  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, InflightParamRegistry, iter_params
  from deepspeed import comm
  from deepspeed.accelerator import get_accelerator
label_desc: Use image node_id 4 for calling a global function with example usage: _apply_forward_and_backward_to_tensors_only(module, forward_function, backward_function, outputs) and returns: tuple, outputs, outputs