Skip to content

Commit

Permalink
Change the way we set endpoints deprecated in api_def.proto.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 203004822
  • Loading branch information
annarev authored and tensorflower-gardener committed Jul 2, 2018
1 parent c1560f0 commit 466e6ab
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tensorflow/core/api_def/api_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,33 @@ void TestAllApiDefAttributeNamesAreValid(
}
}
}

void TestDeprecatedAttributesSetCorrectly(
const std::unordered_map<string, ApiDef>& api_defs_map) {
for (const auto& name_and_api_def : api_defs_map) {
int num_deprecated_endpoints = 0;
const auto& api_def = name_and_api_def.second;
for (const auto& endpoint : api_def.endpoint()) {
if (endpoint.deprecated()) {
++num_deprecated_endpoints;
}
}

const auto& name = name_and_api_def.first;
ASSERT_TRUE(api_def.deprecation_message().empty() ||
num_deprecated_endpoints == 0)
<< "Endpoints are set to 'deprecated' for deprecated op " << name
<< ". If an op is deprecated (i.e. deprecation_message is set), "
<< "all the endpoints are deprecated implicitly and 'deprecated' "
<< "field should not be set.";
if (num_deprecated_endpoints > 0) {
ASSERT_NE(num_deprecated_endpoints, api_def.endpoint_size())
<< "All " << name << " endpoints are deprecated. Please, set "
<< "deprecation_message in api_def_" << name << ".pbtxt instead. "
<< "to indicate that the op is deprecated.";
}
}
}
} // namespace

class BaseApiTest : public ::testing::Test {
Expand Down Expand Up @@ -236,6 +263,11 @@ TEST_F(BaseApiTest, AllApiDefAttributeNamesAreValid) {
TestAllApiDefAttributeNamesAreValid(ops_, api_defs_map_);
}

// Checks that deprecation is set correctly.
TEST_F(BaseApiTest, DeprecationSetCorrectly) {
TestDeprecatedAttributesSetCorrectly(api_defs_map_);
}

class PythonApiTest : public ::testing::Test {
protected:
PythonApiTest() {
Expand Down Expand Up @@ -272,4 +304,9 @@ TEST_F(PythonApiTest, AllApiDefAttributeNamesAreValid) {
TestAllApiDefAttributeNamesAreValid(ops_, api_defs_map_);
}

// Checks that deprecation is set correctly.
TEST_F(PythonApiTest, DeprecationSetCorrectly) {
TestDeprecatedAttributesSetCorrectly(api_defs_map_);
}

} // namespace tensorflow
10 changes: 10 additions & 0 deletions tensorflow/core/framework/api_def.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ import "tensorflow/core/framework/attr_value.proto";
message ApiDef {
// Name of the op (in the OpDef) to specify the API for.
string graph_op_name = 1;
// If this op is deprecated, set deprecation message to the message
// that should be logged when this op is used.
// The message should indicate alternative op to use, if any.
string deprecation_message = 12;

enum Visibility {
// Normally this is "VISIBLE" unless you are inheriting a
Expand All @@ -56,6 +60,12 @@ message ApiDef {
// use a snake_case convention instead of CamelCase.
string name = 1;

// Set if this endpoint is deprecated. If set to true, a message suggesting
// to use a non-deprecated endpoint instead will be printed. If all
// endpoints are deprecated, set deprecation_message in ApiDef instead.
bool deprecated = 3;
// Deprecated: set deprecated to "true" instead. We can auto-generate
// the message.
// If this endpoint is deprecated, set deprecation_message to a
// message that should be logged when the endpoint is used.
// The message should indicate alternative endpoint to use, if any.
Expand Down

0 comments on commit 466e6ab

Please sign in to comment.