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

Function QuantizeNodes

tensorflow/tools/graph_transforms/quantize_nodes.cc:589–950  ·  view source on GitHub ↗

Converts any float ops that have eight-bit equivalents into their quantized forms, so that as much calculation as possible is done in the lower-precision format.

Source from the content-addressed store, hash-verified

587// forms, so that as much calculation as possible is done in the lower-precision
588// format.
589Status QuantizeNodes(const GraphDef& input_graph_def,
590 const TransformFuncContext& context,
591 GraphDef* output_graph_def) {
592 // Loop through all of the quantizable op types, and replace any occurrences
593 // with equivalent sub-graphs with quantized ops at their core. For example
594 // this one-input operation:
595 //
596 // Input(float)
597 // |
598 // v
599 // Operation
600 // |
601 // v
602 // (float)
603 //
604 // Will be turned into it's quantized equivalent:
605 //
606 // Input(float) ReshapeDims
607 // +------v v-------------+
608 // | Reshape
609 // | |
610 // | | ReductionDims
611 // | +-----+ |
612 // | | +---c---------+
613 // | v v v v-------+
614 // | Min Max
615 // | +----+ |
616 // v v v--------+
617 // Quantize
618 // |
619 // v
620 // QuantizedOperation
621 // | | |
622 // v v v
623 // Dequantize
624 // |
625 // v
626 // (float)
627 //
628 // This keeps the inputs and outputs visible to the rest of the graph in
629 // float
630 // and converts them down to quantized buffers internally for the
631 // computation.
632 // The result will end up with a lot of redundant dequantize/quantize pairs
633 // between adjacent quantized ops, but a later pass removes these where it
634 // can.
635
636 std::set<string> ops_to_ignore;
637 if (context.params.count("ignore_op") > 0) {
638 for (const string& name : context.params.at("ignore_op")) {
639 ops_to_ignore.insert(name);
640 }
641 }
642
643 const std::vector<QuantizedOpInfo>& op_list = GetQuantizedOpList();
644 string op_pattern;
645 bool is_first = true;
646 std::map<string, QuantizedOpInfo> op_map;

Callers

nothing calls this directly

Calls 15

QuantizePlaceholdersFunction · 0.85
IsGraphValidFunction · 0.85
HoistFakeQuantsFunction · 0.85
ExtractRangeFromParamsFunction · 0.85
ReplaceMatchingOpTypesFunction · 0.85
GetInOutTypesFunction · 0.85
CopyOriginalMatchFunction · 0.85
UniqueNodeNameFromInputFunction · 0.85
AddNodeInputFunction · 0.85
NodeNameFromInputFunction · 0.85
CopyNodeAttrFunction · 0.85

Tested by

no test coverage detected