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

Method IsFoldable

tensorflow/core/grappler/optimizers/constant_folding.cc:915–1073  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

913}
914
915bool ConstantFolding::IsFoldable(const NodeDef& node,
916 const GraphProperties* properties) const {
917 // Folding not applicable to ops with no inputs.
918 if (node.input().empty()) {
919 return false;
920 }
921 // Skip constants, they're already folded
922 if (IsConstant(node)) {
923 return false;
924 }
925 // Don't fold stateful ops such as TruncatedNormal.
926 if (!IsFreeOfSideEffect(node)) {
927 return false;
928 }
929
930 // Skips nodes that must be preserved except whitelisted nodes.
931 if (nodes_to_preserve_.find(node.name()) != nodes_to_preserve_.end() &&
932 nodes_whitelist_.find(node.name()) == nodes_whitelist_.end()) {
933 return false;
934 }
935
936 // Skip control flow nodes, they can't be folded.
937 if (ModifiesFrameInfo(node)) {
938 return false;
939 }
940
941 // Skips ops that don't benefit from folding.
942 if (IsPlaceholder(node)) {
943 return false;
944 }
945 // `FakeParam` op is used as a placeholder in If branch function. It doesn't
946 // have a valid output when executed.
947 if (IsFakeParam(node)) {
948 return false;
949 }
950
951 if (node.op() == "AccumulateNV2") {
952 return false;
953 }
954 // Removing LoopCond nodes can screw up the partitioner.
955 if (node.op() == "LoopCond") {
956 return false;
957 }
958
959 const string& op = node.op();
960 if (op.find("Save") != string::npos || op.find("Restore") != string::npos ||
961 op.find("Reader") != string::npos) {
962 return false;
963 }
964 if (op.find("Quantized") != string::npos ||
965 op.find("FakeQuantWithMinMaxVars") != string::npos ||
966 op.find("QuantizeAndDequantizeV3") != string::npos ||
967 op.find("Sparse") == 0) {
968 return false;
969 }
970
971 // Don't fold nodes that contain TPU attributes.
972 // TODO(rmlarsen): We should be able to fold many of these nodes as long as we

Callers

nothing calls this directly

Calls 15

IsFreeOfSideEffectFunction · 0.85
ModifiesFrameInfoFunction · 0.85
IsFakeParamFunction · 0.85
HasTPUAttributesFunction · 0.85
IsControlInputFunction · 0.85
IsReallyConstantFunction · 0.85
HasControlInputsFunction · 0.85
DataTypeSizeFunction · 0.85
LookUpOpDefMethod · 0.80
GetOutputsMethod · 0.80
attrMethod · 0.80
HasOutputPropertiesMethod · 0.80

Tested by

no test coverage detected