Indices returned by torch.topk is of wrong order

The indices return by torch.topk is strange.
In my option, if sorted=False, then the returned indices should be sorted, that is the elements in the indices are ascending.
However, in the following example, t2 has something wrong:

2144,  20,  104,  118,  123,  136,  137,  144,  171
>>> import torch
>>> t0 = torch.load('./t0.pt')
>>> t0.shape
torch.Size([2146])
>>> t0
tensor([4.4721, 4.5826, 4.3589,  ..., 4.5826, 3.7417, 4.0000], device='cuda:0')
>>> t1, t2 = torch.topk(t0, 200, dim=0, largest=False, sorted=False)
>>> t1
tensor([3.1623, 3.7417, 3.6056, 3.7417, 3.6056, 3.7417, 3.7417, 3.6056, 3.7417,
        3.7417, 3.6056, 3.6056, 3.3166, 3.7417, 3.6056, 3.7417, 3.7417, 3.6056,
        3.7417, 3.7417, 3.7417, 3.7417, 3.7417, 3.7417, 3.7417, 3.4641, 3.7417,
        3.7417, 3.7417, 3.6056, 3.6056, 3.6056, 3.7417, 3.4641, 3.7417, 3.6056,
        3.7417, 3.7417, 3.6056, 3.1623, 3.7417, 3.4641, 3.7417, 3.7417, 3.7417,
        3.7417, 3.7417, 3.7417, 3.6056, 3.7417, 3.7417, 3.7417, 3.7417, 3.4641,
        3.4641, 3.7417, 3.1623, 3.4641, 3.3166, 3.4641, 3.7417, 3.3166, 3.4641,
        3.6056, 3.3166, 3.3166, 3.3166, 3.7417, 3.3166, 3.7417, 3.3166, 3.7417,
        3.4641, 3.7417, 3.3166, 3.7417, 3.7417, 3.6056, 3.7417, 3.7417, 3.4641,
        3.7417, 3.3166, 3.7417, 3.4641, 3.7417, 3.7417, 3.7417, 3.7417, 3.7417,
        3.4641, 3.7417, 3.1623, 3.4641, 3.7417, 3.3166, 3.7417, 3.7417, 3.3166,
        3.4641, 3.4641, 3.3166, 3.4641, 3.7417, 3.7417, 3.4641, 3.7417, 3.7417,
        3.3166, 3.3166, 3.7417, 3.3166, 3.3166, 3.7417, 3.7417, 3.4641, 3.6056,
        3.7417, 3.7417, 3.4641, 3.7417, 3.7417, 3.4641, 3.3166, 3.7417, 3.7417,
        3.7417, 3.4641, 3.7417, 3.3166, 3.7417, 3.3166, 3.4641, 3.7417, 3.3166,
        3.3166, 3.4641, 3.3166, 3.3166, 3.7417, 3.7417, 3.1623, 3.3166, 3.4641,
        3.7417, 3.7417, 3.3166, 3.7417, 3.4641, 3.3166, 3.4641, 3.6056, 3.7417,
        3.7417, 3.6056, 3.7417, 3.0000, 3.6056, 3.7417, 3.4641, 3.7417, 3.3166,
        3.7417, 3.7417, 3.3166, 3.3166, 3.3166, 3.3166, 2.8284, 3.4641, 3.3166,
        3.7417, 3.7417, 3.6056, 3.6056, 3.6056, 3.7417, 3.7417, 3.6056, 3.3166,
        3.7417, 3.7417, 3.7417, 3.4641, 3.4641, 2.8284, 3.4641, 3.4641, 3.7417,
        3.1623, 3.7417, 3.7417, 3.8730, 3.8730, 3.8730, 3.8730, 3.8730, 3.8730,
        3.8730, 3.8730], device='cuda:0')
>>> t2
tensor([   6,   18,   22,   30,  119,  127,  148,  202,  205,  211,  218,  221,
         241,  249,  259,  281,  282,  288,  296,  312,  339,  366,  439,  503,
         523,  526,  533,  534,  541,  665,  676,  677,  716,  720,  724,  734,
         787,  797,  798,  823,  850,  879,  887,  913,  931,  933,  954,  955,
         969,  978,  997, 1009, 1016, 1038, 1040, 1044, 1046, 1047, 1082, 1083,
        1095, 1131, 1143, 1145, 1163, 1166, 1241, 1254, 1258, 1262, 1272, 1291,
        1295, 1299, 1305, 1306, 1309, 1310, 1313, 1320, 1328, 1331, 1334, 1339,
        1343, 1347, 1357, 1365, 1390, 1400, 1402, 1416, 1417, 1419, 1439, 1456,
        1466, 1474, 1501, 1519, 1530, 1535, 1539, 1608, 1619, 1622, 1626, 1630,
        1636, 1651, 1657, 1665, 1667, 1668, 1671, 1672, 1685, 1686, 1694, 1696,
        1701, 1707, 1713, 1716, 1717, 1732, 1761, 1781, 1785, 1788, 1810, 1821,
        1822, 1832, 1863, 1868, 1880, 1887, 1899, 1907, 1917, 1971, 1973, 1985,
        1996, 1997, 1998, 2000, 2005, 2009, 2016, 2017, 2020, 2021, 2027, 2029,
        2034, 2041, 2042, 2043, 2051, 2056, 2059, 2060, 2062, 2064, 2067, 2068,
        2070, 2072, 2073, 2074, 2075, 2076, 2078, 2080, 2082, 2084, 2087, 2092,
        2099, 2107, 2113, 2119, 2120, 2124, 2130, 2131, 2134, 2138, 2140, 2144,
          20,  104,  118,  123,  136,  137,  144,  171], device='cuda:0')
