From f8c45a5b38a81ff513cdced2063b838eb381d317 Mon Sep 17 00:00:00 2001 From: Alexandre Passos Date: Thu, 26 Mar 2020 09:10:58 -0700 Subject: [PATCH] Clarify assert docs PiperOrigin-RevId: 303125125 Change-Id: Ib69a093f0e9723cd275f1d6e55dddb1c44ca5765 --- tensorflow/python/ops/control_flow_ops.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/tensorflow/python/ops/control_flow_ops.py b/tensorflow/python/ops/control_flow_ops.py index 156b06bde4a..bbb4f917b12 100644 --- a/tensorflow/python/ops/control_flow_ops.py +++ b/tensorflow/python/ops/control_flow_ops.py @@ -117,16 +117,6 @@ def Assert(condition, data, summarize=None, name=None): If `condition` evaluates to false, print the list of tensors in `data`. `summarize` determines how many entries of the tensors to print. - NOTE: In graph mode, to ensure that Assert executes, one usually attaches - a dependency: - - ```python - # Ensure maximum element of x is smaller or equal to 1 - assert_op = tf.Assert(tf.less_equal(tf.reduce_max(x), 1.), [x]) - with tf.control_dependencies([assert_op]): - ... code using x ... - ``` - Args: condition: The condition to evaluate. data: The tensors to print out when condition is false. @@ -141,8 +131,17 @@ def Assert(condition, data, summarize=None, name=None): @end_compatibility Raises: - @compatibility(eager) - `tf.errors.InvalidArgumentError` if `condition` is not true + @compatibility(TF1) + When in TF V1 mode (that is, outside `tf.function`) Assert needs a control + dependency on the output to ensure the assertion executes: + + ```python + # Ensure maximum element of x is smaller or equal to 1 + assert_op = tf.Assert(tf.less_equal(tf.reduce_max(x), 1.), [x]) + with tf.control_dependencies([assert_op]): + ... code using x ... + ``` + @end_compatibility """ if context.executing_eagerly():