Skip to content

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

Open
@zqwitt

Description

@zqwitt

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]]

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions