Hi Ian,
You can try the following solution.
import torch

x = torch.tensor([[4, 2, 7, 1], [9, 22, 5, 13], [6, 4, 8, 25], [3, 9, 6, 10], [4, 1, 6, 14]])
H, W = x.shape

x = x.view(-1)
K = 4
_, indices = x.topk(4)
two_d_indices = torch.cat(((indices // W).unsqueeze(1), (indices % W).unsqueeze(1)), dim=1)
print(two_d_indices)

Thanks