sorted defines, if the values should be returned in a sorted way or not.
It does not determine the order of the indices.
If you want to sort the indices, you could apply torch.sort on them after the topk call.