diff --git a/tensorflow/python/autograph/operators/control_flow.py b/tensorflow/python/autograph/operators/control_flow.py index 77db7579ece..8b4e97c238c 100644 --- a/tensorflow/python/autograph/operators/control_flow.py +++ b/tensorflow/python/autograph/operators/control_flow.py @@ -80,6 +80,7 @@ from tensorflow.python.framework import func_graph from tensorflow.python.framework import ops from tensorflow.python.framework import tensor_util from tensorflow.python.ops import control_flow_ops +from tensorflow.python.ops import control_flow_util from tensorflow.python.ops import math_ops from tensorflow.python.ops import tensor_array_ops from tensorflow.python.ops.ragged import ragged_tensor @@ -429,7 +430,9 @@ def _known_len_tf_for_stmt( return control_flow_ops.cond(main_test, extra_test, lambda: False) return main_test - opts['maximum_iterations'] = n + # TODO(b/159186914): Remove. + if not control_flow_util.GraphOrParentsInXlaContext(ops.get_default_graph()): + opts['maximum_iterations'] = n _tf_while_stmt( aug_test, @@ -475,7 +478,9 @@ def _tf_ragged_for_stmt( return control_flow_ops.cond(main_test, extra_test, lambda: False) return main_test - opts['maximum_iterations'] = n + # TODO(b/159186914): Remove. + if not control_flow_util.GraphOrParentsInXlaContext(ops.get_default_graph()): + opts['maximum_iterations'] = n _tf_while_stmt( aug_test, @@ -524,8 +529,10 @@ def _tf_range_for_stmt( return control_flow_ops.cond(main_test, extra_test, lambda: False) return main_test - opts['maximum_iterations'] = math_ops.cast( - misc.get_range_len(start, limit, delta), dtypes.int32) + # TODO(b/159186914): Remove. + if not control_flow_util.GraphOrParentsInXlaContext(ops.get_default_graph()): + opts['maximum_iterations'] = math_ops.cast( + misc.get_range_len(start, limit, delta), dtypes.int32) _tf_while_stmt( aug_test,