tfjs-node tf.topk sorted not working as expected. Does not have the same behaviour as tfjs module.
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]]
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!!!