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

Method OptimizeGraph

tensorflow/core/grappler/optimizers/meta_optimizer.cc:429–583  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

427}
428
429Status MetaOptimizer::OptimizeGraph(Cluster* cluster, const GrapplerItem& item,
430 GraphDef* optimized_graph) {
431 int min_graph_nodes = cfg_.min_graph_nodes() == 0 ? kDefaultMinGraphNodes
432 : cfg_.min_graph_nodes();
433 if (item.graph.node_size() < min_graph_nodes) {
434 VLOG(3) << "Skipping optimization, graph has less than " << min_graph_nodes
435 << " nodes.";
436 *optimized_graph = item.graph;
437 return Status::OK();
438 }
439
440 std::vector<std::unique_ptr<GraphOptimizer>> optimizers;
441 if (cfg_.optimizers().empty()) {
442 TF_RETURN_IF_ERROR(InitializeOptimizers(&optimizers));
443 } else {
444 TF_RETURN_IF_ERROR(InitializeOptimizersByName(&optimizers));
445 }
446
447 // Initialize the configured verifiers.
448 std::vector<std::unique_ptr<GraphVerifier>> inter_optimizer_verifiers;
449 std::vector<std::unique_ptr<GraphVerifier>> post_optimization_verifiers;
450 InitializeVerifiers(&inter_optimizer_verifiers, &post_optimization_verifiers);
451 if (inter_optimizer_verifiers.empty()) {
452 VLOG(2) << "No inter optimizer verifiers have been configured";
453 } else {
454 VLOG(2) << inter_optimizer_verifiers.size()
455 << " inter optimizer verifiers have been configured";
456 }
457 if (post_optimization_verifiers.empty()) {
458 VLOG(2) << "No post optimization verifiers have been configured";
459 } else {
460 VLOG(2) << post_optimization_verifiers.size()
461 << " post optimization verifiers have been configured";
462 }
463
464 VLOG(2) << "Optimize GrapplerItem: item.id=" << item.id
465 << " num_optimizers=" << optimizers.size()
466 << ", num nodes = " << item.graph.node_size();
467
468 if (optimizers.empty()) {
469 VLOG(3) << "Skipping graph optimization, no optimizers registered";
470 *optimized_graph = item.graph;
471 return Status::OK();
472 }
473
474 // Invariant: optimized_graph contains the most recently optimized version of
475 // the graph.
476 GrapplerItem optimized_item = item;
477 optimized_graph->Swap(&optimized_item.graph);
478
479 GraphOptimizationResult optimization_result(item.id);
480 GraphOptimizer* sa_optimizer = nullptr;
481 GraphOptimizer* multi_stream_optimizer = nullptr;
482
483 // Constants in the graph are normally compressed after model_pruner.
484 // Do it here if model pruner is disabled.
485 if (cfg_.disable_model_pruning()) {
486 CompressConstants(optimized_graph);

Callers 15

GetOptimizedGraphFunction · 0.45
grappler_optimizeFunction · 0.45
_inline_functionsMethod · 0.45
testBasicMethod · 0.45
testKeepNodesMethod · 0.45
testLoopsMethod · 0.45
testNoSwappingMethod · 0.45
testSimpleSwapMethod · 0.45

Calls 15

NumIterationsFunction · 0.85
DumpGraphDefToFileFunction · 0.85
IsRunOnceOptimizerFunction · 0.85
TopologicalSortFunction · 0.85
ReassignColocationFunction · 0.85
CompressConstantsFunction · 0.70
nameMethod · 0.65
StrCatFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
SwapMethod · 0.45
getMethod · 0.45

Tested by 14

GetOptimizedGraphFunction · 0.36
grappler_optimizeFunction · 0.36
_inline_functionsMethod · 0.36
testBasicMethod · 0.36
testKeepNodesMethod · 0.36
testLoopsMethod · 0.36
testNoSwappingMethod · 0.36
testSimpleSwapMethod · 0.36
testHintDoesRewriteMethod · 0.36