code: def _find_temp_tensors(grads, forward_ops):
      """
      find all the tensors that are used for computing grads and has been
      computed during forward
      :param grads:
      :param forward_ops:
      :return:
      """
      import sys
  
      is_py2 = sys.version[0] == "2"
      if is_py2:
          import Queue as queue
      else:
          import queue as queue
      queue = queue.Queue()
      for grad in grads:
          queue.put(grad)
  
      temp_tensors = set()
      visited = set()
      while not queue.empty():
          tensor = queue.get()
          # this is necessary, because input may not be differentiable
          if tensor is None:
              continue
          else:
              visited.add(tensor.name)
              if tensor.op.type == "Placeholder":
                  continue
              if tensor.op.name in forward_ops:
                  temp_tensors.add(tensor.name)
                  continue
              for input_tensor in tensor.op.inputs:
                  # this is necessary because there may be a cycle in the graph such as tf.while_loop
                  if input_tensor.name not in visited:
                      queue.put(input_tensor)
      return temp_tensors
  
file_path: BigDL/python/dllib/src/bigdl/dllib/utils/tf.py
imports: import os
  import json
  import copy
  import tempfile
  import re
  import shutil
  from bigdl.dllib.utils.file_utils import put_local_file_to_remote, get_remote_file_to_local, get_file_list, is_local_path
  from bigdl.dllib.utils.log4Error import *
label_desc: Use image node_id 5 for calling a global function with example usage: _find_temp_tensors(grads, forward_ops) and returns: temp_tensors