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

error getting gradient of tf.nn.crelu (concat_v2 along axis -1) #6377

Closed
mikowals opened this issue Dec 17, 2016 · 2 comments
Closed

error getting gradient of tf.nn.crelu (concat_v2 along axis -1) #6377

mikowals opened this issue Dec 17, 2016 · 2 comments
Assignees

Comments

@mikowals
Copy link
Contributor

I am on MacOS Sierra with CPU only nightly.
tf.git_version is 0.12.0-rc0-1156-g8c18a00-dirty.

The error comes from the gradient calculation in concat_v2 when axis = -1 is used to get the last dimension. I could not find axis=-1 documentation for concat_v2 but that is how crelu is implemented.

Concat_v2 along last dimension as a positive int works fine. The forward pass with axis = -1 also works fine, it is just getting a gradient that gives an error.

Reproduce with:

import tensorflow as tf

inputs = tf.random_normal([64, 32,32, 3])
inputs2 = tf.random_normal([64, 32,32, 3])
hidden = tf.concat_v2([inputs, inputs2], axis=-1)  # axis = 3 works fine
grad = tf.gradients(hidden, [inputs])

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

Gives error:

...which was originally created as op u'concat_v2', defined at:
File "crelu.py", line 5, in
hidden = tf.concat_v2([inputs, inputs2], axis=-1)
File "/Users/mikowals/projects/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 1062, in concat_v2
name=name)
File "/Users/mikowals/projects/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 498, in _concat_v2
name=name)
File "/Users/mikowals/projects/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 763, in apply_op
op_def=op_def)
File "/Users/mikowals/projects/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2389, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/Users/mikowals/projects/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1264, in init
self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): Concat dim is out of range: -1 vs. 4
[[Node: gradients/concat_v2_grad/ConcatOffset = ConcatOffset[N=2, _device="/job:localhost/replica:0/task:0/cpu:0"](concat_v2/axis, gradients/concat_v2_grad/Shape, gradients/concat_v2_grad/Shape_1)]]

@aselle
Copy link
Contributor

aselle commented Dec 19, 2016

Thanks for reporting this. I can reproduce this on the nightly build as well. Looks like grad might not support negative axes. We'll look into it. As you say the work around is to use non-negative axes for now.

caisq pushed a commit to caisq/tensorflow that referenced this issue Jan 8, 2017
@annarev
Copy link
Contributor

annarev commented Jan 23, 2017

The fix commit is now in r1.0 branch. I will close this issue as fixed. Let me know if you still see any issue with negative axis concat grad.

@annarev annarev closed this as completed Jan 23, 2017
copybara-service bot pushed a commit that referenced this issue Oct 19, 2023
…uple

Imported from GitHub PR openxla/xla#6377

Some while loops might not be rooted on a tuple.
This removes the check to assert on such situation.
Addressed issue: openxla/xla#6353
Copybara import of the project:

--
d454d73618f606360f2eff896093045896419c46 by TJ <tjx@nvidia.com>:

Fix the check failure where while loop is not rooted on a tuple

--
c5fccd1f594cf2bf1b54daa60f05e71eecea58e8 by TJ <tjx@nvidia.com>:

removed redundant code in tests

Merging this change closes #6377

PiperOrigin-RevId: 574847170
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants