diff options
Diffstat (limited to 'tensorflow/python/framework/ops.py')
-rw-r--r-- | tensorflow/python/framework/ops.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/tensorflow/python/framework/ops.py b/tensorflow/python/framework/ops.py index d3527c693e..f9796ca679 100644 --- a/tensorflow/python/framework/ops.py +++ b/tensorflow/python/framework/ops.py @@ -37,6 +37,7 @@ from tensorflow.python.framework import device as pydev from tensorflow.python.framework import dtypes from tensorflow.python.framework import registry from tensorflow.python.framework import tensor_shape +from tensorflow.python.framework import versions from tensorflow.python.util import compat @@ -1545,6 +1546,7 @@ class Graph(object): @@seed @@unique_name @@version + @@graph_def_version @@create_op @@gradient_override_map @@ -1585,6 +1587,8 @@ class Graph(object): self._finalized = False # Functions defined in the graph self._functions = collections.OrderedDict() + # Default GraphDef version + self._graph_def_version = versions.GRAPH_DEF_VERSION def _check_not_finalized(self): """Check if the graph is finalized. @@ -1620,10 +1624,37 @@ class Graph(object): @property def version(self): - """Returns a version number that increases as ops are added to the graph.""" + """Returns a version number that increases as ops are added to the graph. + + Note that this is unrelated to the + [GraphDef version](#Graph.graph_def_version). + """ return self._next_id_counter @property + def graph_def_version(self): + """The GraphDef version of this graph. + + For details on the meaning of each version, see [`GraphDef`] + (https://tensorflow.googlesource.com/tensorflow/+/master/tensorflow/core/framework/graph.proto). + """ + return self._graph_def_version + + @graph_def_version.setter + def graph_def_version(self, version): + if not (versions.GRAPH_DEF_VERSION_MIN <= version <= + versions.GRAPH_DEF_VERSION_MAX): + low = version < versions.GRAPH_DEF_VERSION_MIN + raise ValueError( + "GraphDef version %d is %s supported: TensorFlow %s needs %d <= " + "version <= %d. Please %s." % + (version, "no longer" if low else "not yet", + versions.__version__, versions.GRAPH_DEF_VERSION_MIN, + versions.GRAPH_DEF_VERSION_MAX, + "regenerate your graph" if low else "upgrade TensorFlow")) + self._graph_def_version = version + + @property def seed(self): return self._seed @@ -1684,6 +1715,7 @@ class Graph(object): ValueError: If the `graph_def` would be too large. """ graph = graph_pb2.GraphDef() + graph.version = self._graph_def_version bytesize = 0 for op_id in sorted(self._nodes_by_id): op = self._nodes_by_id[op_id] |