aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/framework/ops.py
diff options
context:
space:
mode:
authorGravatar Vijay Vasudevan <vrv@google.com>2015-12-03 17:56:16 -0800
committerGravatar Vijay Vasudevan <vrv@google.com>2015-12-03 17:56:16 -0800
commit54a644f33f34a32fa2cb5e7a489c64540b16e166 (patch)
tree6c15047163a4e2554bdb737079f6abb536b8d641 /tensorflow/python/framework/ops.py
parenteb5e56e479a41ad3696ea351e5804d17464d521a (diff)
TensorFlow: upstream changes to git
Change 109366961 TensorFlow BUILD: now that we have an ops library, set linkstatic to 1. This fixes a breakage in the would-be opensource build, and it *might* mean we can get rid of all of the RequireDefaultOps() calls in our code. The ops library is much smaller than the kernels library that was previously linked together. We set linkstatic=0 presumably since we didn't want to package a static copy of the kernels (very large) everywhere. But the op definitions are small, so this seems like a safe change to make. Time to build the various tests was not any longer after this change, and inspecting the example_trainer binary showed no large increase. Change 109363613 TensorFlow: new graph_def_builder_test needs to RequireDefaultOps. Change 109362569 Split ":ops" out of ":kernels" target in tensorflow/core. Change 109360666 Catch dtype and some shape errors sooner in `QueueBase`. Some avoidable errors were not being caught (e.g. the dtypes of the enqueue components were not checked against the queue's dtypes in Python), leading to cryptic messages at runtime. After this CL, they will be caught earlier. Change 109359569 TensorFlow: Expect g_ != nullptr in test Change 109350735 Add a version number to GraphDef We would like to be able to deprecate behavior in newly generated graphs without invalidating tensorflow's ability to read and evaluate old graphs. For this purpose, GraphDef now has a version field which can be checked inside op kernels to determine how backwards compatible to be. version.h defines TF_GRAPHDEF_VERSION_MIN and TF_GRAPHDEF_VERSION_MAX specifying the range of supported GraphDef versions in the current version of tensorflow. Also expose tf.__version__ and tf.__graph_def_version{,_min,_max}__ for Python interrogation purposes. Whenever we want to deprecate or change some GraphDef semantics, we will proceed as follows: 1. Bump TF_GRAPHDEF_VERSION_MAX, leaving TF_GRAPHDEF_VERSION_MIN unchanged. Describe the change in graph.proto, include the date introduced. 2. In each relevant kernel, implement the new behavior if the GraphDef version is new, but preserve the old behavior for previous GraphDef versions. 3. Wait six months or so (we need to formalize this somewhere). 4. Bump TF_GRAPHDEF_VERSION_MIN and remove the backwards compatibility. The GraphDef version is distinct from the open source version, but at least (4) and possibly (1) correspond to major version number bumps. The first GraphDef version bump is the upcoming scalar strictness change, which affects Google users only since open source is already scalar strict. This commit does not yet plumb the version number into OpKernelConstruction so that ops can access it. That will follow. Change 109350260 Made TensorShapeProto implicitly convertible to TensorShape. Base CL: 109366982
Diffstat (limited to 'tensorflow/python/framework/ops.py')
-rw-r--r--tensorflow/python/framework/ops.py34
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]