I’d imagine that it is something along the lines of
qs = torch.randn(1, 4, 6, 6) # batch 1, 4 channels (1 quaternion) and 6x6 matrix, bs = 1
bs, _, h, w = qs.shape
amp = torch.norm(qs, dim=1, keepdim=True)
amp_uf = amp.unfold(3, 2, 2).unfold(2, 2, 2).reshape(bs, 1, h // 2, w // 2, 2 * 2)
qs_uf = qs.unfold(3, 2, 2).unfold(2, 2, 2).reshape(bs, 4, h // 2, w // 2, 2 * 2)
maxamp = amp_uf.argmax(-1, keepdim=True).expand(-1, 4, -1, -1, -1)
qs_pooled = qs_uf.gather(-1, maxamp).view(bs, 4, h // 2, w // 2)

(The gather gets goes over the dimensions except the last and then picks the value at the maxamp index in the last dimension.)
Best regards
Thomas