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

Function OptimizeGraph

tensorflow/core/grappler/optimizers/data/rebatch.cc:833–862  ·  view source on GitHub ↗

Helper function that given a GrapplerItem generates a mutated graph def with the batch size changed. The GrapplerItem could be generated from the main graph or could be a function graph.

Source from the content-addressed store, hash-verified

831// with the batch size changed. The GrapplerItem could be generated from the
832// main graph or could be a function graph.
833Status OptimizeGraph(const GrapplerItem& item, int64 num_replicas,
834 bool use_fallback, GraphDef* output) {
835 *output = item.graph;
836 MutableGraphView graph(output);
837
838 FunctionLibraryDefinition flib(OpRegistry::Global(), item.graph.library());
839
840 NodeDef* sink_node;
841 TF_RETURN_IF_ERROR(graph_utils::GetFetchNode(graph, item, &sink_node));
842
843 Status s = RecursivelyHandleOp(*sink_node, num_replicas, use_fallback, &flib,
844 &graph);
845 if (!s.ok()) {
846 if (use_fallback) {
847 VLOG(1) << "Failed to rebatch by rewriting the batch transformation ("
848 << s << "). Using a fallback method instead.";
849 // If RecursivelyHandleOp fails, we reset `graph` to use the original,
850 // graph, since that function may have mutated `graph`.
851 *output = item.graph;
852 graph = MutableGraphView(output);
853 TF_RETURN_IF_ERROR(
854 RebatchWithFallback(sink_node, num_replicas, &flib, &graph));
855 } else {
856 // Return the error
857 return s;
858 }
859 }
860 *output->mutable_library() = flib.ToProto();
861 return Status::OK();
862}
863
864} // anonymous namespace
865

Callers 2

RecursivelyHandleOpFunction · 0.70

Calls 7

GetFetchNodeFunction · 0.85
RebatchWithFallbackFunction · 0.85
RecursivelyHandleOpFunction · 0.70
MutableGraphViewClass · 0.50
libraryMethod · 0.45
okMethod · 0.45
ToProtoMethod · 0.45

Tested by

no test coverage detected