Support empty input tensor for some ops (fix #14657)#15264
Conversation
|
Can one of the admins verify this patch? |
yzhwang
left a comment
There was a problem hiding this comment.
Thanks for the PR!
Could you add according test cases for empty input tensor for all these ops?
fused_batch_norm test is at here:https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/nn_fused_batchnorm_test.py
Others are located at tensorflow/python/kernel_tests.
| if (filter_shape.num_elements() == 0) { | ||
| return; | ||
| } | ||
| if (input.shape().num_elements() == 0) { |
There was a problem hiding this comment.
Could you also add this to conv_input_filter_ops.cc?
Also, could you make the comments for this consistent by saying something like: if there is nothing to cmpute, return empty tensors as the output.
There was a problem hiding this comment.
You mean conv_grad_input_ops.cc? It has handled this correctly.
I'll add comments.
|
When input tensor has zero elements, the reference BN forward implementation in the test script gives NaN for mean/variance, however I return zeros. |
|
@zhangyaobit Could you comment on this: #15264 (comment) please? |
|
@tensorflow-jenkins test this please |
|
I haven't switched from returning zeros to returning NaNs, so the test is failing. I'll do that later |
|
Let's wait for @zhangyaobit 's comment on this first then. |
yzhwang
left a comment
There was a problem hiding this comment.
Undo LGTM for now until fix fused_batch_norm test.
|
@ppwwyyxx, could you comment on the use case of an empty input (e.g. [0, 64, 64, 3])? Should we require the input is non-empty? |
|
In object detection we may run CNN on patches (object candidates) cropped from an image with predicted boxes. When the image has no candidates we'll get zero patches. In training we can filter out these data but still can't avoid it in testing. A workaround is to use In fact, I just found that the existing CPU (eigen) implementation of |
|
Thanks! This sounds good. Could you make the behavior of GPU implementation consistent with Eigen (return NaNs)? Please let me know once the PR is ready for review. |
|
@zhangyaobit The changes have been made. Could you review it when you have a time? Thanks! |
| << " offset shape: " << offset.shape().DebugString() | ||
| << " tensor format: " << tensor_format; | ||
|
|
||
| // If input is empty, weturn NaN mean/variance |
|
@tensorflow-jenkins test this please |
|
The implementation of |
- deps = ARRAY_DEPS,
+ deps = [
+ "//tensorflow/core:array_grad",
+ "//tensorflow/core:array_ops_op_lib",
+ "//tensorflow/core:framework",
+ "//tensorflow/core:lib",
+ "//third_party/eigen3",
+ ":bounds_check",
+ ":fill_functor",
+ ":ops_util",
+ ],Cherry-picking the dependencies seems to make this PR build, but doesn't sound like an ideal solution. In general I guess functors should not depend on ops, but here |
|
Jenkins, test this please. |
|
Thanks @drpngx for help! However I haven't yet fixed the cyclic dependency error mentioned above. I
The first one seems to be within my reach. I can give it a try but not sure if there is any reason why this is not done before. |
|
@yifeif for some reason, this is stuck with |
|
Ah if a PR has ran Kokoro tests before, it will need the force-run tag :). |
|
Oh, makes sense, of course. |
|
@ppwwyyxx there are some build breakages on GPU, could you check? |
…2DBackpropFilter (fix tensorflow#14657)
e06cf96 to
8502d24
Compare
|
The build was failing because of the bazel dependency problem, which should've been fixed now after I moved implementations to |
|
Jenkins, test this please. |
|
/CC @gunan ran out of devmapper space on the Jenkins build. Jenkins, test this please. |
|
Why is 'XLA' build failing without details? |
|
OK, looks like @yifeif might have fixed it. We just ran out of space on the machine. |
|
@ppwwyyxx looks like an internal infra failure. I kicked it off again. |
|
Merged. Woohoo! |
Cudnn kernels doesn't work for empty input tensors.
This PR adds support for empty input tensor for FusedBatchNorm,FusedBatchNormGrad,Conv2DBackpropFilter, and cudnn pooling. (fix #14657)