code: def memoize_autodiff(func):
      """
      Memoize to avoid rebuilding of the gradient tree.
  
      Arguments:
          func (Function): Function to memoize.
      """
      cache = {}
  
      @wraps(func)
      def memoizer(op_tree, be, next_error=None):
          """
          If params in the caches, return results directly. Othewise, add to cache
          and return the results.
  
          Arguments:
              op_tree (OpTreeNode): the op-tree to supply to the func.
              be (Backend): computation backend to supply to the func.
              next_error (Tensor or OpTreeNode, optional): next layer's error to
                                                           supply to the func.
          """
          key = (op_tree.key(), be, next_error)
          if key not in cache:
              cache[key] = func(op_tree, be, next_error)
              # print 'created grad_tree cache'
          return cache[key]
  
      return memoizer
  
imports: from __future__ import division
  from builtins import object, zip
  from neon.backends.backend import OpTreeNode, Tensor
  import numpy
  from functools import wraps
label_desc: Use image node_id 1 for calling a global function with example usage: memoize_autodiff(func) and returns: memoizer, cache