aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/graph/graph.cc
diff options
context:
space:
mode:
authorGravatar Skye Wanderman-Milne <skyewm@google.com>2017-07-06 13:59:28 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-07-06 14:03:01 -0700
commit7d5c74a9c89333f4f5b0524856907ac1b9f43a7b (patch)
tree92961ba96c8bfacf8548b3097f87e86ac355e931 /tensorflow/core/graph/graph.cc
parent2caec3af18a5c81f4c02f049cb5f39ca71700795 (diff)
Move duplicate detection logic from Graph to FunctionLibraryDefinition
Turns out this is more useful, since there are many function libraries that don't belong to a graph. This will be used in a future change. Note that this maintains the current behavior of Graph. In addition, updates FunctionDefsEqual() to handle unset attr entries (I ran into this when using this in said future change). PiperOrigin-RevId: 161126628
Diffstat (limited to 'tensorflow/core/graph/graph.cc')
-rw-r--r--tensorflow/core/graph/graph.cc30
1 files changed, 1 insertions, 29 deletions
diff --git a/tensorflow/core/graph/graph.cc b/tensorflow/core/graph/graph.cc
index 7a5e76fdd0..9691326c99 100644
--- a/tensorflow/core/graph/graph.cc
+++ b/tensorflow/core/graph/graph.cc
@@ -413,35 +413,7 @@ void Graph::RemoveEdge(const Edge* e) {
}
Status Graph::AddFunctionLibrary(const FunctionDefLibrary& fdef_lib) {
- for (const FunctionDef& fdef : fdef_lib.function()) {
- const FunctionDef* preexisting_fdef = ops_.Find(fdef.signature().name());
- if (preexisting_fdef != nullptr) {
- if (!FunctionDefsEqual(*preexisting_fdef, fdef)) {
- return errors::InvalidArgument(
- "Cannot add function '", fdef.signature().name(),
- "' because a different function with the same name already "
- "exists.");
- }
- // Ignore duplicate FunctionDefs
- continue;
- }
- TF_RETURN_IF_ERROR(ops_.AddFunctionDef(fdef));
- }
- for (const GradientDef& grad : fdef_lib.gradient()) {
- string preexisting_grad_func = ops_.FindGradient(grad.function_name());
- if (!preexisting_grad_func.empty()) {
- if (preexisting_grad_func != grad.gradient_func()) {
- return errors::InvalidArgument(
- "Cannot assign gradient function '", grad.gradient_func(), "' to '",
- grad.function_name(), "' because it already has gradient function ",
- "'", preexisting_grad_func, "'");
- }
- // Ignore duplicate GradientDefs
- continue;
- }
- TF_RETURN_IF_ERROR(ops_.AddGradientDef(grad));
- }
- return Status::OK();
+ return ops_.AddLibrary(fdef_lib);
}
namespace {