TensorFlow: make EqualGraphDef ignore internal attributes (those that
starts with "_", which are not part of the public interface of ops and can change. Change: 115719866
This commit is contained in:
parent
1827f66ab8
commit
e9c1ccd421
@ -156,9 +156,16 @@ bool EqualNodeDef(const NodeDef& actual, const NodeDef& expected,
|
||||
|
||||
std::unordered_set<string> actual_attr;
|
||||
for (const auto& a : actual.attr()) {
|
||||
if (!a.first.empty() && a.first[0] == '_') {
|
||||
continue;
|
||||
}
|
||||
actual_attr.insert(a.first);
|
||||
}
|
||||
for (const auto& e : expected.attr()) {
|
||||
if (!e.first.empty() && e.first[0] == '_') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (actual_attr.erase(e.first) == 0) {
|
||||
if (diff != nullptr) {
|
||||
*diff = strings::StrCat("Node named '", actual.name(),
|
||||
|
@ -30,8 +30,10 @@ namespace tensorflow {
|
||||
bool EqualGraphDef(const GraphDef& actual, const GraphDef& expected,
|
||||
string* diff);
|
||||
|
||||
// Determines if actual and expected are equal, ignoring ordering of
|
||||
// attrs and control inputs. If the NodeDefs are different and
|
||||
// Determines if actual and expected are equal, ignoring: ordering of
|
||||
// attrs, internal attributes, and control inputs.
|
||||
//
|
||||
// If the NodeDefs are different and
|
||||
// diff != nullptr, *diff is set to an explanation of the difference.
|
||||
bool EqualNodeDef(const NodeDef& actual, const NodeDef& expected, string* diff);
|
||||
|
||||
|
@ -295,5 +295,18 @@ TEST_F(EqualGraphDefTest, AttrMismatch) {
|
||||
diff_);
|
||||
}
|
||||
|
||||
TEST_F(EqualGraphDefTest, IgnoreInternalAttrs) {
|
||||
Node* a = Input(e_.opts().WithName("A"));
|
||||
NodeDef actual(a->def());
|
||||
AddNodeAttr("foo", "bar", &actual);
|
||||
// Internal attrs are ignored.
|
||||
AddNodeAttr("_class", 5, &actual);
|
||||
|
||||
NodeDef expected(a->def());
|
||||
AddNodeAttr("foo", "bar", &expected);
|
||||
AddNodeAttr("_kernel", "eigen", &actual);
|
||||
EXPECT_TRUE(EqualNodeDef(actual, expected, &diff_));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tensorflow
|
||||
|
Loading…
Reference in New Issue
Block a user