diff options
author | Skye Wanderman-Milne <skyewm@google.com> | 2017-05-01 07:56:28 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-05-01 09:04:29 -0700 |
commit | 474aba363a85d68fdd8f8ab8b1d9d749a91e6e7a (patch) | |
tree | f0df306b0434e8079408659224c4c7bfce8ced20 /tensorflow | |
parent | 2a1a0d729fb23ac8758fff64119503e8e3e7b94d (diff) |
Make FunctionLibraryDefinition::AddFunctionDef() check for conflicting op name
This prevents a function from masking an existing op.
Change: 154720287
Diffstat (limited to 'tensorflow')
-rw-r--r-- | tensorflow/core/framework/function.cc | 6 | ||||
-rw-r--r-- | tensorflow/core/framework/function_test.cc | 9 | ||||
-rw-r--r-- | tensorflow/core/graph/graph.cc | 7 | ||||
-rw-r--r-- | tensorflow/core/graph/graph_test.cc | 15 |
4 files changed, 22 insertions, 15 deletions
diff --git a/tensorflow/core/framework/function.cc b/tensorflow/core/framework/function.cc index 8a7d96c38a..c731155924 100644 --- a/tensorflow/core/framework/function.cc +++ b/tensorflow/core/framework/function.cc @@ -882,6 +882,12 @@ Status FunctionLibraryDefinition::AddFunctionDef(const FunctionDef& fdef) { fdef.signature().name(), " already exists in function library."); } + const OpDef* op_def; + if (default_registry_->LookUpOpDef(fdef.signature().name(), &op_def).ok()) { + return errors::InvalidArgument( + "Cannot add function '", fdef.signature().name(), + "' because an op with the same name already exists."); + } ptr.reset(new FunctionDefAndOpRegistration(fdef)); return Status::OK(); } diff --git a/tensorflow/core/framework/function_test.cc b/tensorflow/core/framework/function_test.cc index efc6a2edcc..07462a575e 100644 --- a/tensorflow/core/framework/function_test.cc +++ b/tensorflow/core/framework/function_test.cc @@ -944,6 +944,15 @@ TEST(FunctionLibraryDefinitionTest, AddFunctionDef) { ASSERT_NE(second, nullptr); EXPECT_EQ(second->DebugString(), test::function::WXPlusB().signature().DebugString()); + + // Can't add function with same name as existing op + FunctionDef fdef = test::function::XTimesTwo(); + fdef.mutable_signature()->set_name("Add"); + Status s = lib_def.AddFunctionDef(fdef); + EXPECT_FALSE(s.ok()); + EXPECT_EQ(s.error_message(), + "Cannot add function 'Add' because an op with the same name " + "already exists."); } TEST(FunctionLibraryDefinitionTest, AddGradientDef) { diff --git a/tensorflow/core/graph/graph.cc b/tensorflow/core/graph/graph.cc index fae9f26f76..e1657cb862 100644 --- a/tensorflow/core/graph/graph.cc +++ b/tensorflow/core/graph/graph.cc @@ -380,13 +380,6 @@ Status Graph::AddFunctionLibrary(const FunctionDefLibrary& fdef_lib) { // Ignore duplicate FunctionDefs continue; } - // TODO(skyewm): fix test breakages and reenable this check - // const OpDef* op_def; - // if (ops_.LookUpOpDef(fdef.signature().name(), &op_def).ok()) { - // return errors::InvalidArgument( - // "Cannot add function '", fdef.signature().name(), - // "' because an op with the same name already exists."); - // } TF_RETURN_IF_ERROR(ops_.AddFunctionDef(fdef)); } for (const GradientDef& grad : fdef_lib.gradient()) { diff --git a/tensorflow/core/graph/graph_test.cc b/tensorflow/core/graph/graph_test.cc index 739ad90efd..502b7b26da 100644 --- a/tensorflow/core/graph/graph_test.cc +++ b/tensorflow/core/graph/graph_test.cc @@ -412,15 +412,14 @@ TEST_F(GraphTest, AddFunctionLibrary) { "Cannot add function 'XTimesTwo' because a different function with " "the same name already exists."); - // TODO(skyewm): reenable along with duplicate op check // Function with same name as an existing op triggers an error - // error_proto = proto; - // error_proto.mutable_function(0)->mutable_signature()->set_name("Add"); - // s = graph_.AddFunctionLibrary(error_proto); - // EXPECT_FALSE(s.ok()); - // EXPECT_EQ(s.error_message(), - // "Cannot add function 'Add' because an op with the same name " - // "already exists."); + error_proto = proto; + error_proto.mutable_function(0)->mutable_signature()->set_name("Add"); + s = graph_.AddFunctionLibrary(error_proto); + EXPECT_FALSE(s.ok()); + EXPECT_EQ(s.error_message(), + "Cannot add function 'Add' because an op with the same name " + "already exists."); // Adding a gradient function to an existing function is ok GradientDef* grad = proto.add_gradient(); |