That is a weird thing to do. Did you intend to extract smallest 2 element for each row? If so, use this one liner
a.topk(2, dim=1, largest=False)

if you don’t need result to be sorted, you can add sorted=False (defaulted to True).