aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/c/python_api.cc
diff options
context:
space:
mode:
authorGravatar Igor Ganichev <iga@google.com>2017-11-29 14:01:29 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-11-29 14:06:17 -0800
commitcb5a63d8d2b6e049a0a128ba47560f842497db8b (patch)
treeced4a0647f9bab632a2d9a80895e7cc9bca0c78c /tensorflow/c/python_api.cc
parent1d0b07351d901334b33565595d4c23607f11cc27 (diff)
Check when session cannot run because its graph was modified
With current tensorflow code, if user modifies some operation after session.run() was called, this modification will never make it to the C++ runtime and no errors will be raised leading to silent wrong results. This change adds checks for such cases when C API is enabled. We don't change the code path for C API being disabled because C API should be enabled by default soon. PiperOrigin-RevId: 177359630
Diffstat (limited to 'tensorflow/c/python_api.cc')
-rw-r--r--tensorflow/c/python_api.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/tensorflow/c/python_api.cc b/tensorflow/c/python_api.cc
index ba5a9268b4..37629a74ba 100644
--- a/tensorflow/c/python_api.cc
+++ b/tensorflow/c/python_api.cc
@@ -22,6 +22,7 @@ namespace tensorflow {
void AddControlInput(TF_Graph* graph, TF_Operation* op, TF_Operation* input) {
mutex_lock l(graph->mu);
graph->graph.AddControlEdge(&input->node, &op->node);
+ RecordMutation(graph, *op, "adding control input");
}
void SetAttr(TF_Graph* graph, TF_Operation* op, const char* attr_name,
@@ -36,11 +37,13 @@ void SetAttr(TF_Graph* graph, TF_Operation* op, const char* attr_name,
mutex_lock l(graph->mu);
op->node.AddAttr(attr_name, attr_val);
+ RecordMutation(graph, *op, "setting attribute");
}
void SetRequestedDevice(TF_Graph* graph, TF_Operation* op, const char* device) {
mutex_lock l(graph->mu);
op->node.set_requested_device(device);
+ RecordMutation(graph, *op, "setting device");
}
void UpdateEdge(TF_Graph* graph, TF_Output new_src, TF_Input dst,
@@ -75,6 +78,13 @@ void UpdateEdge(TF_Graph* graph, TF_Output new_src, TF_Input dst,
}
status->status = graph->graph.UpdateEdge(&new_src.oper->node, new_src.index,
&dst.oper->node, dst.index);
+
+ if (status->status.ok()) {
+ // This modification only updates the destination node for
+ // the purposes of running this graph in a session. Thus, we don't
+ // record the source node as being modified.
+ RecordMutation(graph, *dst.oper, "updating input tensor");
+ }
}
} // namespace tensorflow