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.
| 587 | // forms, so that as much calculation as possible is done in the lower-precision |
| 588 | // format. |
| 589 | Status 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; |
nothing calls this directly
no test coverage detected