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

Function IsTrivialOp

tensorflow/core/grappler/optimizers/model_pruner.cc:61–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59}
60
61bool 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
84bool RemovalIncreasesEdgeCount(const utils::MutableNodeView& node_view) {
85 int in_degree =

Callers 1

OptimizeMethod · 0.85

Calls 11

IsStopGradientFunction · 0.85
IsIdentityNSingleInputFunction · 0.85
IsTrivialIdentityFunction · 0.85
NumRegularFaninsMethod · 0.80
NumControllingFaninsMethod · 0.80
NumRegularFanoutsMethod · 0.80
IsIdentityFunction · 0.50
IsNoOpFunction · 0.50
IsConstantFunction · 0.50
IsAddNFunction · 0.50
nodeMethod · 0.45

Tested by

no test coverage detected