From 1e1e08e367e3d1d1ad49710c51db82708232c38a Mon Sep 17 00:00:00 2001 From: Rohan Jain Date: Wed, 29 Apr 2020 09:21:51 -0700 Subject: [PATCH] Removing experimental from run_functions_eagerly. Also removed all references for the experimental one from documentation. PiperOrigin-RevId: 309036487 Change-Id: I91ab0f8857387c337f329c13e78ffba312ae362c --- .../autograph/g3doc/reference/debugging.md | 2 +- tensorflow/python/eager/context.py | 16 ++--- tensorflow/python/eager/def_function.py | 71 ++++++++++++++++++- tensorflow/python/keras/engine/training_v1.py | 2 +- .../ops/parallel_for/control_flow_ops.py | 2 +- .../api/golden/v1/tensorflow.config.pbtxt | 8 +++ .../api/golden/v2/tensorflow.config.pbtxt | 8 +++ 7 files changed, 96 insertions(+), 13 deletions(-) diff --git a/tensorflow/python/autograph/g3doc/reference/debugging.md b/tensorflow/python/autograph/g3doc/reference/debugging.md index abc30842297..2c2a96cec86 100644 --- a/tensorflow/python/autograph/g3doc/reference/debugging.md +++ b/tensorflow/python/autograph/g3doc/reference/debugging.md @@ -62,7 +62,7 @@ Adding a call to `tf.config.experimental_execute_functions_eagerly` before executing the function will land the debugger in the original code instead: ``` -tf.config.experimental_run_functions_eagerly(True) +tf.config.run_functions_eagerly(True) f(1) ``` diff --git a/tensorflow/python/eager/context.py b/tensorflow/python/eager/context.py index eb928614817..182b8478420 100644 --- a/tensorflow/python/eager/context.py +++ b/tensorflow/python/eager/context.py @@ -1793,7 +1793,7 @@ def executing_eagerly(): cases. * Executing inside `tf.function`, unless under `tf.init_scope` or - `tf.config.experimental_run_functions_eagerly(True)` is previously called. + `tf.config.run_functions_eagerly(True)` is previously called. * Executing inside a transformation function for `tf.dataset`. * `tf.compat.v1.disable_eager_execution()` is called. @@ -1815,8 +1815,8 @@ def executing_eagerly(): Inside `tf.function` after - `tf.config.experimental_run_functions_eagerly(True)` is called: - >>> tf.config.experimental_run_functions_eagerly(True) + `tf.config.run_functions_eagerly(True)` is called: + >>> tf.config.run_functions_eagerly(True) >>> @tf.function ... def fn(): ... with tf.init_scope(): @@ -1825,7 +1825,7 @@ def executing_eagerly(): >>> fn() True True - >>> tf.config.experimental_run_functions_eagerly(False) + >>> tf.config.run_functions_eagerly(False) Inside a transformation function for `tf.dataset`: @@ -1858,7 +1858,7 @@ def executing_eagerly_v1(): this API might return `False` in the following use cases. * Executing inside `tf.function`, unless under `tf.init_scope` or - `tf.config.experimental_run_functions_eagerly(True)` is previously called. + `tf.config.run_functions_eagerly(True)` is previously called. * Executing inside a transformation function for `tf.dataset`. * `tf.compat.v1.disable_eager_execution()` is called. @@ -1881,9 +1881,9 @@ def executing_eagerly_v1(): False Inside `tf.function` - after `tf.config.experimental_run_functions_eagerly(True)` is called: + after `tf.config.run_functions_eagerly(True)` is called: - >>> tf.config.experimental_run_functions_eagerly(True) + >>> tf.config.run_functions_eagerly(True) >>> @tf.function ... def fn(): ... with tf.init_scope(): @@ -1892,7 +1892,7 @@ def executing_eagerly_v1(): >>> fn() True True - >>> tf.config.experimental_run_functions_eagerly(False) + >>> tf.config.run_functions_eagerly(False) Inside a transformation function for `tf.dataset`: diff --git a/tensorflow/python/eager/def_function.py b/tensorflow/python/eager/def_function.py index e0273324a52..5fbf6c93ca4 100644 --- a/tensorflow/python/eager/def_function.py +++ b/tensorflow/python/eager/def_function.py @@ -41,6 +41,7 @@ from tensorflow.python.ops import resource_variable_ops from tensorflow.python.platform import tf_logging as logging from tensorflow.python.profiler import traceme from tensorflow.python.training.tracking import base as trackable +from tensorflow.python.util import deprecation from tensorflow.python.util import nest from tensorflow.python.util import object_identity from tensorflow.python.util import tf_decorator @@ -305,8 +306,11 @@ class UnliftedInitializerVariable(resource_variable_ops.UninitializedVariable): RUN_FUNCTIONS_EAGERLY = False +@deprecation.deprecated( + None, + "Use tf.config.run_functions_eagerly instead of the experimental version.") @tf_export("config.experimental_run_functions_eagerly") -def run_functions_eagerly(run_eagerly): +def experimental_run_functions_eagerly(run_eagerly): """Enables / disables eager execution of `tf.function`s. Calling `tf.config.experimental_run_functions_eagerly(True)` will make all @@ -345,6 +349,60 @@ def run_functions_eagerly(run_eagerly): Calling `tf.config.experimental_run_functions_eagerly(False)` will undo this behavior. + Note: This flag has no effect on functions passed into tf.data transformations + as arguments. tf.data functions are never executed eagerly and are always + executed as a compiled Tensorflow Graph. + + Args: + run_eagerly: Boolean. Whether to run functions eagerly. + """ + return run_functions_eagerly(run_eagerly) + + +@tf_export("config.run_functions_eagerly") +def run_functions_eagerly(run_eagerly): + """Enables / disables eager execution of `tf.function`s. + + Calling `tf.config.run_functions_eagerly(True)` will make all + invocations of `tf.function` run eagerly instead of running as a traced graph + function. + + This can be useful for debugging or profiling. For example, let's say you + implemented a simple iterative sqrt function, and you want to collect the + intermediate values and plot the convergence. Appending the values to a list + in `@tf.function` normally wouldn't work since it will just record the Tensors + being traced, not the values. Instead, you can do the following. + + >>> ys = [] + >>> + >>> @tf.function + ... def sqrt(x): + ... y = x / 2 + ... d = y + ... for _ in range(10): + ... d /= 2 + ... if y * y < x: + ... y += d + ... else: + ... y -= d + ... ys.append(y.numpy()) + ... return y + >>> + >>> tf.config.run_functions_eagerly(True) + >>> sqrt(tf.constant(2.)) + + >>> ys + [1.5, 1.25, 1.375, 1.4375, 1.40625, 1.421875, 1.4140625, 1.4179688, 1.4160156, + 1.4150391] + >>> tf.config.run_functions_eagerly(False) + + Calling `tf.config.run_functions_eagerly(False)` will undo this + behavior. + + Note: This flag has no effect on functions passed into tf.data transformations + as arguments. tf.data functions are never executed eagerly and are always + executed as a compiled Tensorflow Graph. + Args: run_eagerly: Boolean. Whether to run functions eagerly. """ @@ -352,9 +410,18 @@ def run_functions_eagerly(run_eagerly): RUN_FUNCTIONS_EAGERLY = bool(run_eagerly) +@deprecation.deprecated( + None, + "Use tf.config.functions_run_eagerly instead of the experimental version.") @tf_export("config.experimental_functions_run_eagerly") -def functions_run_eagerly(): +def experimental_functions_run_eagerly(): """Returns the value of the `experimental_run_functions_eagerly` setting.""" + return functions_run_eagerly() + + +@tf_export("config.functions_run_eagerly") +def functions_run_eagerly(): + """Returns the value of the `run_functions_eagerly` setting.""" return RUN_FUNCTIONS_EAGERLY diff --git a/tensorflow/python/keras/engine/training_v1.py b/tensorflow/python/keras/engine/training_v1.py index 3553dea89fb..0a40ce3899b 100644 --- a/tensorflow/python/keras/engine/training_v1.py +++ b/tensorflow/python/keras/engine/training_v1.py @@ -534,7 +534,7 @@ class Model(training_lib.Model): 'is enabled.') if not self.dynamic: if self._run_eagerly is None: - # Respect `tf.config.experimental_run_functions_eagerly` unless + # Respect `tf.config.run_functions_eagerly` unless # `run_eagerly` was explicitly passed to `compile`. return def_function.RUN_FUNCTIONS_EAGERLY else: diff --git a/tensorflow/python/ops/parallel_for/control_flow_ops.py b/tensorflow/python/ops/parallel_for/control_flow_ops.py index 5339af538fd..a7649778161 100644 --- a/tensorflow/python/ops/parallel_for/control_flow_ops.py +++ b/tensorflow/python/ops/parallel_for/control_flow_ops.py @@ -195,7 +195,7 @@ def pfor(loop_fn, iters, fallback_to_while_loop=True, parallel_iterations=None): if functions_run_eagerly: logging.warning( "It looks like tf.function behavior was disabled, perhaps using " - "tf.config.experimental_run_functions_eagerly. Vectorization " + "tf.config.run_functions_eagerly. Vectorization " "primitives (e.g. tf.vectorized_map) require tf.function to work. " "These primitives will override the disable.") def_function.run_functions_eagerly(False) diff --git a/tensorflow/tools/api/golden/v1/tensorflow.config.pbtxt b/tensorflow/tools/api/golden/v1/tensorflow.config.pbtxt index 7876afae9a4..bf0c669cd93 100644 --- a/tensorflow/tools/api/golden/v1/tensorflow.config.pbtxt +++ b/tensorflow/tools/api/golden/v1/tensorflow.config.pbtxt @@ -40,6 +40,10 @@ tf_module { name: "experimental_run_functions_eagerly" argspec: "args=[\'run_eagerly\'], varargs=None, keywords=None, defaults=None" } + member_method { + name: "functions_run_eagerly" + argspec: "args=[], varargs=None, keywords=None, defaults=None" + } member_method { name: "get_logical_device_configuration" argspec: "args=[\'device\'], varargs=None, keywords=None, defaults=None" @@ -60,6 +64,10 @@ tf_module { name: "list_physical_devices" argspec: "args=[\'device_type\'], varargs=None, keywords=None, defaults=[\'None\'], " } + member_method { + name: "run_functions_eagerly" + argspec: "args=[\'run_eagerly\'], varargs=None, keywords=None, defaults=None" + } member_method { name: "set_logical_device_configuration" argspec: "args=[\'device\', \'logical_devices\'], varargs=None, keywords=None, defaults=None" diff --git a/tensorflow/tools/api/golden/v2/tensorflow.config.pbtxt b/tensorflow/tools/api/golden/v2/tensorflow.config.pbtxt index 7876afae9a4..bf0c669cd93 100644 --- a/tensorflow/tools/api/golden/v2/tensorflow.config.pbtxt +++ b/tensorflow/tools/api/golden/v2/tensorflow.config.pbtxt @@ -40,6 +40,10 @@ tf_module { name: "experimental_run_functions_eagerly" argspec: "args=[\'run_eagerly\'], varargs=None, keywords=None, defaults=None" } + member_method { + name: "functions_run_eagerly" + argspec: "args=[], varargs=None, keywords=None, defaults=None" + } member_method { name: "get_logical_device_configuration" argspec: "args=[\'device\'], varargs=None, keywords=None, defaults=None" @@ -60,6 +64,10 @@ tf_module { name: "list_physical_devices" argspec: "args=[\'device_type\'], varargs=None, keywords=None, defaults=[\'None\'], " } + member_method { + name: "run_functions_eagerly" + argspec: "args=[\'run_eagerly\'], varargs=None, keywords=None, defaults=None" + } member_method { name: "set_logical_device_configuration" argspec: "args=[\'device\', \'logical_devices\'], varargs=None, keywords=None, defaults=None"