>>> 

I could not upload the t0.py file, so I print it out:

>>> print(t0)
tensor([4.4721, 4.5826, 4.3589, 4.7958, 4.5826, 4.2426, 3.1623, 4.8990, 4.5826,
        4.8990, 4.7958, 4.8990, 4.5826, 4.8990, 4.7958, 4.5826, 4.4721, 4.8990,
        3.7417, 4.7958, 3.8730, 4.6904, 3.6056, 4.8990, 4.7958, 4.6904, 4.2426,
        4.3589, 4.8990, 4.5826, 3.7417, 4.7958, 4.5826, 4.7958, 4.7958, 4.8990,
        4.5826, 4.5826, 4.5826, 4.8990, 4.2426, 4.5826, 4.4721, 4.1231, 4.8990,
        4.5826, 4.8990, 4.7958, 4.5826, 4.8990, 4.1231, 4.7958, 4.4721, 4.8990,
        4.5826, 4.8990, 4.8990, 4.5826, 4.5826, 4.8990, 4.0000, 4.1231, 4.8990,
        4.5826, 4.8990, 4.3589, 4.2426, 4.8990, 4.2426, 4.8990, 4.2426, 4.8990,
        4.2426, 4.1231, 4.5826, 4.2426, 4.1231, 4.5826, 4.5826, 4.5826, 4.5826,
        4.4721, 4.5826, 4.7958, 4.5826, 4.1231, 4.4721, 4.8990, 4.2426, 4.5826,
        4.5826, 4.1231, 4.3589, 4.5826, 4.4721, 4.1231, 4.4721, 4.4721, 4.5826,
        4.8990, 4.7958, 4.5826, 4.7958, 4.4721, 3.8730, 4.4721, 4.4721, 4.8990,
        5.2915, 4.8990, 4.5826, 4.7958, 4.4721, 4.4721, 4.8990, 4.7958, 4.5826,
        4.8990, 3.8730, 3.6056, 4.7958, 4.5826, 4.5826, 3.8730, 4.0000, 4.6904,
        4.0000, 3.7417, 4.4721, 4.1231, 4.8990, 4.1231, 4.4721, 4.4721, 4.7958,
        4.5826, 3.8730, 3.8730, 4.2426, 4.1231, 4.2426, 4.2426, 4.8990, 4.2426,
        3.8730, 4.1231, 4.4721, 4.4721, 3.7417, 4.3589, 4.3589, 4.1231, 4.1231,
        4.0000, 4.4721, 4.4721, 4.1231, 4.4721, 4.5826, 4.5826, 4.5826, 4.3589,
        4.4721, 4.3589, 4.2426, 4.5826, 4.1231, 4.2426, 4.7958, 4.2426, 4.7958,
        3.8730, 4.7958, 4.8990, 4.2426, 4.4721, 4.0000, 4.8990, 4.6904, 4.6904,
        4.8990, 4.1231, 4.5826, 4.8990, 4.5826, 4.4721, 4.8990, 4.1231, 4.8990,
        4.8990, 4.2426, 4.4721, 4.4721, 4.3589, 4.5826, 5.0990, 4.5826, 4.7958,
        4.2426, 4.2426, 4.1231, 4.1231, 3.6056, 4.5826, 4.1231, 3.7417, 4.4721,
        4.8990, 4.4721, 4.8990, 4.8990, 3.7417, 4.1231, 4.4721, 4.5826, 4.4721,
        4.0000, 4.7958, 3.6056, 4.4721, 4.8990, 3.6056, 4.7958, 4.4721, 3.8730,
        4.8990, 4.7958, 4.2426, 4.4721, 4.8990, 4.1231, 4.7958, 4.8990, 4.8990,
        4.2426, 4.8990, 4.2426, 4.5826, 4.2426, 4.8990, 4.7958, 3.3166, 4.7958,
        4.8990, 4.1231, 3.8730, 4.2426, 4.2426, 4.4721, 3.7417, 4.8990, 4.8990,
        4.2426, 4.4721, 4.8990, 4.8990, 4.4721, 4.5826, 4.8990, 3.6056, 4.5826,
        4.7958, 4.4721, 4.6904, 4.5826, 4.2426, 4.5826, 4.8990, 4.8990, 4.8990,
        4.2426, 4.5826, 4.8990, 4.5826, 4.2426, 4.4721, 4.7958, 4.7958, 4.8990,
        4.1231, 4.2426, 3.7417, 3.7417, 4.3589, 4.8990, 4.7958, 4.2426, 4.6904,
        3.6056, 4.0000, 4.4721, 4.4721, 4.4721, 4.4721, 4.8990, 4.8990, 3.7417,
        4.1231, 4.5826, 4.5826, 4.7958, 4.1231, 4.4721, 4.5826, 4.4721, 4.2426,
        4.4721, 4.0000, 4.5826, 4.5826, 4.8990, 4.4721, 3.7417, 4.5826, 4.0000,
        4.0000, 4.5826, 4.8990, 4.2426, 4.2426, 4.4721, 4.4721, 4.5826, 4.4721,
        4.7958, 4.8990, 4.8990, 4.5826, 3.8730, 4.5826, 4.1231, 3.8730, 4.5826,
        4.5826, 4.1231, 4.8990, 4.1231, 4.5826, 3.8730, 3.7417, 4.8990, 4.2426,
        4.5826, 4.4721, 4.5826, 4.8990, 4.5826, 4.7958, 4.5826, 4.4721, 4.1231,
        4.8990, 5.0000, 4.2426, 4.8990, 4.7958, 4.8990, 4.5826, 4.5826, 4.2426,
        4.8990, 4.6904, 4.7958, 4.4721, 4.4721, 4.4721, 3.7417, 4.8990, 4.5826,
        4.5826, 3.8730, 4.1231, 4.8990, 4.8990, 4.1231, 4.8990, 4.1231, 4.5826,
        4.7958, 4.4721, 4.8990, 4.8990, 4.8990, 4.8990, 4.2426, 4.5826, 4.8990,
        4.2426, 4.8990, 4.5826, 4.1231, 4.7958, 4.2426, 4.2426, 4.5826, 4.7958,
        4.8990, 4.2426, 4.8990, 4.5826, 4.7958, 4.1231, 4.8990, 4.1231, 4.8990,
        4.7958, 4.4721, 4.7958, 4.1231, 4.1231, 4.1231, 4.7958, 4.5826, 4.5826,
        4.5826, 4.7958, 4.2426, 4.4721, 4.8990, 4.7958, 4.7958, 4.4721, 4.5826,
        4.3589, 3.8730, 4.8990, 4.7958, 4.1231, 4.7958, 4.1231, 4.5826, 4.1231,
        4.4721, 4.4721, 4.2426, 4.2426, 4.5826, 4.8990, 4.4721, 3.7417, 4.1231,
        4.8990, 4.5826, 4.2426, 4.5826, 4.8990, 4.5826, 4.2426, 4.8990, 4.8990,
        4.5826, 4.4721, 4.8990, 4.8990, 3.8730, 4.5826, 4.8990, 4.8990, 4.2426,
        4.2426, 4.5826, 4.2426, 4.3589, 4.7958, 4.4721, 4.3589, 4.8990, 4.7958,
        4.5826, 4.4721, 4.1231, 4.1231, 4.5826, 4.8990, 4.5826, 4.1231, 3.8730,
        4.5826, 4.5826, 4.8990, 4.1231, 4.1231, 4.4721, 4.8990, 4.5826, 4.5826,
        4.5826, 4.4721, 4.2426, 4.4721, 4.7958, 4.8990, 4.1231, 4.4721, 3.8730,
        4.5826, 4.7958, 4.2426, 3.8730, 4.4721, 4.4721, 4.2426, 4.1231, 3.7417,
        4.8990, 4.7958, 4.4721, 4.2426, 4.5826, 4.4721, 4.5826, 4.4721, 4.8990,
        4.1231, 4.7958, 4.2426, 4.4721, 4.8990, 4.5826, 4.2426, 4.5826, 4.4721,
        4.4721, 3.7417, 4.1231, 4.4721, 3.4641, 4.4721, 4.8990, 4.7958, 4.0000,
        4.8990, 4.1231, 3.7417, 3.7417, 3.8730, 4.4721, 4.8990, 4.8990, 4.5826,
        4.5826, 3.7417, 4.5826, 4.1231, 4.0000, 4.2426, 4.5826, 4.8990, 3.8730,
        4.1231, 4.1231, 4.2426, 4.4721, 4.3589, 4.7958, 4.1231, 4.1231, 4.2426,
        4.4721, 4.2426, 4.1231, 4.0000, 4.1231, 4.5826, 4.1231, 4.1231, 4.5826,
        4.2426, 4.8990, 4.5826, 4.2426, 4.1231, 4.3589, 4.1231, 4.4721, 4.4721,
        4.0000, 4.7958, 3.8730, 4.7958, 3.8730, 4.1231, 4.5826, 4.3589, 4.5826,
        4.3589, 4.5826, 4.8990, 4.5826, 4.2426, 4.5826, 4.5826, 4.2426, 4.0000,
        4.7958, 4.3589, 4.5826, 4.7958, 4.2426, 4.3589, 4.8990, 4.7958, 4.7958,
        4.8990, 4.1231, 4.4721, 4.8990, 4.8990, 4.2426, 4.8990, 4.5826, 4.7958,
        4.2426, 4.5826, 4.7958, 4.2426, 4.7958, 4.5826, 4.5826, 4.4721, 4.4721,
        4.1231, 4.2426, 4.3589, 4.5826, 4.4721, 4.6904, 4.6904, 4.3589, 4.5826,
        4.4721, 4.8990, 4.8990, 4.4721, 4.5826, 4.1231, 4.5826, 4.8990, 4.4721,
        4.5826, 4.3589, 4.3589, 4.3589, 3.8730, 4.1231, 4.6904, 4.7958, 4.2426,
        4.4721, 4.5826, 4.8990, 4.7958, 4.3589, 4.5826, 4.8990, 4.1231, 4.3589,
        4.7958, 4.2426, 4.3589, 4.4721, 4.4721, 4.7958, 4.4721, 3.8730, 3.6056,
        4.5826, 4.8990, 4.4721, 4.7958, 4.7958, 4.5826, 4.2426, 4.7958, 4.5826,
        4.7958, 3.6056, 3.6056, 4.1231, 4.5826, 4.4721, 4.5826, 4.7958, 4.1231,
        4.6904, 4.3589, 4.8990, 4.3589, 4.2426, 4.7958, 4.0000, 4.7958, 4.3589,
        4.4721, 4.7958, 4.7958, 3.8730, 4.8990, 4.7958, 4.5826, 3.8730, 4.5826,
        4.7958, 4.7958, 4.8990, 4.1231, 3.8730, 4.5826, 4.1231, 4.2426, 4.1231,
        4.4721, 4.5826, 4.5826, 4.5826, 4.5826, 3.7417, 3.8730, 4.8990, 4.2426,
        3.4641, 4.8990, 4.8990, 4.5826, 3.7417, 4.8990, 4.5826, 4.7958, 4.8990,
        4.0000, 4.2426, 4.2426, 4.8990, 4.6904, 3.6056, 4.3589, 4.7958, 4.2426,
        4.1231, 4.3589, 4.5826, 4.5826, 4.7958, 4.4721, 4.8990, 4.8990, 4.5826,
        4.5826, 4.8990, 4.7958, 4.5826, 4.5826, 4.4721, 4.5826, 4.7958, 4.8990,
        4.8990, 4.8990, 4.8990, 4.5826, 3.8730, 4.7958, 4.4721, 4.8990, 4.8990,
        4.7958, 4.3589, 4.8990, 4.4721, 4.8990, 4.4721, 4.3589, 4.4721, 4.4721,
        4.8990, 4.7958, 4.8990, 4.4721, 4.7958, 4.5826, 4.4721, 4.7958, 4.5826,
        4.4721, 4.5826, 4.1231, 4.7958, 3.7417, 4.2426, 4.1231, 4.2426, 4.2426,
        3.8730, 4.2426, 4.1231, 4.2426, 4.2426, 3.7417, 3.6056, 4.4721, 4.2426,
        4.2426, 4.5826, 4.2426, 4.1231, 4.1231, 3.8730, 4.5826, 4.0000, 4.5826,
        4.7958, 4.2426, 4.5826, 4.8990, 4.6904, 4.8990, 4.4721, 4.8990, 4.5826,
        4.1231, 4.4721, 4.2426, 4.8990, 3.1623, 4.5826, 4.8990, 4.4721, 4.5826,
        4.4721, 4.4721, 4.0000, 4.8990, 4.7958, 4.7958, 4.8990, 4.7958, 4.4721,
        4.2426, 4.2426, 4.2426, 4.4721, 4.1231, 4.5826, 4.2426, 4.4721, 4.4721,
        4.2426, 4.7958, 4.1231, 4.7958, 3.7417, 4.2426, 4.8990, 4.7958, 4.8990,
        4.5826, 4.4721, 4.5826, 4.1231, 4.7958, 4.4721, 4.7958, 4.2426, 3.8730,
        4.8990, 4.0000, 4.1231, 4.2426, 4.1231, 4.1231, 4.2426, 4.5826, 4.1231,
        4.5826, 4.1231, 3.8730, 4.2426, 4.4721, 4.0000, 3.4641, 4.5826, 4.1231,
        4.5826, 3.8730, 4.8990, 4.3589, 4.8990, 3.7417, 4.5826, 4.8990, 4.4721,
        4.8990, 4.1231, 4.7958, 4.5826, 4.0000, 4.8990, 4.4721, 4.5826, 4.5826,
        4.1231, 4.4721, 4.5826, 4.7958, 4.1231, 4.7958, 4.0000, 4.8990, 4.4721,
        4.5826, 4.4721, 4.2426, 4.5826, 3.7417, 5.0000, 4.7958, 4.8990, 4.4721,
        4.5826, 4.1231, 4.4721, 4.8990, 4.5826, 4.8990, 4.1231, 4.2426, 4.8990,
        4.8990, 4.0000, 4.5826, 4.2426, 3.7417, 4.2426, 3.7417, 4.1231, 4.2426,
        4.2426, 4.4721, 4.1231, 4.8990, 4.7958, 4.0000, 4.2426, 4.1231, 4.5826,
        4.5826, 4.8990, 4.4721, 4.5826, 4.8990, 4.5826, 4.3589, 4.7958, 4.4721,
        3.7417, 3.7417, 4.4721, 4.8990, 4.1231, 4.4721, 4.8990, 4.2426, 4.5826,
        4.8990, 4.4721, 4.4721, 4.5826, 4.5826, 4.4721, 3.6056, 4.3589, 4.3589,
        4.5826, 4.2426, 4.1231, 4.5826, 4.3589, 4.4721, 3.7417, 4.5826, 4.7958,
        3.8730, 4.8990, 4.8990, 4.7958, 4.7958, 4.2426, 4.8990, 4.4721, 4.8990,
        4.4721, 4.3589, 4.5826, 4.5826, 4.7958, 4.5826, 4.1231, 3.7417, 4.4721,
        4.1231, 4.5826, 4.8990, 4.5826, 4.1231, 3.8730, 4.5826, 4.0000, 4.1231,
        4.2426, 3.7417, 5.1962, 4.1231, 4.2426, 4.7958, 4.6904, 4.7958, 3.7417,
        4.1231, 5.0000, 3.8730, 4.2426, 4.5826, 4.8990, 3.8730, 4.7958, 3.8730,
        3.8730, 3.8730, 4.0000, 4.4721, 4.4721, 4.1231, 4.2426, 4.7958, 4.7958,
        4.5826, 4.5826, 3.8730, 3.4641, 4.5826, 3.4641, 4.5826, 4.3589, 4.8990,
        3.7417, 4.2426, 3.1623, 3.4641, 4.1231, 4.8990, 5.0000, 4.4721, 4.2426,
        4.4721, 4.2426, 4.4721, 4.4721, 4.8990, 4.8990, 4.8990, 4.5826, 4.2426,
        4.7958, 4.5826, 4.4721, 3.8730, 3.8730, 4.1231, 4.7958, 4.7958, 4.4721,
        3.8730, 4.0000, 4.1231, 4.5826, 4.1231, 4.2426, 4.7958, 4.8990, 4.1231,
        4.2426, 4.4721, 3.3166, 3.4641, 4.5826, 4.2426, 4.5826, 4.8990, 4.2426,
        4.4721, 4.5826, 4.7958, 4.8990, 4.4721, 4.6904, 3.7417, 4.7958, 4.8990,
        4.2426, 3.8730, 4.8990, 4.8990, 4.5826, 4.7958, 4.1231, 4.4721, 4.4721,
        4.7958, 4.1231, 4.2426, 4.2426, 4.2426, 4.4721, 4.1231, 4.4721, 3.8730,
        4.2426, 4.8990, 4.4721, 5.1962, 4.2426, 4.2426, 4.2426, 4.4721, 4.5826,
        4.5826, 4.0000, 4.2426, 4.1231, 4.2426, 4.8990, 3.3166, 4.4721, 4.7958,
        4.8990, 4.5826, 4.0000, 4.8990, 4.2426, 4.2426, 4.1231, 4.7958, 4.3589,
        3.4641, 4.5826, 3.6056, 4.0000, 4.2426, 4.5826, 4.8990, 4.8990, 4.2426,
        3.8730, 4.1231, 4.5826, 4.7958, 4.5826, 3.8730, 3.8730, 4.1231, 4.1231,
        4.1231, 5.1962, 3.3166, 4.2426, 4.5826, 3.3166, 4.2426, 4.2426, 3.8730,
        4.5826, 4.5826, 4.5826, 4.2426, 4.7958, 4.5826, 5.1962, 4.2426, 4.4721,
        4.8990, 4.8990, 4.5826, 4.2426, 4.1231, 4.4721, 4.5826, 4.1231, 4.5826,
        4.1231, 4.4721, 4.7958, 4.4721, 4.8990, 4.8990, 4.7958, 4.0000, 4.1231,
        4.7958, 4.5826, 4.5826, 4.2426, 4.6904, 4.1231, 4.3589, 4.5826, 4.5826,
        4.4721, 4.5826, 3.8730, 4.2426, 4.5826, 4.1231, 3.8730, 4.2426, 4.6904,
        4.7958, 3.8730, 5.2915, 4.7958, 4.4721, 4.7958, 4.4721, 4.5826, 4.8990,
        4.5826, 5.0000, 4.1231, 4.2426, 4.7958, 4.4721, 4.2426, 4.1231, 4.8990,
        3.8730, 4.1231, 4.8990, 4.4721, 4.3589, 4.5826, 4.3589, 4.3589, 3.3166,
        4.2426, 4.8990, 4.5826, 4.1231, 4.1231, 4.0000, 4.1231, 4.2426, 3.8730,
        3.8730, 4.7958, 4.1231, 3.7417, 4.5826, 4.1231, 4.4721, 3.3166, 4.5826,
        4.0000, 4.7958, 3.7417, 5.1962, 4.4721, 4.8990, 4.5826, 4.5826, 4.4721,
        4.2426, 3.8730, 4.1231, 3.3166, 5.0990, 4.2426, 4.6904, 4.4721, 4.4721,
        4.2426, 4.5826, 4.2426, 4.5826, 3.8730, 4.8990, 3.8730, 4.5826, 4.2426,
        4.8990, 4.5826, 4.1231, 4.6904, 3.7417, 4.2426, 4.7958, 4.8990, 3.4641,
        4.4721, 4.4721, 4.2426, 3.7417, 4.4721, 4.1231, 4.8990, 4.8990, 4.4721,
        3.3166, 3.7417, 4.5826, 4.8990, 3.7417, 3.6056, 4.3589, 4.2426, 3.7417,
        4.1231, 4.4721, 4.2426, 4.7958, 4.4721, 4.4721, 3.7417, 3.8730, 4.1231,
        4.5826, 4.1231, 4.8990, 4.2426, 4.4721, 3.4641, 3.8730, 4.3589, 3.7417,
        4.1231, 3.8730, 3.3166, 4.4721, 4.4721, 4.2426, 4.7958, 3.7417, 4.7958,
        3.8730, 4.4721, 3.4641, 4.2426, 4.1231, 4.5826, 3.7417, 4.4721, 4.4721,
        4.3589, 4.8990, 4.4721, 4.2426, 4.1231, 4.3589, 4.2426, 3.7417, 4.8990,
        4.1231, 4.5826, 3.8730, 4.1231, 4.1231, 4.1231, 3.7417, 4.1231, 4.5826,
        4.4721, 4.4721, 4.4721, 3.8730, 4.1231, 4.8990, 4.5826, 4.5826, 4.4721,
        3.8730, 4.5826, 4.1231, 4.0000, 4.1231, 3.8730, 4.1231, 5.0990, 4.4721,
        4.1231, 4.7958, 4.6904, 4.7958, 3.7417, 4.1231, 4.1231, 5.0000, 3.8730,
        4.2426, 4.5826, 4.8990, 4.6904, 3.8730, 3.7417, 4.0000, 3.4641, 4.2426,
        4.2426, 4.8990, 4.7958, 4.5826, 4.5826, 3.8730, 3.8730, 4.8990, 3.8730,
        4.5826, 4.3589, 4.8990, 3.7417, 3.1623, 3.8730, 3.4641, 4.1231, 4.8990,
        5.0000, 4.4721, 4.2426, 4.4721, 4.2426, 4.1231, 4.5826, 5.0000, 4.8990,
        4.8990, 4.5826, 4.5826, 4.7958, 4.5826, 4.4721, 4.2426, 4.5826, 3.7417,
        4.7958, 4.6904, 3.8730, 4.0000, 4.1231, 4.1231, 4.7958, 4.5826, 4.1231,
        4.2426, 4.4721, 4.6904, 4.8990, 4.1231, 4.5826, 4.4721, 3.3166, 4.2426,
        4.5826, 4.8990, 4.8990, 4.2426, 4.4721, 4.5826, 4.8990, 4.6904, 3.7417,
        4.7958, 4.8990, 4.2426, 3.8730, 4.8990, 4.5826, 4.7958, 3.7417, 4.1231,
        4.4721, 4.7958, 4.1231, 4.2426, 4.2426, 4.5826, 4.1231, 4.2426, 4.1231,
        4.2426, 4.2426, 4.5826, 4.4721, 5.1962, 4.2426, 4.2426, 4.2426, 4.2426,
        4.4721, 4.5826, 4.1231, 4.2426, 4.7958, 4.1231, 4.2426, 3.3166, 4.4721,
        4.4721, 4.7958, 4.8990, 5.0990, 4.5826, 4.1231, 4.8990, 4.8990, 4.5826,
        4.2426, 4.8990, 4.5826, 4.4721, 4.4721, 3.8730, 4.5826, 3.4641, 4.7958,
        4.1231, 4.2426, 4.5826, 4.8990, 4.8990, 4.2426, 4.1231, 4.5826, 4.5826,
        3.4641, 3.8730, 4.1231, 4.1231, 5.1962, 3.3166, 4.1231, 4.2426, 4.5826,
        3.4641, 4.5826, 3.8730, 3.8730, 4.5826, 4.4721, 4.5826, 4.2426, 4.7958,
        4.5826, 5.1962, 4.1231, 4.4721, 4.8990, 4.5826, 4.2426, 4.1231, 4.1231,
        4.4721, 4.4721, 4.8990, 4.1231, 4.3589, 4.2426, 4.7958, 4.4721, 4.7958,
        4.1231, 4.4721, 4.7958, 4.4721, 4.5826, 4.5826, 4.4721, 4.0000, 4.2426,
        4.3589, 4.5826, 4.2426, 4.4721, 4.5826, 3.8730, 3.8730, 4.5826, 4.8990,
        4.1231, 3.8730, 4.5826, 4.6904, 3.8730, 5.2915, 4.7958, 4.1231, 4.7958,
        4.4721, 4.2426, 4.8990, 5.0000, 4.1231, 4.2426, 4.4721, 3.8730, 4.8990,
        4.0000, 4.4721, 4.4721, 4.6904, 4.3589, 4.3589, 3.7417, 4.2426, 4.2426,
        4.1231, 4.0000, 4.1231, 4.2426, 3.8730, 3.8730, 4.7958, 4.1231, 3.7417,
        4.1231, 4.1231, 3.4641, 4.5826, 4.3589, 4.2426, 3.7417, 5.1962, 4.4721,
        4.5826, 3.7417, 4.2426, 4.4721, 4.2426, 4.2426, 4.1231, 3.3166, 5.1962,
        4.2426, 4.6904, 4.4721, 4.2426, 4.5826, 4.2426, 4.5826, 3.8730, 4.8990,
        3.8730, 4.2426, 4.8990, 4.2426, 3.3166, 4.6904, 4.1231, 4.1231, 4.7958,
        5.1962, 3.7417, 4.1231, 4.0000, 4.4721, 3.8730, 4.2426, 4.1231, 4.1231,
        3.3166, 4.8990, 3.3166, 3.7417, 4.5826, 4.8990, 3.7417, 3.4641, 4.2426,
        4.1231, 4.4721, 4.1231, 4.1231, 4.3589, 4.2426, 4.4721, 4.7958, 4.2426,
        4.4721, 4.4721, 3.6056, 3.7417, 3.8730, 4.1231, 4.5826, 4.1231, 4.8990,
        4.2426, 4.4721, 3.7417, 4.4721, 3.4641, 4.2426, 4.5826, 3.8730, 4.4721,
        3.7417, 4.1231, 4.4721, 4.4721, 4.2426, 4.7958, 3.7417, 4.4721, 3.8730,
        4.4721, 4.1231, 4.4721, 3.4641, 4.8990, 4.6904, 3.3166, 3.7417, 4.7958,
        4.4721, 4.8990, 4.2426, 4.5826, 4.5826, 4.3589, 4.2426, 4.1231, 4.0000,
        4.2426, 4.8990, 4.1231, 4.5826, 3.7417, 4.0000, 4.1231, 4.2426, 4.1231,
        4.1231, 4.5826, 4.4721, 4.4721, 4.4721, 4.1231, 4.8990, 4.5826, 4.8990,
        4.0000, 4.5826, 4.4721, 4.5826, 4.1231, 4.0000, 4.1231, 4.2426, 4.1231,
        5.0990, 4.1231, 4.2426, 4.7958, 4.6904, 4.3589, 3.7417, 4.1231, 5.0000,
        3.8730, 4.2426, 4.5826, 4.8990, 4.7958, 3.8730, 3.8730, 3.8730, 4.2426,
        4.1231, 4.2426, 5.0000, 4.7958, 4.5826, 3.8730, 3.8730, 4.8990, 3.4641,
        4.5826, 4.3589, 4.8990, 3.7417, 4.4721, 3.8730, 3.3166, 4.0000, 4.2426,
        4.1231, 4.8990, 5.0000, 4.4721, 4.2426, 4.1231, 4.2426, 4.1231, 4.4721,
        5.0000, 4.8990, 4.8990, 4.5826, 4.5826, 4.7958, 4.4721, 4.4721, 3.8730,
        4.5826, 3.7417, 4.7958, 4.6904, 4.2426, 4.0000, 4.5826, 4.1231, 4.2426,
        4.7958, 4.8990, 4.1231, 3.3166, 3.4641, 4.5826, 4.2426, 4.5826, 4.8990,
        4.2426, 4.4721, 4.2426, 4.8990, 4.6904, 3.7417, 4.4721, 4.4721, 4.8990,
        4.2426, 3.8730, 4.8990, 4.7958, 4.5826, 4.7958, 4.1231, 4.4721, 4.4721,
        4.6904, 4.1231, 4.2426, 4.2426, 4.5826, 4.1231, 4.4721, 4.2426, 4.2426,
        4.8990, 4.4721, 5.1962, 4.2426, 3.8730, 4.2426, 4.4721, 4.5826, 4.5826,
        3.3166, 4.0000, 4.2426, 4.1231, 4.2426, 3.3166, 4.7958, 4.6904, 5.0990,
        4.5826, 4.7958, 4.8990, 4.5826, 4.2426, 4.1231, 4.4721, 4.3589, 3.4641,
        4.8990, 4.1231, 4.2426, 4.5826, 4.8990, 4.8990, 3.3166, 4.8990, 4.2426,
        4.2426, 4.5826, 4.5826, 4.2426, 3.8730, 4.1231, 4.1231, 4.6904, 5.1962,
        3.3166, 4.2426, 4.5826, 3.8730, 4.2426, 3.8730, 3.8730, 4.5826, 3.7417,
        4.5826, 4.5826, 4.2426, 4.5826, 5.1962, 4.1231, 4.4721, 4.8990, 4.5826,
        3.7417, 4.1231, 4.4721, 4.5826, 4.5826, 4.1231, 4.3589, 4.7958, 4.4721,
        4.8990, 4.7958, 4.4721, 4.4721, 4.7958, 4.7958, 4.5826, 4.5826, 4.2426,
        4.8990, 4.1231, 4.3589, 4.5826, 4.5826, 4.4721, 4.5826, 3.8730, 4.2426,
        4.5826, 4.2426, 4.1231, 3.8730, 4.5826, 4.6904, 5.2915, 4.7958, 4.1231,
        4.7958, 4.4721, 4.5826, 4.8990, 5.0000, 4.1231, 3.8730, 4.4721, 4.8990,
        4.2426, 4.1231, 4.8990, 4.1231, 4.5826, 4.4721, 4.4721, 3.8730, 4.3589,
        3.1623, 4.3589, 3.3166, 4.5826, 4.1231, 4.1231, 4.1231, 4.2426, 3.8730,
        3.8730, 4.7958, 4.1231, 4.1231, 4.5826, 3.4641, 4.5826, 4.0000, 3.8730,
        4.7958, 4.4721, 4.1231, 5.1962, 4.4721, 4.5826, 4.5826, 3.7417, 3.7417,
        3.3166, 4.0000, 3.7417, 4.2426, 3.8730, 4.2426, 3.8730, 3.4641, 4.2426,
        4.4721, 3.8730, 3.3166, 4.2426, 4.0000, 4.5826, 4.4721, 4.8990, 4.2426,
        3.4641, 3.6056, 4.0000, 4.5826, 3.7417, 3.7417, 4.1231, 3.8730, 4.5826,
        4.1231, 4.4721, 3.6056, 4.8990, 3.7417, 4.2426, 4.1231, 4.2426, 4.7958,
        3.0000, 4.2426, 4.1231, 4.1231, 4.0000, 3.8730, 4.4721, 3.6056, 3.7417,
        3.4641, 3.8730, 4.2426, 4.5826, 4.3589, 4.4721, 4.2426, 4.4721, 3.7417,
        4.1231, 4.2426, 3.8730, 4.2426, 3.3166, 4.1231, 4.0000, 3.7417, 3.7417,
        4.4721, 3.3166, 4.2426, 3.3166, 4.5826, 4.1231, 3.3166, 3.3166, 4.5826,
        2.8284, 4.4721, 3.4641, 3.3166, 3.7417, 3.7417, 3.6056, 4.4721, 3.6056,
        4.1231, 3.6056, 4.5826, 3.7417, 3.8730, 3.7417, 4.1231, 4.5826, 3.6056,
        4.1231, 4.0000, 4.4721, 4.1231, 3.3166, 4.0000, 4.2426, 4.1231, 4.0000,
        4.7958, 4.8990, 3.7417, 4.2426, 4.2426, 4.4721, 4.2426, 4.2426, 3.8730,
        3.8730, 3.7417, 4.1231, 4.4721, 4.5826, 4.2426, 4.8990, 3.7417, 4.1231,
        4.8990, 4.4721, 3.8730, 4.5826, 3.4641, 3.4641, 4.2426, 4.0000, 3.8730,
        2.8284, 3.8730, 4.0000, 4.2426, 4.1231, 4.2426, 3.4641, 3.4641, 4.1231,
        4.2426, 3.7417, 4.2426, 4.2426, 4.5826, 3.1623, 4.4721, 3.7417, 4.1231,
        4.0000, 4.5826, 3.7417, 4.0000], device='cuda:0')

