Did you change your network’s final layer to only have a two-dimensional output?
Without evidence to the contrary (i.e. the tensor you input to topk and the result) I would venture that it is more likely that something is unexpected about what you feed into topk than with topk itself.
Best regards
Thomas