tensorflow icon indicating copy to clipboard operation
tensorflow copied to clipboard

TopK result always sort when k==num_cols

Open guizili0 opened this issue 5 years ago • 9 comments

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): No
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): CentOS Linux release 7.5.1804
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: No
  • TensorFlow installed from (source or binary): - TensorFlow version (use command below): 2.1.0 using pip install
  • Python version: - Bazel version (if compiling from source):NA
  • GCC/Compiler version (if compiling from source): NA
  • CUDA/cuDNN version: - GPU model and memory:NA

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

top_k op always sort when k == input size

Describe the expected behavior No sort when sorted=False 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.

import tensorflow as tf

a = tf.constant([1, 2, 3, 4], dtype=tf.float32)
b = tf.math.top_k(a, k=4, sorted=False)
c = tf.math.top_k(a, k=4, sorted=True)

print(b)
print(c)

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.

TopKV2(values=<tf.Tensor: shape=(4,), dtype=float32, numpy=array([4., 3., 2., 1.], dtype=float32)>, indices=<tf.Tensor: shape=(4,), dtype=int32, numpy=array([3, 2, 1, 0], dtype=int32)>)
TopKV2(values=<tf.Tensor: shape=(4,), dtype=float32, numpy=array([4., 3., 2., 1.], dtype=float32)>, indices=<tf.Tensor: shape=(4,), dtype=int32, numpy=array([3, 2, 1, 0], dtype=int32)>)

The result show b and c are same with the result has been sorted.

guizili0 avatar Feb 24 '20 08:02 guizili0

I have tried on colab with TF version 2.1.0, 2.2.0-dev20200218 and was able to reproduce the issue.Please, find the gist here. Thanks!

ravikyram avatar Feb 24 '20 12:02 ravikyram

@rmlarsen do you know who works on this?

alextp avatar Mar 02 '20 18:03 alextp

I have tried on colab with TF version 2.2,2.3-rc1,nightly version(2.4.0-dev20200712) and was able to reproduce the issue.Please, find the gist here. Thanks!

ravikyram avatar Jul 13 '20 12:07 ravikyram

able to reproduce even when k!=num_col. sorted is never effective.

import tensorflow as tf
a = tf.reshape(tf.range(100), (10, 10))
a = tf.random.normal((10, 10))
print(a)
print(tf.math.top_k(a, k=4, sorted=True))
print(tf.math.top_k(a, k=4, sorted=False))

(tf 2.4.1, Driver: 460.73.01, CUDA Version: 11.2 Quadro RTX 6000) Reproduced also on google colab.

Basically sorted=False does not work at all. We have to tf.sort the indices again.

steven-hh-ding avatar Apr 27 '21 17:04 steven-hh-ding

Was able to reproduce your issue in Tf Nightly 2.6.0-dev20210524, please find the gist here. Thanks!

sachinprasadhs avatar May 25 '21 07:05 sachinprasadhs

@rmlarsen this is still not working for 2.6.0-dev20210607

steven-hh-ding avatar Jun 09 '21 18:06 steven-hh-ding

Was able to reproduce your issue in Tf 2.13.0-dev20230305, please find the gist here. Thanks!

chunduriv avatar Aug 02 '22 09:08 chunduriv

Hi,

Thank you for opening this issue. Since this issue has been open for a long time, the code/debug information for this issue may not be relevant with the current state of the code base.

The Tensorflow team is constantly improving the framework by fixing bugs and adding new features. We suggest you try the latest TensorFlow version with the latest compatible hardware configuration which could potentially resolve the issue. If you are still facing the issue, please create a new GitHub issue with your latest findings, with all the debugging information which could help us investigate.

Please follow the release notes to stay up to date with the latest developments which are happening in the Tensorflow space.

Venkat6871 avatar Jul 26 '24 08:07 Venkat6871

This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you.

github-actions[bot] avatar Aug 03 '24 01:08 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further.

github-actions[bot] avatar Aug 10 '24 01:08 github-actions[bot]

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

google-ml-butler[bot] avatar Aug 10 '24 01:08 google-ml-butler[bot]