-
Notifications
You must be signed in to change notification settings - Fork 74.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Redo of #23090] Clean up binary element-wise assertions #23109
[Redo of #23090] Clean up binary element-wise assertions #23109
Conversation
Review comments from previous PR: 1 2 3 4 5 6 |
Pushed some additional changes to address open review comments from @iganichev. Thanks for the review, and sorry for creating additional work for you with the commit structure of the previous PR. |
@frreiss Can you please make changes to address test failures to proceed with the PR? Please let me know if you need any information. Thanks! |
@frreiss I looked at a few failures. They either expect a wrong string message in the error of different exception type (because we did not use static checking in all the asserts). They should be fairly straightforward to fix. |
Looking into the test failures now. |
Can someone look at the log from that failing copybara job and let me know what went wrong? I don't have access to that CI server. |
tensorflow/contrib/neural_link:utils_test is failing, with the following message
|
I'm fine with disabling this test / reverting assertion changes which affect it |
I don't have the source code that's being exercised there. But from the stack trace, it looks like the test case If this diagnosis is correct, you can fix the failing tests by wrapping the call to Or you can just disable the test cases |
@frreiss here is the internal error
|
Thanks for that info, @rthadur. That traceback seems to be the same one that @alextp posted above. Looking at the stack trace again, I'm pretty confident in my assessment from yesterday: This PR adds a static check to If you wrap the statement at line 260 of |
@frreiss Sorry for delay. I am fixing the internal errors now. |
…ion time This is purely refactoring that is compatible with current asserts firing during session.run and newer asserts that sometime fire at op creation time. It is needed to submit tensorflow/tensorflow#23109. PiperOrigin-RevId: 261207674
@frreiss. I submitted the change but it broke quite a few more tests in various projects I did not anticipate and they are not as straightforward as before - when we are trying to get a constant value from a tensor "x_static = tensor_util.constant_value(x)", the new tensor x_static becomes unfeedable - users cannot change it in feed_dict. Some tests try to change the value after going through some assert op. I am rolling it back and will try to resubmit after fixing all the issues. |
PiperOrigin-RevId: 261230566
Thanks, @iganichev, I appreciate the help in shepherding this change. |
Imported from GitHub PR #23109 **The working branch off of which PR #23090 was based was destroyed in a tragic git accident. This PR is a redo of the same changes.** **The reviewers on the original PR were @ymodak and @iganichev. @rohan100jain was also following the original PR.** **Original description follows:** TensorFlow 1.5 added two pieces of useful functionality to the `assert_equals` op. In eager mode, `assert_equals` now prints a more useful error message that pinpoints which elements of the input tensors differ (see commit 361c558). In graph mode, `assert_equals` now evaluates the assertion at graph construction time when both inputs can be evaluated statically (see commit cfbeafe). This PR ports this additional functionality to the other binary element-wise assertion ops `assert_none_equal`, `assert_less`, `assert_less_equal`, `assert_greater`, and `assert_greater_equal`. **Before:** ``` In [1]: import numpy as np ...: import tensorflow as tf ...: tf.enable_eager_execution() ...: zeros = np.zeros(1000) ...: mostly_ones = np.full(1000, 1.) ...: mostly_ones[567] = 0. ...: tf.assert_none_equal(zeros, mostly_ones, summarize=3) --------------------------------------------------------------------------- InvalidArgumentError Traceback (most recent call last) <ipython-input-1-23dba1a27a31> in <module> 5 mostly_ones = np.full(1000, 1.) 6 mostly_ones[567] = 0. ----> 7 tf.assert_none_equal(zeros, mostly_ones, summarize=3) [...stack trace continues...] InvalidArgumentError: Expected 'tf.Tensor(False, shape=(), dtype=bool)' to be true. Summarized data: b'' b'Condition x != y did not hold for every single element:' b'x (shape=(1000,) dtype=float64) = ' 0.0, 0.0, 0.0, ... b'y (shape=(1000,) dtype=float64) = ' 1.0, 1.0, 1.0, ... ``` **After:** ``` In [1]: import numpy as np ...: import tensorflow as tf ...: tf.enable_eager_execution() ...: zeros = np.zeros(1000) ...: mostly_ones = np.full(1000, 1.) ...: mostly_ones[567] = 0. ...: tf.assert_none_equal(zeros, mostly_ones, summarize=3) --------------------------------------------------------------------------- InvalidArgumentError Traceback (most recent call last) <ipython-input-1-1c86ae0b9399> in <module> 5 mostly_ones = np.full(1000, 1.) 6 mostly_ones[567] = 0. ----> 7 tf.assert_none_equal(zeros, mostly_ones) [...stack trace continues...] InvalidArgumentError: Condition x != y did not hold. Indices of first 1 different values: [[567]] Corresponding x values: [0.] Corresponding y values: [0.] First 3 elements of x: [0. 0. 0.] First 3 elements of y: [1. 1. 1.] ``` The ops `assert_negative`, `assert_non_negative`, `assert_positive`, and `assert_non_positive` also get some of the new functionality, as they are based on `assert_less` and `assert_less_equal`. **Before:** ``` In [1]: import tensorflow as tf ...: tf.assert_non_negative(-1.) Out[1]: <tf.Operation 'assert_non_negative/assert_less_equal/Assert/AssertGuard/Merge' type=Merge> ``` **After:** ``` In [1]: import tensorflow as tf ...: tf.assert_non_negative(-1.) --------------------------------------------------------------------------- InvalidArgumentError Traceback (most recent call last) <ipython-input-1-c2ddbad603d6> in <module> 1 import tensorflow as tf ----> 2 tf.assert_non_negative(-1.) [...stack trace continues...] InvalidArgumentError: Condition x >= 0 did not hold element-wise: x (assert_non_negative/x:0) = -1.0 ``` I also removed some unnecessary newlines from the error messages and fixed a glitch in the handling of the `message` parameter when the `data` parameter is used. **Before:** ``` In [1]: import tensorflow as tf ...: tf.assert_equal(1., 0., data=[3.], message="My error message") --------------------------------------------------------------------------- InvalidArgumentError Traceback (most recent call last) <ipython-input-1-ef2b26ad5e73> in <module> 1 import tensorflow as tf ----> 2 tf.assert_equal(1., 0., data=[3.], message="My error message") [snip!] InvalidArgumentError: 3.0 ``` **After:** ``` In [1]: import tensorflow as tf ...: tf.assert_equal(1., 0., data=[3.], message="My error message") --------------------------------------------------------------------------- InvalidArgumentError Traceback (most recent call last) <ipython-input-1-ef2b26ad5e73> in <module> 1 import tensorflow as tf ----> 2 tf.assert_equal(1., 0., data=[3.], message="My error message") [...stack trace continues...] InvalidArgumentError: My error message 3.0 ``` In the process, I replaced a bunch of near-duplicate code and documentation across the `assert_*` functions with a single function (`_binary_assert()` in `check_ops.py`) and common blocks of documentation (`_binary_assert_doc()` and `_unary_assert_doc()` in `check_ops.py`). `check_ops.py` is now about 125 lines shorter. I added some new regression tests to cover static assertion checks in graph mode and modified some existing tests to account for the new functionality. I built a local copy of the documentation for the `tf.debugging` package and reviewed all the resulting Markdown files. PiperOrigin-RevId: 263692234
…ion time This is purely refactoring that is compatible with current asserts firing during session.run and newer asserts that sometime fire at op creation time. It is needed to submit tensorflow/tensorflow#23109. PiperOrigin-RevId: 261207674
The working branch off of which PR #23090 was based was destroyed in a tragic git accident. This PR is a redo of the same changes.
The reviewers on the original PR were @ymodak and @iganichev. @rohan100jain was also following the original PR.
Original description follows:
TensorFlow 1.5 added two pieces of useful functionality to the
assert_equals
op. In eager mode,assert_equals
now prints a more useful error message that pinpoints which elements of the input tensors differ (see commit 361c55899cb524ca078c65eabdd3d79bfc10c8f9). In graph mode,assert_equals
now evaluates the assertion at graph construction time when both inputs can be evaluated statically (see commit cfbeafe11d9b86f8685c1c0f97d285885b5a5f1f).This PR ports this additional functionality to the other binary element-wise assertion ops
assert_none_equal
,assert_less
,assert_less_equal
,assert_greater
, andassert_greater_equal
.Before:
After:
The ops
assert_negative
,assert_non_negative
,assert_positive
, andassert_non_positive
also get some of the new functionality, as they are based onassert_less
andassert_less_equal
.Before:
After:
I also removed some unnecessary newlines from the error messages and fixed a glitch in the handling of the
message
parameter when thedata
parameter is used.Before:
After:
In the process, I replaced a bunch of near-duplicate code and documentation across the
assert_*
functions with a single function (_binary_assert()
incheck_ops.py
) and common blocks of documentation (_binary_assert_doc()
and_unary_assert_doc()
incheck_ops.py
).check_ops.py
is now about 125 lines shorter.I added some new regression tests to cover static assertion checks in graph mode and modified some existing tests to account for the new functionality.
I built a local copy of the documentation for the
tf.debugging
package and reviewed all the resulting Markdown files.