code: def tf_toposort(ts, within_ops=None):
      all_ops = ge.get_forward_walk_ops(
          [x.op for x in ts], within_ops=within_ops
      )
  
      deps = {}
      for op in all_ops:
          for o in op.outputs:
              deps[o] = set(op.inputs)
      sorted_ts = toposort(deps)
  
      # only keep the tensors from our original list
      ts_sorted_lists = []
      for l in sorted_ts:
          keep = list(set(l).intersection(ts))
          if keep:
              ts_sorted_lists.append(keep)
  
      return ts_sorted_lists
  
file_path: gpt-2-simple/gpt_2_simple/src/memory_saving_gradients.py
imports: from toposort import toposort
  import contextlib
  import numpy
  import tensorflow
  import time
  import sys
  from tensorflow.python.ops import gradients
label_desc: Use image node_id 5 for calling a global function with example usage: tf_toposort(ts, within_ops) and returns: ts_sorted_lists