| 33 | namespace grappler { |
| 34 | |
| 35 | bool IsTrivialIdentity(const utils::MutableNodeView& node_view) { |
| 36 | if (node_view.NumControllingFanins() > 0) { |
| 37 | // Node is driven by control dependency. |
| 38 | return false; |
| 39 | } |
| 40 | if (node_view.NumControlledFanouts() > 0) { |
| 41 | // Node drives control dependency. |
| 42 | return false; |
| 43 | } |
| 44 | for (const auto& regular_fanin : node_view.GetRegularFanins()) { |
| 45 | if (IsSwitch(*regular_fanin.node_view()->node())) { |
| 46 | // Node is driven by switch. |
| 47 | return false; |
| 48 | } |
| 49 | } |
| 50 | for (const auto& regular_fanouts : node_view.GetRegularFanouts()) { |
| 51 | for (const auto& regular_fanout : regular_fanouts) { |
| 52 | if (IsMerge(*regular_fanout.node_view()->node())) { |
| 53 | // Node feeds merge. |
| 54 | return false; |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | bool IsTrivialOp(const utils::MutableNodeView& node_view) { |
| 62 | // Remove the stop gradient nodes since they serve no purpose once the graph |
no test coverage detected