MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TEST_F

Function TEST_F

tensorflow/core/grappler/utils/pattern_utils_test.cc:107–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105class PatternMatcherTest : public ::testing::Test {};
106
107TEST_F(PatternMatcherTest, MatMulBiasAddGeluNodeIndices) {
108 ::tensorflow::Status status;
109 GraphDef graph;
110 GetMatMulBiasAddGeluGraph(&graph);
111 OpTypePattern pattern = GetMatMulBiasAddGeluPattern();
112 MutableGraphView graph_view(&graph, &status);
113 TF_ASSERT_OK(status);
114 graph_view.SortTopologically(/*ignore_cycles=*/false, {});
115 auto root_node_view = graph_view.GetNode("gelu");
116
117 SubGraphMatcher<MatchingDirection::kFollowInputs> graph_matcher(&graph_view);
118 std::map<string, int> matched_nodes_map; // label to node index map
119 std::set<int> remove_node_indices;
120 bool found_match = graph_matcher.GetMatchedNodes(
121 pattern, root_node_view, &matched_nodes_map, &remove_node_indices);
122
123 EXPECT_TRUE(found_match);
124 EXPECT_FALSE(matched_nodes_map.empty());
125 EXPECT_FALSE(remove_node_indices.empty());
126
127 bool all_indices_matched = true;
128 for (auto it = matched_nodes_map.begin(); it != matched_nodes_map.begin();
129 it++) {
130 auto label = absl::StripPrefix(it->first, "my_");
131 int matched_node_idx = it->second;
132 int expected_node_idx = graph_view.GetNode(label)->node_index();
133 if (matched_node_idx != expected_node_idx) {
134 all_indices_matched = false;
135 break;
136 }
137 }
138 EXPECT_TRUE(all_indices_matched);
139}
140
141// Pattern should not be matched if any of candidate remove nodes has external
142// dependent.

Callers

nothing calls this directly

Calls 15

SortTopologicallyMethod · 0.80
GetMatchedNodesMethod · 0.80
NumNodesMethod · 0.80
GetMutationBuilderMethod · 0.80
set_opMethod · 0.80
GetNodeMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
node_indexMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected