from tensorflow.python.util import compat

    for k in kwargs_attr:
      self._definition.attr[k].CopyFrom(kwargs_attr[k])

    # Hash the definition and its dependencies.
    hasher = hashlib.sha1()

    def _hash_func_def():
      """Hash the function definition agnostic to node/map ordering."""

      def update_num(n):
        hasher.update(compat.as_bytes("%x" % n))

      def update_str(s):
        update_num(len(s))
        hasher.update(compat.as_bytes(s))

      def update_strs(slist):
        update_num(len(slist))
        for s in slist:
          update_str(s)

      for adef in self._definition.signature.input_arg:
        update_str(adef.SerializeToString())

      for adef in self._definition.signature.output_arg:
        update_str(adef.SerializeToString())

      for n in sorted(self._definition.node_def, key=lambda n: n.name):
