Is there any unique function which keeps the order of occurence?

Hi,

I have tested your cases and it seems you are right.
Clearly, docs say that if one specifies dim then whether sorted=True or sorted=False the tensor will be sorted even though default values is None. And I think because of that, even though the default value of sorted=False it stills sorts the tensor.
Due to this forced sorting, I think it losses the original order of values.

This is another related post around this issue:

Also, in the referenced post, you can find an approach to get the correct order but it is not built-in.

Bests