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

Function IsTrivialIdentity

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

Source from the content-addressed store, hash-verified

33namespace grappler {
34
35bool 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
61bool IsTrivialOp(const utils::MutableNodeView& node_view) {
62 // Remove the stop gradient nodes since they serve no purpose once the graph

Callers 1

IsTrivialOpFunction · 0.85

Calls 6

NumControllingFaninsMethod · 0.80
NumControlledFanoutsMethod · 0.80
node_viewMethod · 0.80
IsSwitchFunction · 0.50
IsMergeFunction · 0.50
nodeMethod · 0.45

Tested by

no test coverage detected