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

Method ToGraphDefSubRange

tensorflow/core/graph/graph.cc:666–728  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

664}
665
666void Graph::ToGraphDefSubRange(GraphDef* graph_def, int from_node_id) const {
667 graph_def->Clear();
668 *graph_def->mutable_versions() = versions();
669 *graph_def->mutable_library() = ops_.ToProto();
670
671 graph_def->mutable_node()->Reserve(std::max(1, num_nodes() - from_node_id));
672
673 std::vector<const Edge*>
674 inputs; // Construct this outside the loop for speed.
675 for (auto id = from_node_id; id < num_node_ids(); ++id) {
676 const Node* node = FindNodeId(id);
677 if (node == nullptr || !node->IsOp()) continue;
678 NodeDef* node_def = graph_def->add_node();
679 *node_def = node->def();
680
681 // Use the node's assigned device, if any, instead of the device requested
682 // in the NodeDef.
683 if (!node->assigned_device_name().empty()) {
684 node_def->set_device(node->assigned_device_name());
685 }
686
687 // Get the inputs for this Node. We make sure control inputs are
688 // after data inputs, as required by GraphDef.
689 inputs.clear();
690 inputs.resize(node->num_inputs(), nullptr);
691 for (const Edge* edge : node->in_edges()) {
692 if (edge->IsControlEdge()) {
693 inputs.push_back(edge);
694 } else {
695 CHECK(inputs[edge->dst_input()] == nullptr)
696 << "Edge " << edge->src()->DebugString() << ":"
697 << edge->dst()->DebugString() << " with dst_input "
698 << edge->dst_input() << " and had pre-existing input edge "
699 << inputs[edge->dst_input()]->src()->DebugString() << ":"
700 << inputs[edge->dst_input()]->dst()->DebugString();
701
702 inputs[edge->dst_input()] = edge;
703 }
704 }
705 // Sort the control inputs for more predictable serialization.
706 std::sort(inputs.begin() + node->num_inputs(), inputs.end(),
707 [](const Edge* a, const Edge* b) -> bool {
708 return a->src()->name() < b->src()->name();
709 });
710 node_def->clear_input();
711 node_def->mutable_input()->Reserve(inputs.size());
712
713 for (size_t i = 0; i < inputs.size(); ++i) {
714 const Edge* edge = inputs[i];
715 if (edge == nullptr) {
716 if (i < node->requested_inputs().size()) {
717 node_def->add_input(node->requested_inputs()[i]);
718 } else {
719 node_def->add_input("");
720 }
721 } else {
722 const Node* src = edge->src();
723 if (!src->IsOp()) continue;

Callers 1

MaybeExtendGraphMethod · 0.80

Calls 15

sortFunction · 0.85
IsOpMethod · 0.80
AddInputFunction · 0.70
nameMethod · 0.65
maxFunction · 0.50
ClearMethod · 0.45
ToProtoMethod · 0.45
ReserveMethod · 0.45
emptyMethod · 0.45
set_deviceMethod · 0.45
clearMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected