djl icon indicating copy to clipboard operation
djl copied to clipboard

Torch NDArray .max(int, boolean) should return tuple.

Open brr53 opened this issue 2 years ago • 2 comments

Currently NDArray.max(int, boolean) only returns the max values. However it should also give the indexes in a tuple as per pytorch docs.

https://pytorch.org/docs/stable/generated/torch.max.html "Returns a namedtuple (values, indices) where values is the maximum value of each row of the input tensor in the given dimension dim. And indices is the index location of each maximum value found (argmax)."

If djl's version of .max() on NDArray is intentional, please share what is the best DJL way to calculate the index of each max value. Thank you!

brr53 avatar Feb 06 '23 22:02 brr53

@frankfliu What do you think? Is this something I can contribute?

brr53 avatar Feb 08 '23 18:02 brr53

  1. DJL NDArray API works in tensor level, we are not trying to align with PyTorch's behavior, our behavior is more like numpy
  2. Our pytorch implementation using libtorch, the behavior aligns with libtorch::Tenosr.max()
  3. torch.max(input) return tensor, not tuple, only torch.max(input, dim) returns tuple, and this is specific to pytorch
  4. You can always call NDArray.argmax() to return the index, which is PyTorch internally use as well.

frankfliu avatar Feb 08 '23 19:02 frankfliu