Skip to content

tfjs-node tf.topk sorted not working as expected. Does not have the same behaviour as tfjs module. #8528

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

Open
zqwitt opened this issue Mar 16, 2025 · 1 comment
Assignees

Comments

@zqwitt
Copy link

zqwitt commented Mar 16, 2025

System information

  • MacOS 14.7.1
  • @tensorflow/tfjs-node@^4.22.0 / @tensorflow/tfjs@^4.22.0

Describe the current behavior
When using @tensorflow/tfjs-node when calling tf.topk(X,N, false) the values and indices do not return unsorted. Instead they are sorted in descending order as though tf.topk(X,N, true) had been called.

Describe the expected behavior

I would expect it to print with the same behaviour as "@tensorflow/tfjs"

Standalone code to reproduce the issue

When using @tensorflow/tfjs-node

import * as tf from "@tensorflow/tfjs-node";

const X = tf.tensor2d([
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
]);
const N = X.shape[0];

const { values } = tf.topk(X, N, false);

values.print();

values prints

Tensor
    [[3, 2, 1],
     [6, 5, 4],
     [9, 8, 7]]

Describe the expected behavior

I would expect it to print with the same behaviour as "@tensorflow/tfjs"

Tensor
    [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]
@zqwitt zqwitt added the type:bug Something isn't working label Mar 16, 2025
@shmishra99 shmishra99 self-assigned this Mar 18, 2025
@shmishra99
Copy link
Contributor

Hi @zqwitt ,

I am able to reproduce the same behavior on my side. I will check this issue further to determine the root cause and solution. I'll provide you with an update soon.

Thank You!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants