Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/eager/polymorphic_function/quarantine.py: 74%
19 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
1# Copyright 2022 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ==============================================================================
15"""Internal APIs to be removed in the future."""
17from tensorflow.python.eager.polymorphic_function import atomic_function
18from tensorflow.python.eager.polymorphic_function import eager_function_run
19from tensorflow.python.util import deprecation
20from tensorflow.python.util.tf_export import tf_export
23# TODO(b/244360504): Remove this API in favour of the graph transformation API.
24def add_function_callback(function_callback):
25 """Add a callback function for Function creation.
27 The callback function has the signature:
29 `def function_callback(function: AtomicFunction) -> AtomicFunction`
31 Repeated registration of the same callback function will cause repeated
32 transformations.
34 After a callback is added, it can be removed with the
35 `remove_function_callback()` method.
37 Args:
38 function_callback: The callback to add.
39 """
40 atomic_function.FUNCTION_TRANSFORMS.append(function_callback)
43# TODO(b/244360504): Remove this API in favour of the graph transformation API.
44def remove_function_callback(function_callback):
45 """Remove an already-added function callback.
47 See the doc string of `add_function_callback()` for more information.
49 Args:
50 function_callback: The callback to remove.
51 """
52 atomic_function.FUNCTION_TRANSFORMS.remove(function_callback)
55# TODO(b/244360504): Remove this API in favour of the graph transformation API.
56def clear_function_callbacks():
57 """Clear all function callbacks, if any have been regisered."""
58 atomic_function.FUNCTION_TRANSFORMS.clear()
61@deprecation.deprecated(
62 None, "Use `tf.config.run_functions_eagerly` instead of the experimental "
63 "version.")
64@tf_export("config.experimental_run_functions_eagerly")
65def experimental_run_functions_eagerly(run_eagerly):
66 """Enables / disables eager execution of `tf.function`s.
68 Calling `tf.config.experimental_run_functions_eagerly(True)` will make all
69 invocations of `tf.function` run eagerly instead of running as a traced graph
70 function.
72 See `tf.config.run_functions_eagerly` for an example.
74 Note: This flag has no effect on functions passed into tf.data transformations
75 as arguments. tf.data functions are never executed eagerly and are always
76 executed as a compiled Tensorflow Graph.
78 Args:
79 run_eagerly: Boolean. Whether to run functions eagerly.
81 Returns:
82 None
83 """
84 return eager_function_run.run_functions_eagerly(run_eagerly)
87@deprecation.deprecated(
88 None,
89 "Use tf.config.functions_run_eagerly instead of the experimental version.")
90@tf_export("config.experimental_functions_run_eagerly")
91def experimental_functions_run_eagerly():
92 """Returns the value of the `experimental_run_functions_eagerly` setting."""
93 return eager_function_run.functions_run_eagerly()