Skip to content
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

FusedBatchNorm & Conv2D backwards doesn't support zero batch size #14657

Closed
ppwwyyxx opened this issue Nov 17, 2017 · 10 comments · Fixed by #15264
Closed

FusedBatchNorm & Conv2D backwards doesn't support zero batch size #14657

ppwwyyxx opened this issue Nov 17, 2017 · 10 comments · Fixed by #15264
Assignees
Labels
stat:awaiting tensorflower Status - Awaiting response from tensorflower

Comments

@ppwwyyxx
Copy link
Contributor

ppwwyyxx commented Nov 17, 2017

Most ops in TF work well with tensors with zero elements. However, convolution fusedbatchnorm with cudnn gives the following error:

2017-11-17 08:00:20.835113: F tensorflow/stream_executor/cuda/cuda_dnn.cc:444] could not convert BatchDescriptor {count: 0 feature_map_count: 1024 spatial: 28 28  value_min: 0.000000 value_max: 0.000000 layout: BatchDepthYX} to cudnn tensor descriptor: CUDNN_STATUS_BAD_PARAM 

I would expect it checks and returns a 4D tensor with zero batch-size. Currently I have to work around it by tf.cond.

@cy89
Copy link

cy89 commented Nov 17, 2017

@zheng-xq this seems like it falls between the boundaries of cuDNN and TF. Is this something we might fix, or should I set to "contributions welcome"?

@cy89 cy89 added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Nov 17, 2017
@facaiy
Copy link
Member

facaiy commented Nov 18, 2017

Perhaps doc of cudnnSetTensorNdDescriptor is helpful for discussion.

Return Value Meaning
CUDNN_STATUS_BAD_PARAM At least one of the elements of the array dimA was negative or zero, or dataType has an invalid enumerant value

@hpnhxxwn
Copy link

@ppwwyyxx
Hi, I'm facing the same issue using CUDA 8.0 with cuDNN 6. Could you show me how did you use tf.cond? Like which parameter did you put condition on?

Thank you!

@hpnhxxwn
Copy link

@ppwwyyxx Could you point me how to use tf.cond on keras generator type of input?

@ppwwyyxx
Copy link
Contributor Author

I'm not sure I know what you mean. And I think it's already unrelated to the issue anyway. You can search for documentation/examples or ask on stackoverflow for usage questions.

@ppwwyyxx
Copy link
Contributor Author

Turned out that Conv2d actually does support empty tensor, but FusedBatchNorm does not. That is probably why I saw this error. To reproduce:

with tf.device('/gpu:0'):
    x = tf.random_normal([0, 16, 64, 64])
    scale = tf.random_normal([16])
    y = tf.nn.fused_batch_norm(x, scale, scale, data_format='NCHW')

with tf.Session() as sess:
    print(sess.run(y))

@ppwwyyxx ppwwyyxx changed the title Convolution doesn't support zero batch size FusedBatchNorm doesn't support zero batch size Dec 11, 2017
@ppwwyyxx
Copy link
Contributor Author

There is a problem with conv2d backward as well, though forward works:

with tf.device('/gpu:0'):
    x = tf.random_normal([0, 16, 64, 64])
    W = tf.random_normal([3, 3, 16, 16])
    y = tf.nn.conv2d(x, W, [1, 1, 1, 1], padding='SAME', data_format='NCHW')
    grad = tf.gradients(y, W)


with tf.Session() as sess:
    print(sess.run(grad))

@ppwwyyxx ppwwyyxx changed the title FusedBatchNorm doesn't support zero batch size FusedBatchNorm & Conv2D backwards doesn't support zero batch size Dec 11, 2017
ppwwyyxx added a commit to ppwwyyxx/tensorflow that referenced this issue Dec 11, 2017
@ppwwyyxx
Copy link
Contributor Author

Anyone can take a look at my PR #15264?

@yzhwang
Copy link

yzhwang commented Dec 19, 2017

Thanks for the PR @ppwwyyxx . I will take a look.

ppwwyyxx added a commit to ppwwyyxx/tensorflow that referenced this issue Dec 28, 2017
drpngx pushed a commit that referenced this issue Dec 29, 2017
* Support empty input tensor for FusedBatchNorm,FusedBatchNormGrad,Conv2DBackpropFilter (fix #14657)

* Also fix pooling ops

* Add some comments in ops

* Add tests for conv/pooling/bn.

* Return NaN mean/variance when input is empty

* update comments

* fix typo

* Move fill_functor implementations to :fill_functor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:awaiting tensorflower Status - Awaiting response from tensorflower
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants