[go: nahoru, domu]

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.ragged.stack doesn't work for multidimensional tensors #48624

Open
michaelyhuang23 opened this issue Apr 19, 2021 · 2 comments
Open

tf.ragged.stack doesn't work for multidimensional tensors #48624

michaelyhuang23 opened this issue Apr 19, 2021 · 2 comments
Assignees
Labels
comp:ops OPs related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower TF 2.16 type:bug Bug

Comments

@michaelyhuang23
Copy link

Please make sure that this is a bug. As per our
GitHub Policy,
we only address code/doc bugs, performance issues, feature requests and
build/installation issues on GitHub. tag:bug_template

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): MacOS BigSur
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
  • TensorFlow installed from (source or binary): installed by pip
  • TensorFlow version (use command below): 2.4.1
  • Python version: 3.7.7
  • Bazel version (if compiling from source):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version:
  • GPU model and memory:

You can collect some of this information using our environment capture
script
You can also obtain the TensorFlow version with:

  1. TF 1.0: python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"
  2. TF 2.0: python -c "import tensorflow as tf; print(tf.version.GIT_VERSION, tf.version.VERSION)"

Describe the current behavior

a =tf.constant([[[3,4,5],[3,4,5]],[[3,4,5],[3,4,5]],[[3,4,5],[3,4,5]],[[3,4,5],[3,4,5]]])
b = tf.constant([[[3,3,4,5],[3,3,4,5],[3,3,4,5]],[[3,3,4,5],[3,3,4,5],[3,3,4,5]],[[3,3,4,5],[3,3,4,5],[3,3,4,5]]])
print(a.shape,b.shape)
c = tf.ragged.stack([a,b],axis=0)

When I attempt to stack two tensors of same rank. If the rank is $$\ge 2$$, it produces an error saying:
tensorflow.python.framework.errors_impl.InvalidArgumentError: ConcatOp : Dimensions of inputs should match: shape[0] = [8,3] vs. shape[1] = [9,4] [Op:ConcatV2] name: concat

I can workaround this by making a, b both ragged tensors

Describe the expected behavior

It should stack them without problem

I traced it into the definition of the tf.ragged.stack function; It appears that the code runs line 180. It seems to assume that I am trying to use normal tf.stack when I have all elements as tensors.

Standalone code to reproduce the issue
Provide a reproducible test case that is the bare minimum necessary to generate
the problem. If possible, please share a link to Colab/Jupyter/any notebook.

Other info / logs Include any logs or source code that would be helpful to
diagnose the problem. If including tracebacks, please include the full
traceback. Large logs and files should be attached.

  File "/Users/michaelhyh/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py", line 201, in wrapper
    return target(*args, **kwargs)
  File "/Users/michaelhyh/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/ragged/ragged_concat_ops.py", line 120, in stack
    return _ragged_stack_concat_helper(values, axis, stack_values=True)
  File "/Users/michaelhyh/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/ragged/ragged_concat_ops.py", line 197, in _ragged_stack_concat_helper
    return _ragged_stack_concat_axis_0(rt_inputs, stack_values)
  File "/Users/michaelhyh/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/ragged/ragged_concat_ops.py", line 222, in _ragged_stack_concat_axis_0
    concatenated_flat_values = array_ops.concat(flat_values, axis=0)
  File "/Users/michaelhyh/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py", line 201, in wrapper
    return target(*args, **kwargs)
  File "/Users/michaelhyh/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/array_ops.py", line 1677, in concat
    return gen_array_ops.concat_v2(values=values, axis=axis, name=name)
  File "/Users/michaelhyh/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1193, in concat_v2
    _ops.raise_from_not_ok_status(e, name)
  File "/Users/michaelhyh/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 6862, in raise_from_not_ok_status
    six.raise_from(core._status_to_exception(e.code, message), None)
  File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.InvalidArgumentError: ConcatOp : Dimensions of inputs should match: shape[0] = [8,3] vs. shape[1] = [9,4] [Op:ConcatV2] name: concat
@saikumarchalla saikumarchalla added TF 2.4 for issues related to TF 2.4 comp:ops OPs related issues labels Apr 20, 2021
@saikumarchalla
Copy link
saikumarchalla commented Apr 20, 2021

@michaelyhuang23 I tried to reproduce the issue with 2 dimensional matrix and it is working fine but when i tried with 3 dimensional matrix, getting the same error as mentioned.

Was able to reproduce the issue with TF 2.4.1 and tf-nightly version as well. Please find the gist here.Thanks!

@ymodak ymodak added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Apr 27, 2021
@chunduriv
Copy link
Contributor
chunduriv commented Oct 4, 2021

I was able to reproduce the issue on colab using TF2.8.2. Please find the gist here for reference.Thanks!

@chunduriv chunduriv added 2.6.0 and removed TF 2.4 for issues related to TF 2.4 labels Oct 4, 2021
@Venkat6871 Venkat6871 added TF 2.16 and removed 2.6.0 labels Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:ops OPs related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower TF 2.16 type:bug Bug
Projects
None yet
Development

No branches or pull requests

5 participants