tensorflow icon indicating copy to clipboard operation
tensorflow copied to clipboard

Possible bug: tf.reverse() does not accept bool type 'dim' argument in r0.12

Open dasabir opened this issue 9 years ago • 4 comments

I think tf.reverse() got messed up in r0.12. Though the documentation says the argument 'dim' has to be 'bool', while running it complains -- "Value passed to parameter 'axis' has DataType bool not in list of allowed values: int32, int64". I can see that this comes from a new op -- tf.reverse_v2(). I saw that in r0.11 this runs with no complains. I have prepared a mwe for this (link provided below). Either the documentation needs to be updated (for r0.12) or this needs to be fixed so that dims can accept boolean. I'd, rather, opt for a fix as this might be a reason for backward incompatibility in some legacy code.

Environment info

Operating System: Centos 7 Installed version of CUDA and cuDNN: cuda 8.0, cuDNN 5.1 If installed from source, provide

  1. The commit hash (git rev-parse HEAD): e4dde23d58a10c9d0c14005d20d1ecdd599539ac
  2. The output of bazel version - 4.2

If possible, provide a minimal reproducible example (We usually don't have time to read hundreds of lines of your code)

I have prepared a mwe for this (Just 26 lines of code). This tries to reproduce one of the examples given in the documentation. Attached here

Logs or other output that would be helpful

Traceback (most recent call last): File "mwe.py", line 16, in t, dims, t_rev = flip() File "mwe.py", line 10, in flip t_rev = tf.reverse(t, dims) File "/scratch/virtual_envs/tensorflow_r12_env/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 2679, in reverse return gen_array_ops.reverse_v2(tensor, axis, name) File "/scratch/virtual_envs/tensorflow_r12_env/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 2963, in reverse_v2 name=name) File "/scratch/virtual_envs/tensorflow_r12_env/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 585, in apply_op param_name=input_name) File "/scratch/virtual_envs/tensorflow_r12_env/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 61, in _SatisfiesTypeConstraint ", ".join(dtypes.as_dtype(x).name for x in allowed_list))) TypeError: Value passed to parameter 'axis' has DataType bool not in list of allowed values: int32, int64

dasabir avatar Jan 06 '17 22:01 dasabir

There's been some backward incompatible changes: https://github.com/tensorflow/tensorflow/blob/c72d891418c326794a913cc13382c104255fe1f2/RELEASE.md#breaking-changes-to-the-api

tf.reverse() now takes indices of axes to be reversed. E.g. tf.reverse(a, [True, False, True]) must now be written as tf.reverse(a, [0, 2]). tf.reverse_v2() will remain until 1.0 final.

does that help?

yaroslavvb avatar Jan 07 '17 01:01 yaroslavvb

@yaroslavvb, I see. Thats quite a list. Yes, the workaround works. I just thought, as it is not conforming to the documentation, it might be an unintentional bug. Please close the issue if its not unintentional.

dasabir avatar Jan 07 '17 04:01 dasabir

I suspect you were looking at the wrong documentation -- your commit hash is 21 hours old so you have a version newer than 0.12 and should be looking at documentation from head. Navigate to "VERSIONS" and click HEAD, the link should be: https://www.tensorflow.org/versions/master/api_docs/python/array_ops/slicing_and_joining#reverse

yaroslavvb avatar Jan 07 '17 04:01 yaroslavvb

@yaroslavvb, got it. I never knew I can get the latest documentation in such way. Thanks for the pointer. Closing the issue.

dasabir avatar Jan 07 '17 05:01 dasabir