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

Function CopyGraph

tensorflow/c/c_api.cc:1827–1865  ·  view source on GitHub ↗

Copies `src_graph` into `dst_graph`. Any node in `src_graph` with input `src_inputs[i]` will have that input replaced with `dst_inputs[i]`. `prefix` will be prepended to copied node names. `control_deps` are nodes in `dst_graph` that the copied `src_graph` nodes will have control dependencies on. `return_nodes` are nodes in `src_graph`, and the new corresponding nodes in `dst_graph` will be retur

Source from the content-addressed store, hash-verified

1825// on. `return_nodes` are nodes in `src_graph`, and the new corresponding nodes
1826// in `dst_graph` will be returned. `return_nodes` must be non-null.
1827Status CopyGraph(Graph* src_graph, Graph* dst_graph,
1828 tensorflow::ShapeRefiner* dst_refiner,
1829 const TF_Output* src_inputs,
1830 const std::vector<tensorflow::Output>& dst_inputs,
1831 const string& prefix,
1832 const std::vector<tensorflow::Operation>& control_deps,
1833 const TF_Output* nodes_to_return, int nreturn_nodes,
1834 std::vector<tensorflow::Output>* return_nodes) {
1835 DCHECK(return_nodes != nullptr);
1836 GraphDef gdef;
1837 src_graph->ToGraphDef(&gdef);
1838
1839 tensorflow::ImportGraphDefOptions opts;
1840 opts.prefix = prefix;
1841
1842 for (int i = 0; i < dst_inputs.size(); ++i) {
1843 opts.input_map[ToTensorId(src_inputs[i])] =
1844 TensorId(dst_inputs[i].node()->name(), dst_inputs[i].index());
1845 }
1846 opts.skip_mapped_nodes = true;
1847
1848 for (const tensorflow::Operation& op : control_deps) {
1849 opts.control_dependencies.push_back(op.node()->name());
1850 }
1851
1852 for (int i = 0; i < nreturn_nodes; ++i) {
1853 opts.return_tensors.push_back(ToTensorId(nodes_to_return[i]));
1854 }
1855
1856 // TODO(skyewm): change to OutputTensor
1857 tensorflow::ImportGraphDefResults results;
1858 TF_RETURN_IF_ERROR(
1859 ImportGraphDef(opts, gdef, dst_graph, dst_refiner, &results));
1860
1861 for (const auto& pair : results.return_tensors) {
1862 return_nodes->emplace_back(pair.first, pair.second);
1863 }
1864 return Status::OK();
1865}
1866
1867bool ValidateConstWhileParams(const TF_WhileParams& params, TF_Status* s) {
1868 if (params.cond_graph == nullptr || params.body_graph == nullptr ||

Callers 1

TF_FinishWhileHelperFunction · 0.70

Calls 9

nameMethod · 0.65
TensorIdClass · 0.50
ImportGraphDefFunction · 0.50
ToGraphDefMethod · 0.45
sizeMethod · 0.45
nodeMethod · 0.45
indexMethod · 0.45
push_backMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected