| 59 | } |
| 60 | |
| 61 | bool IsTrivialOp(const utils::MutableNodeView& node_view) { |
| 62 | // Remove the stop gradient nodes since they serve no purpose once the graph |
| 63 | // is built. Also remove Identity ops. |
| 64 | const auto* node = node_view.node(); |
| 65 | if (IsStopGradient(*node)) { |
| 66 | return true; |
| 67 | } |
| 68 | if (IsIdentity(*node) || IsIdentityNSingleInput(*node)) { |
| 69 | return IsTrivialIdentity(node_view); |
| 70 | } |
| 71 | const bool no_fanins = node_view.NumRegularFanins() == 0 && |
| 72 | node_view.NumControllingFanins() == 0; |
| 73 | if (IsNoOp(*node) && no_fanins) { |
| 74 | return true; |
| 75 | } |
| 76 | // Const nodes are always executed before anything else, so if they only |
| 77 | // have control outputs we can remove them. |
| 78 | if (IsConstant(*node) && no_fanins && node_view.NumRegularFanouts() == 0) { |
| 79 | return true; |
| 80 | } |
| 81 | return IsAddN(*node) && node_view.NumRegularFanins() <= 1; |
| 82 | } |
| 83 | |
| 84 | bool RemovalIncreasesEdgeCount(const utils::MutableNodeView& node_view) { |
| 85 | int in_degree = |
no test coverage detected