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

Function MakeQuantizeOp

tensorflow/core/graph/quantize_training.cc:536–565  ·  view source on GitHub ↗

Adds a QuantizeAndDequantizeV2 or FakeQuantizeWithMinMaxVars op (and required input nodes) based on edge. The result is stored in convert_node.

Source from the content-addressed store, hash-verified

534// (and required input nodes) based on edge.
535// The result is stored in convert_node.
536Status MakeQuantizeOp(Graph* graph, const string& name_prefix,
537 const string& quant_op_type, const EdgeToConvert& edge,
538 std::vector<Node*>* added_variables,
539 Node** convert_node) {
540 Node* input_min;
541 Node* input_max;
542 TF_RETURN_IF_ERROR(MakeInputMinMax(graph, name_prefix, edge, added_variables,
543 &input_min, &input_max));
544 string quant_name = strings::StrCat(name_prefix, "/", quant_op_type);
545 if (quant_op_type == "QuantizeAndDequantizeV2") {
546 TF_RETURN_IF_ERROR(NodeBuilder(quant_name, quant_op_type)
547 .Input(edge.edge->src())
548 .Input(input_min)
549 .Input(input_max)
550 .Attr("signed_input", edge.signed_input)
551 .Attr("num_bits", edge.num_bits)
552 .Attr("range_given", true)
553 .Finalize(graph, convert_node));
554 } else if (quant_op_type == "FakeQuantWithMinMaxVars") {
555 TF_RETURN_IF_ERROR(NodeBuilder(quant_name, quant_op_type)
556 .Input(edge.edge->src())
557 .Input(input_min)
558 .Input(input_max)
559 .Attr("num_bits", edge.num_bits)
560 .Finalize(graph, convert_node));
561 } else {
562 return errors::InvalidArgument("Unknown quant op type: ", quant_op_type);
563 }
564 return Status::OK();
565}
566
567// Insert conversion op, connect it to the graph and remove the old edge.
568Status ProcessTargetEdges(Graph* graph, const string& quant_op_type,

Callers 1

ProcessTargetEdgesFunction · 0.85

Calls 8

MakeInputMinMaxFunction · 0.85
InvalidArgumentFunction · 0.85
NodeBuilderClass · 0.70
StrCatFunction · 0.50
FinalizeMethod · 0.45
AttrMethod · 0.45
InputMethod · 0.45
srcMethod · 0.45

Tested by

no test coverage detected