I’m not sure I can follow your assumption.
Why would you expect the output to be sorted, when you specify sorted=False?
Are you seeing the expected result using sorted=True?

Thank you for your reply.
I mean if sorted=False, then the returned elements should keep their original order in the tensor.
Take the following codes as an example:

>>> import torch
>>> a = torch.tensor([5., 4, 3, 2, 1, 0])
>>> a
tensor([5., 4., 3., 2., 1., 0.])
>>> torch.topk(a, 3, largest=False, sorted=False)
torch.return_types.topk(
values=tensor([0., 1., 2.]), 
indices=tensor([5, 4, 3]))  # since sorted=False, I think the indices should be [3, 4, 5]
>>> torch.topk(a, 3, largest=False, sorted=True)
torch.return_types.topk(
values=tensor([0., 1., 2.]),
indices=tensor([5, 4, 3]))
>>>

When I use sorted=True, the result is correct as expected.

I think I didn’t explain the problem clearly.
When I use sorted=False, I would like to see the returned indices are sorted, not the returned value.
I hope my previous reply is a bit more clearer.

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.

Thank you for your reply.
I understood the definition of sorted .

What confuses me, is why the indices are not in the original order by default (when not sorting the values).
Are there any design reasons? Such as the non-determinism incurred by the parallelism.
But rerunning topk for servel times gave same results.

If you don’t specify sorted=True, there is no guarantee of any order (sorted or original order).

Yes, that’s most likely the reason at least for GPU runs. I’m not sure, how this method is implemented on the CPU.

I see. Thank you very much for your patience and help.

Hello Shengwei!

I wouldn’t consider this a bug, per se, because torch.topk()
doesn’t make any promises about the order it returns (when
sorted = False).

I do think this could be a legitimate feature request. There is
value in having a known return order, and the original order
(which corresponds to sorted indices) would seem to be the
natural choice.

I don’t know what the topk() code looks like, so I don’t know
how hard it would be to do, but if it weren’t too hard, and didn’t
significantly degrade the performance,
I would think that having
topk() return the original (sorted-indices) order would be a
worthwhile improvement. (I also think that for sorted = True
sets of indices for which the values are equal should have
the order of the indices within the set retained.)

(On the other hand, there are undoubtedly more important
bug fixes / feature requests out there in the queue.)

(By analogy, one might compare merge sort and heapsort.
Marge sort is a stable sort, that is, when values test equal, they
are returned in their original order, while heapsort is not stable,
but can have performance advantages. If there were no loss
in performance, it would make sense to always use the stable
sort.)

Best.

K. Frank