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

tf.gradients with unconnected_gradients="zero" returns wrong shape for unconnected resource variables #31297

Closed
cooijmanstim opened this issue Aug 3, 2019 · 3 comments
Assignees
Labels
comp:ops OPs related issues TF 1.14 for issues seen with TF 1.14 type:bug Bug

Comments

@cooijmanstim
Copy link

cooijmanstim commented Aug 3, 2019

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): no
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux 5.2.1-arch1-1-ARCH x86_64
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version (use command below): v1.14.0-rc1-22-gaf24dc91b5
  • Python version: 3.6.8
  • CUDA/cuDNN version: N/A
  • GPU model and memory: N/A

Describe the current behavior
Calling tf.gradients with unconnected_gradients="zero" returns scalars for unconnected resource variables.

Describe the expected behavior
Calling tf.gradients with unconnected_gradients="zero" returns appropriately shaped zero tensors for unconnected resource variables.

Code to reproduce the issue

a = tf.Variable(initial_value=[2., 3.])
b = tf.Variable(initial_value=[3., 4.], use_resource=True)
c = tf.constant(0.)
print(tf.gradients(c, [a, b], unconnected_gradients="zero"))
# => [<tf.Tensor 'zeros_like:0' shape=(2,) dtype=float32>,
#     <tf.Tensor 'zeros_like_1:0' shape=() dtype=float32>]
@gadagashwini-zz gadagashwini-zz self-assigned this Aug 5, 2019
@gadagashwini-zz gadagashwini-zz added comp:ops OPs related issues TF 1.14 for issues seen with TF 1.14 type:bug Bug labels Aug 5, 2019
@gadagashwini-zz
Copy link
Contributor

Could able to reproduce the issue on Colab with Tensorflow 1.14.0. Please find the gist here. Thanks!

@alextp
Copy link
Contributor

alextp commented Aug 19, 2019

@saxenasaurabh I think you improved inferred gradient shape of variables recently in another place; is the same fix applicable here?

@tensorflow-bot
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:ops OPs related issues TF 1.14 for issues seen with TF 1.14 type:bug Bug
Projects
None yet
Development

No branches or pull requests

5 participants