| 105 | class PatternMatcherTest : public ::testing::Test {}; |
| 106 | |
| 107 | TEST_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. |
nothing calls this directly
no test coverage detected