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

Function InitGraph

tensorflow/compiler/tf2xla/tf2xla.cc:362–399  ·  view source on GitHub ↗

InitGraph creates a graph based on the graph_def, that may then be converted to an xla::XlaComputation via ConvertGraphToXla. The graph is rewritten with _Arg and _Retval nodes, representing the inputs and outputs of the function that will be compiled. Each feed id causes a new _Arg node to be created, where we first collect all existing edges pointing from the named node's output index, and the

Source from the content-addressed store, hash-verified

360// with a new edge pointing from the named node's output index to that _Retval
361// node.
362Status InitGraph(const GraphDef& graph_def, const tf2xla::Config& config,
363 std::unique_ptr<Graph>* graph) {
364 TF_RETURN_IF_ERROR(ValidateConfig(config));
365
366 FunctionLibraryDefinition flib_def(OpRegistry::Global(), graph_def.library());
367 std::unique_ptr<Graph> g(new Graph(flib_def));
368
369 // Replace references to fed tensors with references to newly added
370 // placeholders.
371 GraphDef first_copy_def = graph_def;
372
373 // Maps from name:port of a feed to the name:port of the placeholder to use.
374 std::unordered_map<string, string> feed_remapping;
375 TF_RETURN_IF_ERROR(AddPlaceholdersForFeeds(config, g->op_registry(),
376 &feed_remapping, &first_copy_def));
377
378 // Prune the GraphDef first so that unknown ops that we aren't compiling get
379 // filtered out.
380 GraphDef second_copy_def;
381 TF_RETURN_IF_ERROR(
382 PruneGraphDefInto(config, first_copy_def, &second_copy_def));
383
384 TF_RETURN_IF_ERROR(AddDefaultAttrsToGraphDef(
385 &second_copy_def, *g->op_registry(), /*node_offset=*/0));
386
387 TF_RETURN_IF_ERROR(ConvertGraphDefToGraph(
388 GraphConstructorOptions(), std::move(second_copy_def), g.get()));
389 TF_RETURN_IF_ERROR(RewriteAndPruneGraph(g.get(), config, feed_remapping));
390
391 // Functionalize control flow.
392 TF_RETURN_IF_ERROR(FunctionalizeControlFlow(g.get(), &flib_def));
393 // After control flow functionalization, we might have more FunctionDef's
394 // (then/else branch, loop body). Add them to the graph.
395 TF_RETURN_IF_ERROR(g->AddFunctionLibrary(flib_def.ToProto()));
396
397 *graph = std::move(g);
398 return Status::OK();
399}
400
401} // namespace
402

Callers 1

ConvertGraphDefToXlaFunction · 0.70

Calls 13

ValidateConfigFunction · 0.85
AddPlaceholdersForFeedsFunction · 0.85
PruneGraphDefIntoFunction · 0.85
ConvertGraphDefToGraphFunction · 0.85
RewriteAndPruneGraphFunction · 0.85
FunctionalizeControlFlowFunction · 0.85
libraryMethod · 0.45
op_registryMethod · 0.45
getMethod · 0.45
AddFunctionLibraryMethod · 0.45

Tested by

no test coverage detected