-
Notifications
You must be signed in to change notification settings - Fork 617
Description
The build just failed yesterday due to some shape checking fragments in C++ code.
https://source.cloud.google.com/results/invocations/f48f6f28-c9a4-4912-b8c5-336f17167183
Currently, there are three approaches that can check tensor's properties and raise exceptions to block the following computation in addons (migrating from core TF):
-
Pure
if-elseandraisestatement
addons/tensorflow_addons/image/dense_image_warp.py
Lines 51 to 53 in d46dba1
if len(grid.shape) != 4: msg = "Grid must be 4 dimensional. Received size: " raise ValueError(msg + str(grid.shape)) -
tf.debugging.*
addons/tensorflow_addons/image/dense_image_warp.py
Lines 70 to 71 in d46dba1
tf.debugging.assert_equal( query_shape[2], 2, message="Query points must be size 2 in dim 2.") -
OP_REQUIRESin C++
addons/tensorflow_addons/custom_ops/image/cc/kernels/adjust_hsv_in_yiq_op.cc
Lines 57 to 59 in d46dba1
OP_REQUIRES(context, input.dims() >= 3, errors::InvalidArgument("input must be at least 3-D, got shape", input.shape().DebugString()));
However, none of them are robust enough in tf.function and in test cases with @run_in_graph_and_eager_modes. (#138, #257)
When checking core TensorFlow, I find this commit on Apr 10:
tensorflow/tensorflow@4b4a39e#diff-68b5e47db1d9389c8d12852996845819
Op raising
InvalidArgumentErrorunlessxis all negative. This can be
used withtf.control_dependenciesinside oftf.functions to block
followup computation until the check has executed.
According to the doc, does it encourage us to use tf.control_dependencies inside tf.function to do something like shape checking?