Insert conversion op, connect it to the graph and remove the old edge.
| 566 | |
| 567 | // Insert conversion op, connect it to the graph and remove the old edge. |
| 568 | Status ProcessTargetEdges(Graph* graph, const string& quant_op_type, |
| 569 | const std::vector<EdgeToConvert>& target_edges) { |
| 570 | // Remember previously converted ops to avoid duplicated conversion on the |
| 571 | // same input. |
| 572 | std::unordered_map<string, Node*, StringPieceHasher> name_index; |
| 573 | std::vector<Node*> added_variables; |
| 574 | for (const EdgeToConvert edge : target_edges) { |
| 575 | Node* convert_node; |
| 576 | string name_prefix = edge.edge->src()->name(); |
| 577 | |
| 578 | auto iter = name_index.find(name_prefix); |
| 579 | if (iter == name_index.end()) { |
| 580 | TF_RETURN_IF_ERROR(MakeQuantizeOp(graph, name_prefix, quant_op_type, edge, |
| 581 | &added_variables, &convert_node)); |
| 582 | name_index[name_prefix] = convert_node; |
| 583 | } else { |
| 584 | convert_node = iter->second; |
| 585 | } |
| 586 | |
| 587 | graph->AddEdge(convert_node, 0, edge.edge->dst(), edge.edge->dst_input()); |
| 588 | graph->RemoveEdge(edge.edge); |
| 589 | } |
| 590 | |
| 591 | TF_RETURN_IF_ERROR(AddSaveAndRestore(graph, added_variables)); |
| 592 | |
| 593 | return Status::OK(); |
| 594 | } |
| 595 | |
| 596 | } // namespace |
| 597 |
no test coverage detected