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
|
||||
// gradient function.
|
||||
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
|
||||
// be executed. However if we are optimizing a function library (see
|
||||
// meta_optimizer.cc) and a graph was instantiated by a function definition,
|
||||
// we can do that, because functions guarantee that all side effects will be
|
||||
// executed (see function_optimizer.cc for details).
|
||||
bool inline_ops_with_side_effects = false;
|
||||
|
||||
// By default we are allowed to prune ops with side-effects from the main
|
||||
// graph if they are not in transitive fanin of the fetch nodes. If we are
|
||||
// optimizing a graph that was instantiated by a function definition, we
|
||||
// must keep all side effects intact.
|
||||
bool prune_ops_with_side_effects = true;
|
||||
};
|
||||
|
||||
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.
|
||||
|
||||
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(
|
||||
"Can't inline a function with a side-effectful op with empty "
|
||||
"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();
|
||||
}
|
||||
|
||||
// We can safely inline nested function calls with side-effectful ops into
|
||||
// the function body (see function_optimizer.cc for details).
|
||||
func_item.allowed_optimizations().inline_ops_with_side_effects = true;
|
||||
// We are not allowed to prune side effects from the graph instantiated
|
||||
// by the function definition, because we must guarantee function
|
||||
// execution semantics wrt side effects (see function_optimizer.cc).
|
||||
func_item.allowed_optimizations().prune_ops_with_side_effects = false;
|
||||
|
||||
// Optimize function body graph.
|
||||
GraphDef optimized_func_graph;
|
||||
|
Loading…
x
Reference in New Issue
Block a user