Add new flag to GrapplerItem::AllowedOptimizations
PiperOrigin-RevId: 224854657
This commit is contained in:
parent
9d44119fb1
commit
4e7564ef05
@ -86,13 +86,12 @@ struct GrapplerItem {
|
|||||||
// Is it allowed to add nodes to the graph that do not have registered
|
// Is it allowed to add nodes to the graph that do not have registered
|
||||||
// gradient function.
|
// gradient function.
|
||||||
bool non_differentiable_rewrites = true;
|
bool non_differentiable_rewrites = true;
|
||||||
// By default we are not allowed to inline ops with side effects into the
|
|
||||||
// main graph, because we can't guarantee that after pruning these ops will
|
// By default we are allowed to prune ops with side-effects from the main
|
||||||
// be executed. However if we are optimizing a function library (see
|
// graph if they are not in transitive fanin of the fetch nodes. If we are
|
||||||
// meta_optimizer.cc) and a graph was instantiated by a function definition,
|
// optimizing a graph that was instantiated by a function definition, we
|
||||||
// we can do that, because functions guarantee that all side effects will be
|
// must keep all side effects intact.
|
||||||
// executed (see function_optimizer.cc for details).
|
bool prune_ops_with_side_effects = true;
|
||||||
bool inline_ops_with_side_effects = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::unordered_set<string>& devices() const;
|
const std::unordered_set<string>& devices() const;
|
||||||
|
@ -1472,7 +1472,7 @@ Status InlineIndirectFunctionCall(const NodeDef& func_node,
|
|||||||
// for the function body, because functions have strict semantics.
|
// for the function body, because functions have strict semantics.
|
||||||
|
|
||||||
if (num_fanouts == 0 && happens_after.empty() &&
|
if (num_fanouts == 0 && happens_after.empty() &&
|
||||||
!ctx->allowed_optimizations().inline_ops_with_side_effects) {
|
ctx->allowed_optimizations().prune_ops_with_side_effects) {
|
||||||
return errors::Internal(
|
return errors::Internal(
|
||||||
"Can't inline a function with a side-effectful op with empty "
|
"Can't inline a function with a side-effectful op with empty "
|
||||||
"fanouts and empty output control edge set. Function body node: ",
|
"fanouts and empty output control edge set. Function body node: ",
|
||||||
|
@ -533,9 +533,10 @@ Status MetaOptimizer::Optimize(Cluster* cluster, const GrapplerItem& item,
|
|||||||
VLOG(3) << added_devices.error_message();
|
VLOG(3) << added_devices.error_message();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can safely inline nested function calls with side-effectful ops into
|
// We are not allowed to prune side effects from the graph instantiated
|
||||||
// the function body (see function_optimizer.cc for details).
|
// by the function definition, because we must guarantee function
|
||||||
func_item.allowed_optimizations().inline_ops_with_side_effects = true;
|
// execution semantics wrt side effects (see function_optimizer.cc).
|
||||||
|
func_item.allowed_optimizations().prune_ops_with_side_effects = false;
|
||||||
|
|
||||||
// Optimize function body graph.
|
// Optimize function body graph.
|
||||||
GraphDef optimized_func_graph;
|
GraphDef optimized_func_graph;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user